Group Abstract Group Abstract

Message Boards Message Boards

0
|
4.4K Views
|
14 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Error: "Solve was unable to solve the system" after using Rationalize

Posted 3 years ago

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

Can you help me? Thanks.

POSTED BY: Zhenyu Zeng
14 Replies
Posted 3 years ago

Thanks. I know now.

POSTED BY: Zhenyu Zeng
Posted 3 years ago

Thanks. Your method is very good!

POSTED BY: Zhenyu Zeng
Posted 3 years ago

Zhenyu,

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.

Read the documentation.

POSTED BY: Rohit Namjoshi
Posted 3 years ago
POSTED BY: Bill Nelson
Posted 3 years ago

Hello. What's the meaning of [[1]] in your last code? I felt I can't understand it. May you explain it to me?

POSTED BY: Zhenyu Zeng
Posted 3 years ago

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.

POSTED BY: Bill Nelson
Posted 3 years ago

Hello, after these code ran:

pK0 = Rationalize[-2622.38/T - 0.0178471 T + 15.5873, 0];
pK1 = Rationalize[3404.71/T + 0.032786 T - 14.8435, 0];
pK2 = Rationalize[290239/100/T + 0.02379 T - 6.4980, 0];
H = 10^-pH;
c;
T = Rationalize[t + 27315/100];
NSolve[c/b == pK1/H && d/c == pK2/H && 
   b == pK0 a && (a + b + c + d) 12 == DIC, {a, b, c, d}] // Simplify

then I input c, but I can't get the c value but get a c symbol. Why?

POSTED BY: Zhenyu Zeng
Posted 3 years ago

Hello, thanks for your reply. I found in output there were some 1.t, may can I make it to t not 1.t. Thanks.

POSTED BY: Zhenyu Zeng
Posted 3 years ago

If you replace

pH = -Log[H]

with

H=E^-pH

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.

POSTED BY: Bill Nelson
Posted 3 years ago

Hello, thanks for your reply. Is there a way to show out with pH not H?

POSTED BY: Zhenyu Zeng
Posted 3 years ago

I know now.

POSTED BY: Zhenyu Zeng
Posted 3 years ago

Is there a way to show the output with ScienticForm?

POSTED BY: Zhenyu Zeng
Posted 3 years ago

May you tell me why one of terms has not been rationalized?

POSTED BY: Zhenyu Zeng
Posted 3 years ago

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 is able to find your solution.

POSTED BY: Bill Nelson
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard