Hello, I used Rationalize in Solve, but there is still error:Solve::ratnz: Solve was unable to solve the system with inexact coefficients. The answer was obtained by solving a corresponding exact system and numericizing the result.
pK0 = Rationalize[-2622.38/T - 0.0178471 T + 15.5873];
pK1 = Rationalize[3404.71/T + 0.032786 T - 14.8435];
pK2 = Rationalize[290239/100/T + 0.02379 T - 6.4980];
pH = -Log[H];
T = Rationalize[t + 27315/100];
Solve[c/b == pK1/H && d/c == pK2/H &&
b == pK0 a && (a + b + c + c) 12 == DIC, {a, b, c, d}] // Simplify
If you display the value of pK0 I believe you will see that it did not completely rationalize and there is still a decimal point in one of the terms. This is probably because of the number of digits after the decimal point in one of the terms. Changing that expression to
pK0=Rationalize[-2622.38/T - 0.0178471 T + 15.5873, 0]
will force the complete rationalization. The documentation for Rationalize explains this.
then Solve will find solutions in terms of pH instead of H. Please check carefully that the signs of H and pH allow this change to be correctly made. I do not know if the form of this solution is what you need. Please carefully test the solutions to make certain that they are correct.
NSolve, like some other Mathematica functions, does not assign a value to c when it finds the solution. Instead it returns a list of items that can be used for further calculations.
If you want to assign the value of the solution to c then
c=c/.NSolve[c/b==pK1/H && d/c==pK2/H && b==pK0 a && (a+b+c+d) 12==DIC, {a,b,c,d}][[1]]//Simplify
will do this. You can look up /. in the help system to try to understand how this works.
You can, for example use /. to replace all 1. t with t like this
c/.(1.t->t)
Mathematica keeps the values of assignments for later use, until you exit Mathematica or tell it to forget an assignment so remember that this happens.
and in the search box in the upper right corner you can type [[ and then tap Enter on your keyboard and it will take you to the documentation for Part. This is usually abbreviated by [[ and ]].
So with a list {a,b,c,d} you can extract the third item with {a,b,c,d}[[3]]
This works when you have lists inside of lists.
If you look at just the result from NSolve you should see that it has {{one solution},{another solution}}
When I just did c=c/.NSolve[…] there was {} around the value assigned to c. I did not want that so I used [[1]] to extract the first item and thus get rid of the {}.
You might find it helpful to quickly read an introduction to Mathematica programming. There are lots of books and even some web pages that will show you some of this. That might make it easier for you to become more productive.
[1]: Wolfram Language & System Documentation Center
solution =
NSolve[c/b == pK1/H && d/c == pK2/H && b == pK0 a && (a + b + c + d) 12 == DIC, {a, b, c, d}] // Simplify
(* Solution for a *)
a /. solution
You may be tempted to do this
a = a /. solution
but that is not a good idea because now a has a value and that will change the equations passed to NSolve.