I am trying to solve a nonlinear system of equations with Solve (and NSolve), but the evaluation get stuck.

For a very similar system, basically the same, but with the derivatives of the equations, I get no problems. I define the functions I need, write the equations, define the variables, get the solutions with Solve, and, once obtained with another system the initial values, I try to solve the system withNSolve.

Defining the functions:

a[x_] := A (1 - ms[x])
b[x_] := 
  2 ((ArcSinh[nn[x]/ms[x]] ms[x]^3 + nn[x] ms[x] Sqrt[nn[x]^2 + ms[x]^2])/(8 \[Pi]^2) + (ArcSinh[pp[x]/ms[x]] ms[x]^3 + pp[x] ms[x] Sqrt[pp[x]^2 + ms[x]^2])/(8 \[Pi]^2))

where A is a constant. Here I deleted some multiplicative constants to simplify the problem.

Then I have the equations:

eq1[x_] := B a[x] + C a[x]^2 + D a[x]^3 - F b[x]

eq2[x_] := pp[x]^3 - nn[x]^3

eq3[x_] := G - (pp[x]^3 + nn[x]^3)

eq4[x_] := 
   Sqrt[nn[x]^2 + ms[x]^2] - Sqrt[pp[x]^2 + ms[x]^2] - Sqrt[m + ee[x]^2] + 
   H (pp[x]^3 - nn[x]^3)

where B, C, D, G, m and H are constants. Here too, I deleted some multiplicative constants, to simplify the code for you.

Finally, I define the variables:

Var = {ee[x], pp[x], nn[x], ms[x]}

then solve the system "implicitly":

Sol = Solve[{eq1[x] == 0, eq2[x] == 0, eq3[x] == 0, eq4[x] == 0}, Var]

(N.B: it is here that the code get stuck. Despite, as I said, with a similar system with derivatives of the equations, everything work fine.)

and make a list of the equations:

eqs = Table[Var[[i]] == (Var[[i]] /. Sol[[1]]), {i, Length[Var]}];

To conclude, after having obtained the initial conditions, I would try to solve the system:

system0 = Flatten[{eqs, ee[xi] == eei, pp[xi] == ppi, nn[xi] == nni, ms[xi] == msi}];
sol0 = 
  NSolve[system0, {ee, kpp, nn,  ms}, {x, xi, xf}, 
      {MaxSteps -> 10^4, 
       MaxStepFraction -> 10^-2, 
       WorkingPrecision -> 30, 
       InterpolationOrder -> All},

where I previously set xi = 10^-8 and xf = 10.

Trying to be more clear: When I try to evaluate the system with Solve, the evaluation continues indefinitely. I cannot understand why. Where is the mistake?

A similar system with the derivatives of the previous equations and NSolve replaced with NDSolve, works without any problem. The execution of the equivalent line

Sol = Solve[{eq1[x] == 0, eq2[x] == 0, eq3[x] == 0, eq4[x] == 0}, Core] 

is extremely fast (~1 sec).

Any help in understanding where I am wrong is welcome, as well any suggestion to solve numerically this kind of system of equations.

  • 1
    $\begingroup$ Deleting all [x] and [x_] and replacing := by = and Solve by NSolve in your code, one obtains {} in a moment. $\endgroup$ – user64494 Apr 18 '19 at 20:09
  • $\begingroup$ Judging from the options it looks like you want NDSolve, not NSolve. $\endgroup$ – Daniel Lichtblau Apr 19 '19 at 15:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.