Message Boards Message Boards

GROUPS:

Solving system of Nonlinear algebraic equations (quickly)

Posted 5 years ago
19186 Views
|
16 Replies
|
10 Total Likes
|

Hi, I am Kashif, i need a command Like NSolve for solving a system of non-linear equations, which can simplify and separate coefficients of all variables and coefficients; all nonlinear terms .

Thanks

16 Replies

In what way is NSolve inadequate? Could you provide an example of the equations?

Thanks Sir, actually my problem is to solve a nonlinear system involving 6 equations with many non-linear terms , here is the sample in Attachment. In the case of system of 4 non-linear equations with 4 variables , i am getting accurate results within few minutes, but in above case as in file in attachment, when i run the program it continues in running for whole day but dont gives answer.

Please see the file in attachment and Guide me.

Thanks in advance for your time

Attachments:
Posted 5 years ago

You might try this as a quick experiment on your six equation system

v = Total[{exp1, exp2, exp3, exp4, exp5, exp6} /. Equal[l_, r_] -> Norm[l - (r)]];
NMinimize[v, {x1, y1, x2, y2, x3, y3}, StepMonitor :> Print[v]]

Then you can compare that with a similar experiment on your four equation system.

Hopefully that will quickly give you some idea what is happening.

First really thankful to your time ,your suggested command is really useful, as this is very quick in giving results, But I am not getting the required results. Please see in attachment, i am sending a file of a system of 4 equations in 4 variables, in which i already got required results, but with your command, results are not same. If you can get the same results as shown in file, then we can go for a system of 6 equations in 6 variables.

Thanks

Attachments:
Posted 5 years ago

For your four equation system you demonstrate that NSolve is successful

In[27]:= NSolve[{exp1, exp2, exp3, exp4}, {x1, y1, x2, y2}, Reals]

During evaluation of In[27]:= NSolve::ratnz: NSolve was unable to solve the system with inexact coefficients.
The answer was obtained by solving a corresponding exact system and numericizing the result. >>

Out[27]= {{x1 -> -1.08337, y1 -> 0.622023, x2 -> 1.08337, y2 -> 0.622023},
 {x1 -> -0.981789, y1 -> 0.163141, x2 -> 1.06868, y2 -> 0.614297},
 {x1 -> 1.06868, y1 -> 0.614297, x2 -> -0.981789, y2 -> 0.163141},
 {x1 -> 1.08337, y1 -> 0.622023, x2 -> -1.08337, y2 -> 0.622023}}

But NMinimize with the default settings is not successful in finding a good zero for your system.

In[28]:= v = Total[{exp1, exp2, exp3, exp4} /. Equal[l_, r_] -> Norm[l - (r)]];
NMinimize[v, {x1, y1, x2, y2}]

Out[29]= {0.0605371, {x1 -> -0.509966, y1 -> 0.0954671, x2 -> 1.01537, y2 -> 0.573978}}

I had hoped that my simple example would show you a way to solve your problem.

By increasing the number of iterations NMinimize does find a good zero.

In[30]:= v = Total[{exp1, exp2, exp3, exp4} /. Equal[l_, r_] -> Norm[l - (r)]];
NMinimize[v, {x1, y1, x2, y2}, MaxIterations -> 10^3]

Out[31]= {6.92979*10^-15, {x1 -> -0.981789, y1 -> 0.163141, x2 -> 1.06868, y2 -> 0.614297}}

For your six equation system NMinimize with the default settings is not successful in finding a good zero for your system.

In[38]:= v = Total[{expX1, expX2, expX3, expX4, expX5, expX6} /. Equal[l_, r_] -> Norm[l - (r)]];
NMinimize[v, {x1, y1, x2, y2, x3, y3}]

Out[39]= {1.30488*10^8, {x1->3.08738, y1->4.19488, x2->20.9305, y2->22.2496, x3->12.1937, y3->13.4264}}

Even when the number of iterations is greatly increased and other options are experimented with NMinimize still returns quickly, but again is not successful in finding a good zero for your system.

In[40]:= v = Total[{expX1, expX2, expX3, expX4, expX5, expX6} /. Equal[l_, r_] -> Norm[l - (r)]];
NMinimize[v, {x1, y1, x2, y2, x3, y3}, MaxIterations -> 10^6]

Out[41]= {1.30488*10^8, {x1->3.08739, y1->4.19488, x2->20.9305, y2->22.2496, x3->12.1937, y3->13.4264}}

Based on this and other experiments which I did, but did not include in the post, I suspect that it is possible there is either no zero to the six equation system or that there are local minima which are trapping NMimize and preventing it from finding a good zero.

A number of different experiments have not been able to find anything other than that minima.

If you are aware of a good starting location for the search then this might be very helpful.

Hopefully something in this will provide you the clues that you need.

Thanks for the detailed answer and for your time. please do me one more favour, that in

In[30]:= v = Total[{exp1, exp2, exp3, exp4} /. Equal[l_, r_] -> Norm[l - (r)]];
NMinimize[v, {x1, y1, x2, y2}, MaxIterations -> 10^3]

Out[31]= {6.92979*10^-15, {x1 -> -0.981789, y1 -> 0.163141, x2 -> 1.06868, y2 -> 0.614297}}

suggest me another command so that i get all possible 4 values of each variable, not only the one, although this is good approximation. But in my case in all above values of variables only one is the zero of a special function, for which i should have f(x1+i y1)=0, and f(x2+i y2)=0 But with the above value i am not getting good approximation .

I mean as you can see in

In[27]:= NSolve[{exp1, exp2, exp3, exp4}, {x1, y1, x2, y2}, Reals]

Out[27]= {{x1 -> -1.08337, y1 -> 0.622023, x2 -> 1.08337, y2 -> 0.622023},

 {x1 -> -0.981789, y1 -> 0.163141, x2 -> 1.06868, y2 -> 0.614297},

Is the one we got by your command but with this f()=0.1(-01)

{x1 -> 1.06868, y1 -> 0.614297, x2 -> -0.981789, y2 -> 0.163141},

{x1 -> 1.08337, y1 -> 0.622023, x2 -> -1.08337, y2 -> 0.622023}}  

But I need this last one as this gives f(x1+iy1)=1.2(-13),and f(x2+i y2)=3.5(-12) accuracy

Posted 5 years ago

You show that you are able to use NSolve when there appear to be solutions. Why not use NSolve as you have? Each answer seems to not be what you really want. Perhaps you could describe what your real problem is and what answer will be satisfactory for you.

Thanks for your time Nsolve is only giving results for 4 equations with 4 variables but dont run for system of 6 equations with 6 variables.

Posted 5 years ago

Unfortunately I do not know of an available Mathematica function which accept an arbitrary system of equations and will always rapidly and correctly either give you all solutions or tell you that there is no solution.

Perhaps you could try writing your own function which would accept a system of equations and a list of variables. You would craft your function to use NMinimize on a modified version of your system that it creates that is similar to what I have shown several times and with a suitably large number of iterations so that it would likely find one solution if any exists. Then your function would use that result to either print out that there are no solutions or it would give your system and variables to NSolve and return the result from that. Hopefully that would be fast and correct for the kinds of systems that you will give it.

I do not know if this would be a good idea for the kinds of problems that you are working on. I suspect this may be unacceptable for new and different reasons.

Hello Sir, First i apologize for late responding your last reply,

can you Please explain how can I craft my function to use NMinimize on a modified version of my system I mean

In[30]:= v = Total[{exp1, exp2, exp3, exp4} /. Equal[l, r] -> Norm[l - (r)]];
 NMinimize[v, {x1, y1, x2, y2}, MaxIterations -> 10^3]

where should i put my function.

Please see the attachment

Attachments:
Posted 5 years ago

Perhaps try this

aFunction[eqns_, vars_] := Module[{sumNorm, min},
   sumNorm = Total[eqns /. Equal[l_, r_] -> Norm[l - (r)]];
   min = NMinimize[sumNorm, vars];
   If[First[min] > 0.1,
    Print["Likely no solution, NMinimize returns ", First[min], ", Suggest you give up"]; Null,
    Print["Likely solution "]; NSolve[eqns, vars, Reals]
    ]
   ];

and then this

aFunction[{exp1, exp2, exp3, exp4, exp5, exp6}, {x1, y1, x2, y2, x3, y3}]

on your six equation system

and then try this

aFunction[{exp1x, exp2x, exp3x, exp4x}, {x1, y1, x2, y2}]

on your four equation system, where I have renamed exp1 to exp1x, exp2 to exp2x, etc.

This attempt to rapidly inform you when there is no solution and otherwise give you all solutions worries me in several different ways.

I suspect you will have more than these two systems to solve and at least some of them will fail in new and different ways.

Hopefully you can learn from this simple example and be able to construct a much more dependable function to use.

Hello Sir,

I am really extremely thankful for your time and useful suggestions that really helped me much . Your last suggestion is really very good and it worked for the case of 4 equations and 4 variables, but it is taking too much time for system of 6 equations and 6 variables.

Now I need a command for quick solving, Please see the attached file.

Once again thanks

Attachments:

Hello Sir,

i am also facing the same problem in the case of 3 equations with 3 variables, as shown in the attach file.

Please guide me

Attachments:
Posted 5 years ago
exp1 = ComplexExpand[Im[(1+I)/(2+3I-bb) + (1+I)/(2+3I-cc)] + Im[(1+I)/(2+3I-dd)]] - 7/2 == 0;
exp2 = ComplexExpand[Im[(2+2I)/(3+4I-bb) + (2+2I)/(3+4I-cc)] + Im[(2+2I)/(3+4I-dd)]] - 3/4 == 0;
exp3 = ComplexExpand[Im[(3+3I)/(5+7I-bb) + (3+3I)/(5+7I-cc)] + Im[(3+3I)/(5+7I-dd)]] - 3/4 == 0;
N[Reduce[{exp1, exp2, exp3}, {bb, cc, dd}, Backsubstitution -> True]]

exp1c = ComplexExpand[Im[(1 + I)/(2 + 3 I - bbb) + (1 + I)/(2 + 3 I - ccc)]] - 7/2 == 0;
exp2c = ComplexExpand[Im[(2 + 2 I)/(3 + 4 I - bbb) + (2 + 2 I)/(3 + 4 I - ccc)]] - 3/4 == 0;
N[Reduce[{exp1c, exp2c}, {bbb, ccc}, Backsubstitution -> True]]

This is not a general solution that will work for every new example you come up with. For example, it does not rapidly provide a solution to your six equation system that takes too long for you. I suspect there is no single method that will rapidly and correctly solve all the examples you can create.

Posted 3 months ago

Hi,

I have a problem to solve nonlinear simultaneous equations with NSolve. The iteration runs the whole night and don`t returns a solution. Can anyone help me please!!! Thanks!!!

If you have a new question please post it as such. This is in no way a reply for the original question,

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