# Solving a system of nonlinear equations takes forever

**URL:** <https://community.wolfram.com/t/solving-a-system-of-nonlinear-equations-takes-forever/19152>\
**Category:** Questions\
**Tags:** equation-solving, optimization, numerical-computation\
**Created:** [November 21, 2021, 10:47am UTC](https://community.wolfram.com/t/solving-a-system-of-nonlinear-equations-takes-forever/19152 "2021-11-21T10:47:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ridhahorchani](https://avatars.discourse-cdn.com/v4/letter/r/a88e57/32.png) [@ridhahorchani](https://community.wolfram.com/u/ridhahorchani)\
**Post date:** [November 21, 2021, 10:47am UTC](https://community.wolfram.com/t/solving-a-system-of-nonlinear-equations-takes-forever/19152/1 "2021-11-21T10:47:31Z")

</div>

[Open in Wolfram Cloud ↗](https://www.wolframcloud.com/obj/a29fd76e-42a9-4a5a-b7f8-a0f737bf0bf7)

---

<div class="post-metadata">

**Author:** ![dontdont9](https://avatars.discourse-cdn.com/v4/letter/d/54ee81/32.png) [@dontdont9](https://community.wolfram.com/u/dontdont9)\
**Post date:** [November 21, 2021, 8:06pm UTC](https://community.wolfram.com/t/solving-a-system-of-nonlinear-equations-takes-forever/19152/2 "2021-11-21T20:06:18Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![gianlucagorni](https://avatars.discourse-cdn.com/v4/letter/g/ec9cab/32.png) [@gianlucagorni](https://community.wolfram.com/u/gianlucagorni)\
**Post date:** [November 23, 2021, 4:18pm UTC](https://community.wolfram.com/t/solving-a-system-of-nonlinear-equations-takes-forever/19152/3 "2021-11-23T16:18:34Z")

</div>

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}]

```
