Jump to content

KAlgebra/Homework: Difference between revisions

From KDE Wiki Sandbox
Annew (talk | contribs)
Annew (talk | contribs)
No edit summary
Line 1: Line 1:
This page show some use of kalgebra in real word
<languages />
<translate>
This page shows some uses of '''KAlgebra''' in real world problems.


=== Combinatorial example===
== Combinatorial example==


  We have 6 people who want to know how to get around a table with 6 chairs.
We have 6 people who want to know how to get around a table with 6 chairs.


  We now that 6 people can get around the table with this configuration
We know that 6 people can get around the table with this configuration


  p1 p2 p3 p4 p5 p6
{{Output|1=p1 p2 p3 p4 p5 p6<br />
  p1 p2 p3 p4 p6 p5
p1 p2 p3 p4 p6 p5<br />
  p1 p2 p3 p5 p4 p6
p1 p2 p3 p5 p4 p6<br />
  p1 p2 p3 p5 p6 p4
p1 p2 p3 p5 p6 p4}}


  And so on
And so on


  We notice that the last rotate position by 1, the fifth rotate position by
We notice that the last item rotates its position by 1, the fifth rotates position by 2, the fourth rotates position by 3, the third rotates position by 4, the second rotates position by 5 and first rotates position by 6. So we can write down a simple formula:
  2, the fourth rotate position by 3, the third rotate position by 4, the
  second rotate position by 5 and first rotate position by 6.


  So we can write down a simple formula:
{{Input|1=6*5*4*3*2*1}}


  6*5*4*3*2*1
Let's write this into '''KAlgebra''' console:


  Let's write this into kalgebra console:
{{Input|1=((((1*2)*3)*4)*5)*6}}


  ((((1*2)*3)*4)*5)*6
and the answer returned is {{Output|1= =720}}      
=720       


  This kind of arragenment of things around some position, where position
This kind of arrangement of things around some position, where the position number is equal to the number of things, is called "permutation".
  number is equal of number of things is called "permutation"


  Let's try to call in kalgebra the permutation function:
Let's try to call in '''KAlgebra''' the permutation function:


  factorial(6)
{{Input|1=factorial(6)}} and we get
=720
{{Output|1= =720}}


  It's the same result as you can see.
It's the same result as you can see.


==Probability example ==


=== Probability example ===
Let's roll a dice.  We want to know the probability of one face appearing.
 
  Let's roll a dice, we want to know the probability of one face
        
        
  We can define positive probability the favourble result of the event to us
We can define positive probability, the result of the event being favourable to us, and negative probability, the result of the event being unfavourable to us.
  and negative probability the unfavorable result of the event to us
 
  So you have to pick only one face:
 
  probability = 1(face picked)/6(total face)


  So now we know that when a dice is rolled there is a 1/6 of probability that
So you have to pick only one face:
  a face we choice come up


  We can set a simple function in kalgebra to take this formula in a simple
:probability = 1(face picked)/6(total face)
  way:


  probability:=(favorable,total)->favorable/total
So now we know that when a dice is rolled there is a 1/6 of probability that a face we chose will come up.


We can set a simple function in '''KAlgebra''' to take this formula in a simple way:


:probability:=(favorable,total)->favorable/total


=== Numerical Theory ===


    Let's say that we want to know the sum of all numbers between a bounded
== Numerical Theory ==
    interval for istance 1 - 100


    we have to do the sum of all numbers from 0 to 100 if we don't know the
Let's say that we want to know the sum of all numbers between a bounded interval, for instance 1 - 100.  We have to do the sum of all numbers from 0 to 100 if we don't know the rule to get them.
    rule to get them
      
      
    kalgebra offers a great facility to this task. Let's write in console:
'''KAlgebra''' offers a great facility to this task. Let's write in console:


    sum(x: x=1.100)
{{Input|1= sum(x: x=1.100)}}
      
      
    and we get the result
and we get the result.


    The syntax indicate this:
The syntax indicate this:


    1- Bound x as variable
- Bound x as variable
    2- Take first value of x
- Take first value of x
    3- Take second value of x and add the previus value of x
- Take second value of x and add the previus value of x
    4- Take third value of x and add the previus value of x
- Take third value of x and add the previus value of x
    ....
....
    N- Take the last value of x and add the last value of x
:N - Take the last value of x and add the last value of x
      
      


=== Eletronic ===
== Electronic ==
 
    Example1:


    Let's take a simple circuit a and port with two input and one output
Example 1:


    To resolve it on kalgebra we will write
Let's take a simple circuit a and port with two inputs and one output. To resolve it in '''KAlgebra''' we will write


    and(variable1, variable2)
{{Input|1=and(variable1, variable2)}}


    we will get the and value of the input as output
from which we will get the and value of the input as output.






    Example2:
Example2:
    
    
    We have a simple circuit: a battery of 3V and two eletrical resistence
We have a simple circuit: a battery of 3V and two eletrical resistences (R1 and R2) put on parallel of 3kohm. We want to get the current circulating in the circuit.
    (R1 and R2) put on parallel of 3kohm. We want to get the current
    circulating in the circuit.


    We have first to calculate the value of the eletric resistence expressed
We have first to calculate the value of the electric resistence expressed according to the law:
    as the law:


    TotalResistence = (1/R1 + 1/R2)^-1
:TotalResistence = (1/R1 + 1/R2)^-1
    Current = Voltage/TotalResistence
:Current = Voltage/TotalResistence


    Let's write a simple function in kalgebra to do this:
Let's write a simple function in '''KAlgebra''' to do this:


    totalresistence:=(R1,R2)->(1/R1+1/R2)^-1
{{Input|1=totalresistence:=(R1,R2)->(1/R1+1/R2)^-1<br />
    current:=(voltage,totalresistence)->voltage/totalresistence
current:=(voltage,totalresistence)->voltage/totalresistence}}


    let's see what we get:
Let's see what we get:


    current(3, totalresistence(3, 3))
{{Input|1=current(3, totalresistence(3, 3))}}
    =2
{{Output|1=  =2}}
</translate>

Revision as of 11:58, 8 December 2010

This page shows some uses of KAlgebra in real world problems.

Combinatorial example

We have 6 people who want to know how to get around a table with 6 chairs.

We know that 6 people can get around the table with this configuration

p1 p2 p3 p4 p5 p6
p1 p2 p3 p4 p6 p5
p1 p2 p3 p5 p4 p6
p1 p2 p3 p5 p6 p4

And so on

We notice that the last item rotates its position by 1, the fifth rotates position by 2, the fourth rotates position by 3, the third rotates position by 4, the second rotates position by 5 and first rotates position by 6. So we can write down a simple formula:

6*5*4*3*2*1

Let's write this into KAlgebra console:

((((1*2)*3)*4)*5)*6

and the answer returned is

=720

This kind of arrangement of things around some position, where the position number is equal to the number of things, is called "permutation".

Let's try to call in KAlgebra the permutation function:

factorial(6)

and we get

=720

It's the same result as you can see.

Probability example

Let's roll a dice. We want to know the probability of one face appearing.

We can define positive probability, the result of the event being favourable to us, and negative probability, the result of the event being unfavourable to us.

So you have to pick only one face:

probability = 1(face picked)/6(total face)

So now we know that when a dice is rolled there is a 1/6 of probability that a face we chose will come up.

We can set a simple function in KAlgebra to take this formula in a simple way:

probability:=(favorable,total)->favorable/total


Numerical Theory

Let's say that we want to know the sum of all numbers between a bounded interval, for instance 1 - 100. We have to do the sum of all numbers from 0 to 100 if we don't know the rule to get them.

KAlgebra offers a great facility to this task. Let's write in console:

sum(x: x=1.100)

and we get the result.

The syntax indicate this:

  1. - Bound x as variable
  2. - Take first value of x
  3. - Take second value of x and add the previus value of x
  4. - Take third value of x and add the previus value of x

....

N - Take the last value of x and add the last value of x


Electronic

Example 1:

Let's take a simple circuit a and port with two inputs and one output. To resolve it in KAlgebra we will write

and(variable1, variable2)

from which we will get the and value of the input as output.


Example2:

We have a simple circuit: a battery of 3V and two eletrical resistences (R1 and R2) put on parallel of 3kohm. We want to get the current circulating in the circuit.

We have first to calculate the value of the electric resistence expressed according to the law:

TotalResistence = (1/R1 + 1/R2)^-1
Current = Voltage/TotalResistence

Let's write a simple function in KAlgebra to do this:

totalresistence:=(R1,R2)->(1/R1+1/R2)^-1
current:=(voltage,totalresistence)->voltage/totalresistence

Let's see what we get:

current(3, totalresistence(3, 3))
=2