8 nonlinear equations, 8 unknowns - little luck with fsolve/vpasolve
Mostrar comentarios más antiguos
Hi All. I have a system of 8 nonlinear equations that I try to solve with fsolve. If I run the code, I get the solution because I start at the actual solutions. But If I change the guess values (g1,g2,etc) slightly, I get errors, like no solutions found, or fslove stopped prematurely. etc. I tried vpasolve, -- it seems to perform even worse than fslove, returning empty sets. I tried random guess values in fsolve, but it takes too long and I cannot see any solution still. I understand no solver or method is perfect. But perhaps I thought there is an inefficiency in my code? Any help is appreciated. I tried to convert the paramaters to ratios as suggested in earlier threads, -- no luck. Is there a way to solve this problem more efficiently instead of suggesting to give up on this, or research advanced numerical techniques?
2 comentarios
Matt J
el 29 de En. de 2020
Your TolFun setting of 0.001 looks suspiciously lax. It will encourage the solver to stop iterating very early. I doubt it's the only cause of your problems, but I would go to TolFun=1e-10 or so.
Alex Tekin
el 29 de En. de 2020
Respuesta aceptada
Más respuestas (1)
John D'Errico
el 25 de En. de 2020
Editada: John D'Errico
el 25 de En. de 2020
This same question gets asked on literally a daily basis. The problem is not fsolve. It lies in understanding nonlinear equations, and things like basins of attraction. Finally, part of the problem lies in understanding numerical computation in floating point arithmetic, because you have lots of exponents in there. Tiny changes in a parameter will result in huge differences, perhaps in some terms suddenly going into the complex domain.
Without looking seriously at your equations, except to note they form an incredible mess of terms, perhaps even a hundred lines or so in length. I see no trig functions or other periodic functions, so I'll predict there are problably only a few dozen or so real solutions. There will almost certainly be multiple solutions, if any solutions exist at all. (The presence of periodic functions will often turn a problem with finitely many solutions into usually one with infinitely many solutions.)
For example, here is ONE of the 8 equations posed to be solved:
F(1) = - (x(6)^(4-4*n)*((x(1)^2*n^2*x(6)^(2*n-2)*(r-1)^2*(c-1)^2*(x(1)*x(6)^n*(x(1)*x(4)*n*x(6)^(n-1)*(r-1)*(c-1) - x(1)*x(6)^n*(x(2)*(x(5) + x(5)^2 + x(1)*n*x(6)^(n-1)*(r-1)*(c-1) + x(1)*n*x(6)^(n-1)*x(5)*(r-1)*(c-1)+1) + x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x(7))+1)^(1/x(8))*(x(5)^2+1)*(n-1)^3*(f-1)^3*(r-1)^4*(c-1)^4*(1/(exp(-x(6)*x(7))+1)^(1/x(8))-1)) - a;
I should probably have split it into multiple lines to make it possible to read without scrolling too far to the right.
ANY numerical solver is sensitive to initial guesses. Change the start point, get a completely different result. This is the concept of a basin of attraction, thus the set of start points that will result in any given solution. A basin of attaction can sometimes be a very strangely shaped set, especially so in 8 dimensions.
As I said, your problem is not in fsolve. It lies in assuming that you can just throw any complete mess of computations at a computer and expect a reasonable result, without also understanding the methods that must be used to solve the problem.
3 comentarios
Alex Tekin
el 25 de En. de 2020
John D'Errico
el 26 de En. de 2020
I answered the same question a day or so ago, but the question, and my lengthy answer and followup comments got deleted with it.
Is there a way to find all solutions of a nonlinear multi-variate probem?
No, in general this is not possible. In fact, it is provably true that you cannot do so for many actually simple looking provblems. Nothing stops you from using multi-start methods with different random starting points to hope to gain a solution. But at best you can only hope to find perhaps many of the solutions. To know that you have found them all would require bounds on the derivatives of your function within regions, which could allow you to exclude a possible solution in that region. (I recall seeing work on global solvers some years ago, try to achieve exactly this sort of thing. Those ideas won't go anywhere on such a nasty problem. 8 dimensional spaces are big, and the derivatives of your expressions will be really nasty.)
Worse, the very fact that fsolve fails when given a start point away from the solution tends to imply that your function has nasty derivatives. Exponentials, and lots of exponents in general make that just expected.
Can I suggest a different method?
No. Too often I see people create massive complicated systems like this, then expecting their powerful computer to make short work of it. Not gonna happen most of the time. Computers are not yet that powerful. At least some of the time, you cannot even work with the expressions involved using double precision arithmetic. The problem is though, using higher precision is usually a route to failure too, since high precision computation is so slow to work with.
At best, you could consider using vpasolve, using different start points. So a numerical solver in the symbolic toolbox. Such an approach will be highly problematic, and even if you make any progress at all, it will be incredibly slow. Again, high precision symbolic computations are terribly slow.
My suggestion, if anything would work is to step back, to reformulate your problem. I presume this problem comes from some real world system, and is an approximation thereof. You need to reduce the complexity of your approximation, eliminating terms that are of little significance. This is a difficult thing to do, and requires sometimes great skill and true understanding of the problem. But done well, it can make a once impossible problem solvable.
Or, you can keep trying to hack this problem to death, hopefully before it does the same to you.
Alex Tekin
el 26 de En. de 2020
Categorías
Más información sobre Mathematics 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!