Message Boards Message Boards

Solving a system of nonlinear equations takes forever

Posted 2 years ago

POSTED BY: ridha horchani
2 Replies

It seems to me that you have redundant variables. Instead of five {A, B, C1, D1, \[Delta]} you can manage with three x,y,z, with much simpler formulas:

eqs0 = {m1 + m2 + (6 A)/\[Delta]^2 + (
     3 B)/\[Delta] - (2 \[Mu])/
      hbar^2 ((C1 + (8 A)/\[Delta]^3 + (3 B)/\[Delta]^2)/(
       3 + 
        Sqrt[(8 \[Mu])/
         hbar^2 (B/\[Delta]^3 + (3 A)/\[Delta]^4 - D1 + 
           hbar^2/(2 \[Mu]) (0 + 0.5)^2)]))^2 == 3.097, 
   m1 + m2 + (6 A)/\[Delta]^2 + (
     3 B)/\[Delta] - (2 \[Mu])/
      hbar^2 ((C1 + (8 A)/\[Delta]^3 + (3 B)/\[Delta]^2)/(
       5 + 
        Sqrt[(8 \[Mu])/
         hbar^2 (B/\[Delta]^3 + (3 A)/\[Delta]^4 - D1 + 
           hbar^2/(2 \[Mu]) (0 + 0.5)^2)]))^2 == 3.686, 
   m1 + m2 + (6 A)/\[Delta]^2 + (
     3 B)/\[Delta] - (2 \[Mu])/
      hbar^2 ((C1 + (8 A)/\[Delta]^3 + (3 B)/\[Delta]^2)/(
       7 + 
        Sqrt[(8 \[Mu])/
         hbar^2 (B/\[Delta]^3 + (3 A)/\[Delta]^4 - D1 + 
           hbar^2/(2 \[Mu]) (0 + 0.5)^2)]))^2 == 4.039, 
   m1 + m2 + (6 A)/\[Delta]^2 + (
     3 B)/\[Delta] - (2 \[Mu])/
      hbar^2 ((C1 + (8 A)/\[Delta]^3 + (3 B)/\[Delta]^2)/(
       3 + 
        Sqrt[(8 \[Mu])/
         hbar^2 (B/\[Delta]^3 + (3 A)/\[Delta]^4 - D1 + 
           hbar^2/(2 \[Mu]) (1 + 0.5)^2)]))^2 == 3.511, 
   m1 + m2 + (6 A)/\[Delta]^2 + (
     3 B)/\[Delta] - (2 \[Mu])/
      hbar^2 ((C1 + (8 A)/\[Delta]^3 + (3 B)/\[Delta]^2)/(
       5 + 
        Sqrt[(8 \[Mu])/
         hbar^2 (B/\[Delta]^3 + (3 A)/\[Delta]^4 - D1 + 
           hbar^2/(2 \[Mu]) (1 + 0.5)^2)]))^2 == 3.927, 
   m1 + m2 + (6 A)/\[Delta]^2 + (
     3 B)/\[Delta] - (2 \[Mu])/
      hbar^2 ((C1 + (8 A)/\[Delta]^3 + (3 B)/\[Delta]^2)/(
       3 + 
        Sqrt[(8 \[Mu])/
         hbar^2 (B/\[Delta]^3 + (3 A)/\[Delta]^4 - D1 + 
           hbar^2/(2 \[Mu]) (2 + 0.5)^2)]))^2 == 3.77};
eqsNew = 
 eqs0 /. {(C1 + (8 A)/\[Delta]^3 + (3 B)/\[Delta]^2)^2 -> x} /. {(
      6 A)/\[Delta]^2 + (3 B)/\[Delta] -> y} /. {-D1 + (
     3 A)/\[Delta]^4 + B/\[Delta]^3 -> z}
Solve[eqsNew, {x, y, z}]
POSTED BY: Gianluca Gorni
Posted 2 years ago

Norm uses square roots and those can sometimes introduce complex numbers.

Try

NMinimize[(lhs1-rhs1)^2+(lhs2-rhs2)^2+(lhs3-rhs3)^2, {A,B,C1,D1,δ]

which avoids the square roots and may avoid some complex numbers.

Giving NMinimize the option Method->"RandomSearch" seems like it sometimes enables it to find something close to a minimum when other default methods may struggle trying to use more complicated calculations.

Or possibly try FindRoot on that expression, because it seems more aggressive when looking for a solution than NSolve does sometimes, but if you do that then you need to give reasonable starting values for FindRoot to begin searching.

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

Group Abstract Group Abstract