Solving system of nonlinear equations
Mostrar comentarios más antiguos
Hello all. I want to solve 10 nonlinear equations in 10 variables. I used 'solve' function but it didn't give me a result " it takes too much time and nothing happened". Is there any other way to do that? The equations are generated within the program.
24 comentarios
Star Strider
el 2 de Ag. de 2012
Posting the relevant parts of your code will help.
Since you are using ‘solve’ you are obviously using the Symbolic Math Toolbox. How are the equations generated within the program? What are the equations? What do you eventually want to do with them?
omnia
el 2 de Ag. de 2012
Star Strider
el 2 de Ag. de 2012
I am still lost. If you do:
eqn_17(1) = simplify(collect(expand(eqn_17(1))))
and such for every equation in:
soln=solve(eqn_17(1),eqn_17(2),eqn_17(3),eqn_17(4),eqn_17(5),eqn_18(1),eqn_18(2),eqn_18(3),eqn_18(4),eqn_18(5));
what do you get?
It will not be necessary to post them all. Posting those results for ‘eqn_17(1)’ and ‘eqn_18(1)’ will likely give us enough information for now.
omnia
el 5 de Ag. de 2012
Walter Roberson
el 5 de Ag. de 2012
Algebraically solving 10 non-linear equations in 10 unknowns usually takes a number of days, if you do not run out of memory first. The practical "overnight" limit is typically 5 to 7 simultaneous equations.
omnia
el 5 de Ag. de 2012
Star Strider
el 5 de Ag. de 2012
Omnia —
Can you at least post the results of:
eqn_17(1) = simplify(collect(expand(eqn_17(1))))
and
eqn_18(1) = simplify(collect(expand(eqn_18(1))))
for us to see and comment on? If even running those two statements take too much time and do not produce any results, we probably cannot help you.
Walter Roberson
el 5 de Ag. de 2012
How many distinct symbolic variables are there? If f_ES and F_GS each have 10 variables and the variables are not duplicated between the two, then you have 10 equations in 20 unknowns, and you will not be able to get any solution for that unless you specify which 10 of the variables to solve for. The default would be to try to solve for all the variables in the equations, and that would fail because there are not enough equations for 20 variables. But it would go through all the trouble of trying to solve them in case it found that some of variables canceled out.
omnia
el 6 de Ag. de 2012
Star Strider
el 6 de Ag. de 2012
Editada: Star Strider
el 6 de Ag. de 2012
I have one more request, since I had no idea your equations contained numerical constants:
eqn_17(:) = vpa(simplify(collect(expand(eqn_17(1)))),5)
eqn_18(:) = vpa(simplify(collect(expand(eqn_18(1)))),5)
That should at least make them easier to read and understand.
When I do that with the equations you posted (with the ‘syms’ declaration using the vectors of variables in your answer to Walter), I get:
eqn_17(1) = [ 3.3425e10*f_GS1 - 5.5922e11*f_ES1 + 4.6658e11*f_ES1*f_GS1 + 5.3385e10, f_ES2*(5.0e11*f_GS2 - 5.0e11) - 0.5*f_GS2*(6.6849e10*f_ES2 - 6.6849e10) - 5.9513e10*f_ES2 + 5.3385e10, f_ES3*(5.0e11*f_GS3 - 5.0e11) - 0.5*f_GS3*(6.6849e10*f_ES3 - 6.6849e10) - 5.9819e10*f_ES3 + 5.3385e10, f_ES4*(5.0e11*f_GS4 - 5.0e11) - 0.5*f_GS4*(6.6849e10*f_ES4 - 6.6849e10) - 6.0143e10*f_ES4 + 5.3385e10, f_ES5*(5.0e11*f_GS5 - 5.0e11) - 0.5*f_GS5*(6.6849e10*f_ES5 - 6.6849e10) - 6.0487e10*f_ES5 + 5.3385e10]
eqn_18(1) =[ 1.0e12*f_ES1 - 6.8043e10*f_GS1 - 9.3315e11*f_ES1*f_GS1 + 9.6967e7, f_GS2*(6.6849e10*f_ES2 - 6.6849e10) - 1.2438e9*f_GS2 - 2.0*f_ES2*(5.0e11*f_GS2 - 5.0e11) + 1.2192e8, f_GS3*(6.6849e10*f_ES3 - 6.6849e10) - 1.291e9*f_GS3 - 2.0*f_ES3*(5.0e11*f_GS3 - 5.0e11) + 1.4549e8, f_GS4*(6.6849e10*f_ES4 - 6.6849e10) - 1.316e9*f_GS4 - 2.0*f_ES4*(5.0e11*f_GS4 - 5.0e11) + 1.58e8, f_GS5*(6.6849e10*f_ES5 - 6.6849e10) - 1.3043e9*f_GS5 - 2.0*f_ES5*(5.0e11*f_GS5 - 5.0e11) + 1.5213e8]
However I cannot tell you much more than that the magnitude of your constants (most on the order of 1E+10) could cause numeric problems in the calculation.
omnia
el 6 de Ag. de 2012
Star Strider
el 6 de Ag. de 2012
Editada: Star Strider
el 6 de Ag. de 2012
Or a bit more clearly, since ‘eqn_17(1)’ and ‘eqn_18(1)’ are each actually [1 x 5] symbolic vectors:
eqn_17(1,1) = 3.3425e10*f_GS1 + f_ES1*(4.6658e11*f_GS1 - 5.5922e11) + 5.3385e10
eqn_18(1,1) = 9.6967e7 - f_ES1*(9.3315e11*f_GS1 - 1.0e12) - 6.8043e10*f_GS1
eqn_17(1,2) = 3.3425e10*f_GS2 + f_ES2*(4.6658e11*f_GS2 - 5.5951e11) + 5.3385e10
eqn_18(1,2) = 1.2192e8 - f_ES2*(9.3315e11*f_GS2 - 1.0e12) - 6.8093e10*f_GS2
eqn_17(1,3) = 3.3425e10*f_GS3 + f_ES3*(4.6658e11*f_GS3 - 5.5982e11) + 5.3385e10
eqn_18(1,3) = 1.4549e8 - f_ES3*(9.3315e11*f_GS3 - 1.0e12) - 6.814e10*f_GS3
eqn_17(1,4) = 3.3425e10*f_GS4 + f_ES4*(4.6658e11*f_GS4 - 5.6014e11) + 5.3385e10
eqn_18(1,4) = 1.58e8 - f_ES4*(9.3315e11*f_GS4 - 1.0e12) - 6.8165e10*f_GS4
eqn_17(1,5) = 3.3425e10*f_GS5 + f_ES5*(4.6658e11*f_GS5 - 5.6049e11) + 5.3385e10
eqn_18(1,5) = 1.5213e8 - f_ES5*(9.3315e11*f_GS5 - 1.0e12) - 6.8154e10*f_GS5
However I am still convinced that the magnitude of many of the constants is causing numeric problems with the solution. There may also be linear dependence problems, since many of the coefficients of different variables appear to be the same.
omnia
el 6 de Ag. de 2012
Walter Roberson
el 6 de Ag. de 2012
In order to use fsolve(), use matlabFunction() to convert the symbolic expressions into function handles. fsolve() accepts function handles on input.
omnia
el 6 de Ag. de 2012
Star Strider
el 6 de Ag. de 2012
Walter Roberson
el 7 de Ag. de 2012
Did R14 have anonymous functions?
omnia
el 9 de Ag. de 2012
Editada: Walter Roberson
el 9 de Ag. de 2012
Walter Roberson
el 9 de Ag. de 2012
findsym() returns all symbolic variables, so you are substituting ones for all symbolic variables in "eqns" and so your "F" will be a numeric value (a vector likely.) You are not leaving anything to vary to be solved by fsolve()
Alan Weiss
el 9 de Ag. de 2012
Editada: John Kelly
el 2 de Mzo. de 2015
You might want to use matlabFunction to convert your symbolic variables to a function handle that will give your objective function. It will be faster than repeatedly using subs. See the example here.
Alan Weiss
MATLAB mathematical toolbox documentation
Walter Roberson
el 9 de Ag. de 2012
The poster is using R14. I don't know if matlabFunction() was available back then?
omnia
el 11 de Ag. de 2012
Respuestas (1)
Honglei Chen
el 2 de Ag. de 2012
0 votos
Do you have Optimization Toolbox? If so, you can try fsolve
6 comentarios
omnia
el 2 de Ag. de 2012
Image Analyst
el 2 de Ag. de 2012
So, did you try casting your data to double? If not, what did you think to do when you saw this error?
omnia
el 2 de Ag. de 2012
Honglei Chen
el 2 de Ag. de 2012
Solve is part of Symbolic Computation Toolbox. Since you said the result is not satisfying, I'm suggesting you to try the numerical way to solve it, i.e. fsolve. You may need to redefine your variable and rewrite your equations to fit the syntax.
omnia
el 5 de Ag. de 2012
Walter Roberson
el 5 de Ag. de 2012
Use matlabFunction() to convert the symbolic equations into something that fsolve() can deal with.
Categorías
Más información sobre Equation Solving en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!