Multiple solutions using fsolve
182 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi, I've been trying to solve a set of nonlinear equations in many variables. I see that multiple solutions exist for these and fsolve does not output all of them. I'm attaching the code for a simple example to illustrate this.
How do i extract all possible solutions from this?
Many Thanks,
Chandra.
The set of equations in the following example have 2 sets of solutions and fsolve outputs just one of them and gives an exit flag 1. On solving these equations by hand, i found that the solution to the variable a3 is quadratic and has 2 solutions which leads to a set of multiple solutions for all other variables.
% clear
% clc
function [] = nonlinsolve()
%%Solution from fsolve
options = optimset('Display','Iter');
[sol,fval,exitflag] = fsolve(@sol_nonlin,zeros(1,15),options)
%%The solution i am looking for
a0 = 0;a(1)=a0;a(2)=a0;a(3)=2+2*sqrt(2);a(4)=2.6955;a(5)=3.6131;a(6)=a0;
a(7)=a0;a(8)=a0;a(9)=a0;a(10)=a0;a(11)=a0;a(12)=a0;a(13)=a0;a(14)=a0;
a(15)=a0;
f = sol_nonlin(a)
function f = sol_nonlin(a)
f(1) = -a(2)^2/4;
f(2) = a(1) + a(2) - a(2)*a(5);
f(3) = - a(5)^2 + 2*a(5) + a(3) - (3*a(2)*a(9))/2 + 1;
f(4) = a(7) + 3*a(9) - 3*a(5)*a(9);
f(5) = a(2) - (a(2)*a(3))/2;
f(6) = a(3) + 2*a(4) + 2*a(5) - a(3)*a(5) - a(2)*a(7);
f(7) = 2*a(6) + 2*a(7) + 3*a(9) - (3*a(14)*a(2))/2 - (3*a(3)*a(9))/2 ...
- 2*a(5)*a(7);
f(8) = 2*a(10) + 3*a(14) - 3*a(14)*a(5) - 3*a(7)*a(9);
f(9) = - a(3)^2/4 + a(3) - (a(2)*a(6))/2 + 1;
f(10) = a(6) + 2*a(7) + 3*a(8) - a(10)*a(2) - a(3)*a(7) - a(5)*a(6);
f(11) = - a(7)^2 + 2*a(10) + 3*a(11) + 3*a(14) - (3*a(15)*a(2))/2 ...
- (3*a(14)*a(3))/2 - 2*a(10)*a(5) - (3*a(6)*a(9))/2;
f(12) = 3*a(12) + 3*a(15) - 3*a(15)*a(5) - 3*a(14)*a(7) - 3*a(10)*a(9);
f(13) = a(6) - (a(11)*a(2))/2 - (a(3)*a(6))/2;
f(14) = 2*a(10) + a(11) - a(12)*a(2) - a(10)*a(3) - a(11)*a(5) - a(6)*a(7);
f(15) = 2*a(12) + 3*a(15) - (3*a(13)*a(2))/2 - (3*a(15)*a(3))/2 ...
- 2*a(12)*a(5) - (3*a(14)*a(6))/2 - 2*a(10)*a(7) ...
- (3*a(11)*a(9))/2;
f(16) = 3*a(13) - 3*a(10)*a(14) - 3*a(13)*a(5) - 3*a(15)*a(7) ...
- 3*a(12)*a(9);
0 commentaires
Réponses (2)
bym
le 3 Sep 2011
using a starting vector of
xo = [0 0 5 3 4 0 0 0 0 0 0 0 0 0 0]
[sol,fval,exitflag] = fsolve(@sol_nonlin,xo,options)
converges to your desired solution
sol =
Columns 1 through 8
-0.0000 -0.0000 4.8284 2.6955 3.6131 0.0000 0.0000 0.0000
Columns 9 through 15
-0.0000 -0.0000 -0.0000 0.0000 -0.0000 -0.0000 0.0000
Walter Roberson
le 3 Sep 2011
fsolve() is not suitable for finding multiple solutions, except through the mechanism of running multiple times with different x0 until the number of distinct solutions found has accumulated to the number desired.
fmincon() of the square of sol_nonlin() can be a better tool (using the usual trick that zero solving can be expressed as minimizing the square of the function); you would work that by partitioning the permitted range of one of the variables, forcing it to adjust all the other variables to try to fit that one variable in to the target range. Knowing where and how finely to partition might not be simple, though, not unless you are allowed to use some prior knowledge or there is a useful approximation you are permitted to use.
Voir également
Catégories
En savoir plus sur Surrogate Optimization dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!