4
$\begingroup$

I don't understand why, in the code below, Solve works with symbols, but substituting numerical values (rational) for the symbolic parameters makes it unsolvable:

Clear[mo, RT, n]

dG = mo + 2 RT Log[n/(1 + n)] - RT Log[-1 + 2/(1 + n)]
Solve[dG == 0, n]

vals = {mo -> 79900, RT -> 6197399567/2500000};
dGvals = dG /. vals
Solve[dGvals == 0, n]

Mathematica 11.2.0.0 on Mac OS X Yosemite

$\endgroup$

3 Answers 3

4
$\begingroup$

The reason is the precedence of simplifications undertaken by Solve for symbolic vs. numeric values. It turns out that for the latter case Solve tries another route of solution and gets trapped into a very inefficient procedure and eventually gives up.

Let us simplify your problem. In fact, there is a single relevant parameter mo/RT

xN=79900/(6197399567/2500000)//N
(*   32.2313 *)

The respective equation is

eq=x+2Log[n/(1+n)]-Log[-1+2/(1+n)]

Let us approximate xN in 3 different ways and see what happens.

  • Integer (32)

val=Rationalize[xN,1]
Solve[eq==0/.x->val,n]
Out[1]= 32
Out[2]= {{n->1/Sqrt[1+E^32]}}

Fine, this work as expected. $$\frac{1}{\sqrt{1+e^{32}}}$$

  • Simplest rational number (129/4)

val=Rationalize[xN,0.1]
Solve[eq==0/.x->val,n]
Out[3]= 129/4
Out[4]= {{n->Sqrt[(-1+E^(129/4)-E^(129/2)+E^(387/4))/(-1+E^129)]}}

Here, the solution is still possible, but it has a completely different (and equivalent form) $$\sqrt{\frac{-1+e^{129/4}-e^{129/2}+e^{387/4}}{-1+e^{129}}}$$

  • Finally (290/9)

val=Rationalize[xN,0.01]
Solve[eq==0/.x->val,n]
Out[5]= 290/9
Out[6]= {{n->1/Sqrt[(1+E^290)/(1-E^(290/9)+E^(580/9)-E^(290/3)+E^(1160/9)-E^(1450/9)+E^(580/3)-E^(2030/9)+E^(2320/9))]}}

or in human-readable form $$\frac{1}{\sqrt{\frac{1+e^{290}}{1-e^{290/9}+e^{580/9}-e^{290/3}+e^{1160/9}-e^{1450/9}+e^{580/3}-e^{2030/9}+e^{2320/9}}}}$$

If we continue with more and more accurate val the expression get more and more complicated until it reaches the point that MA cannot handle.

$\endgroup$
0
$\begingroup$

Try: Reduce[dGvals == 0, n, Reals]

$\endgroup$
0
$\begingroup$
Clear["Global`*"]

dG = mo + 2 RT Log[n/(1 + n)] - RT Log[-1 + 2/(1 + n)];

sol1 = Solve[dG == 0, n]

(* {{n -> -(1/Sqrt[1 + E^(mo/RT)])}, {n -> 1/Sqrt[1 + E^(mo/RT)]}} *)

Restricting the domain to Reals gives a single solution that is positive. Solve[expr, vars, Reals] restricts all variables, parameters, constants, and function values to belong to the domain Reals.

sol2 = Solve[dG == 0, n, Reals] // Simplify

(* {{n -> Sqrt[1/(1 + E^(mo/RT))]}} *)

vals = {mo -> 79900, RT -> 6197399567/2500000};

dGvals = dG /. vals;

To use Solve with dGvals, restrict the domain to Reals. Again, this eliminates one of the roots.

sol3 = Solve[dGvals == 0, n, Reals]

(* {{n -> 1/Sqrt[1 + E^(199750000000/6197399567)]}} *)

Alternatively, restrict n to being positive

sol4 = Solve[dGvals == 0 && n > 0, n]

(* {{n -> 1/Sqrt[1 + E^(199750000000/6197399567)]}} *)

EDIT: More specifically, for positive values of mo and RT

Simplify[
 FunctionDomain[
  {mo + 2 RT Log[n/(1 + n)] - RT Log[-1 + 2/(1 + n)],
   mo > 0, RT > 0}, n], {mo > 0, RT > 0}]

(* 0 < n < 1 *)

({sol1[[2]]} /. vals) == (sol2 /. vals) == sol3 == sol4

(* True *)
$\endgroup$
5
  • $\begingroup$ This works, thank you, but it seems like a "trick". I'd feel better if I understood why the trick works, understood why the use of numbers stops Solve for no apparent reason that I can see. $\endgroup$
    – Paul R.
    Commented Oct 2, 2019 at 17:57
  • $\begingroup$ @PaulR. My guess is that it has something to do with the fact that adding MaxExtraConditions->All to the symbolic case also stops Solve from giving solutions - it looks like it's doing some questionable transformations that are not valid in all cases, including the case of the values given by vals (notice also that dG/.Solve[dG==0,n]/.vals//N shows that one of the solutions is not valid). By restricting the domain to Reals you're probably giving Solve enough hints to make it be sure about what transformations are allowed $\endgroup$
    – Lukas Lang
    Commented Oct 2, 2019 at 18:19
  • $\begingroup$ @LukasLang See my solution suggesting what could be a possible reason. $\endgroup$
    – yarchik
    Commented Oct 3, 2019 at 9:38
  • $\begingroup$ @yarchik I've seen it, thanks! Nice insight into the process of Solve $\endgroup$
    – Lukas Lang
    Commented Oct 3, 2019 at 9:55
  • $\begingroup$ @yarchik - Excellent! Thank you. $\endgroup$
    – Paul R.
    Commented Oct 4, 2019 at 9:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.