This page shows some uses of KAlgebra in real world problems.
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
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:
Let's write this into KAlgebra console, and the answer returned is:
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
It's the same result as you can see.
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:
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:
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:
and we get the result:
sum(x: x=1..100) = 5050
The syntax indicate this:
Let's take a simple AND gate with two inputs and one output. To resolve it in KAlgebra we will write
from which we will get the and value of the input as output.
We have a simple circuit: a battery of 3V and two electrical resistances (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 resistance expressed according to the law:
Let's write a simple function in KAlgebra to do this:
Let's see what we get:
current(3, totalresistance(3000, 3000))
current(3, totalresistance(3 000, 3 000)) = 0,002
Now, what if we need to know the final temperature when we mix 40L of 15°C water with 30L of 70°C water?
Using conservation of energy, we know that the initial and final thermal energies are the same, so the final energy is equal to the energy of the first fluid plus the energy of the second fluid(using U for internal energy):
Internal energy is equal to the volumetric heat capacity times volume times temperature:
So Cfinal*Vfinal*Tfinal = C1*V1*T1 + C2*V2*T2
And since the heat capacities are all the same and cancel out, and the final volume is the sum of the two initial volumes:
We can then either use this directly in KAlgebra:
(40*15 + 30*70)/(40 + 30)
and get the final temperature, or put in a function if we need to repeat the computation:
finalTemp:=(v1,t1,v2,t2)->(v1*t1 + v2*t2)/(v1+v2)
Which we can then use like this:
finalTemp(40, 15, 30, 70) =38.5714
Now, suppose the two fluids have different volumetric heat capacities, such as 4180 J/(L*K) for the first liquid (water), and 1925 J/(L*K) for the second liquid (ethanol).
We will need to refer back to the equation:
The resultant heat capacity will be the average of the capacities of the first and second fluids, weighted by volume(since it is a volumetric heat capacity rather than mass- or molar-specific):
And plugging this into the previous equation, we get:
And either use this formula directly:
(4180*40*15 + 1925*30*70)/(4180*40+1925*30)
Or write a function if we want to repeat the calculation:
finalTemp2:=(c1,v1,t1,c2,v2,t2)->(c1*v1*t1 + c2*v2*t2)/(c1*v1+c2*v2)
Which we can then use like this:
finalTemp2(4,180, 40, 15, 1,925, 30, 70) =29.1198
Screenshot of KAlgebra after running these computations: