I'm creating a program for equillibrium constants in chemistry. The formula is
[A^a][B^b]/[C^c][D^d] where a reaction is given in the form c[C]+d[D]->a[A]+b[B]. This however is limited to two reactants and two products, when there are times that there may be more than two of each, or imbalanced numbers of each.
My code for this equation looks like this:
If not(dim(L1)=dim(L2):Return
1->B
For(A,1,dim(L1
B(L1(A)^L2(A)->B
End
Disp B
Now, I realize that that does not allow user input inside the program. Simply adding this code to the beginning of the program changes the input to a comma separated values input (e.g. 3,4.57,9.21,-2.8)
Input "Molarities:",Str1
Input "Powers:",Str2
expr("{"+Str1->L1
expr("{"+Str2->L2
The way the code works is by entering a negative value for the power of any molarity which is intended to be in the denominator.
I was wondering if this code could be optimized at all