Why does fsolve seem not iterate towards the solution?
Afficher commentaires plus anciens
Hello all,
I am trying to sovle a two non-linear equation system using fsolve and dogleg method. My objective function along with its jacobian is like this
function [F jacF]= objective(x)
F(:,1) = ((((x(:,2)./10).*k).*(x(:,1)./100)).^2).*(rZ - Rs) +(( Cmax .* ( x(:,1)./100 ) ).^2).*( w.^2.*(rZ - Rs) ) - (((x(:,2)./10).*k).*(x(:,1)./100));
F(:,2) = (x(:,2).*k).^2.*(iZ - w.*Ls) + (x(:,2).*k).^2.*x(:,1).*((w.*Ls)./200) + x(:,1).*((w.*Ls)/200).*(w.*Cmax).^2 + (w.*Cmax).^2 .*(iZ -(w.*Ls));
if nargout > 1 % need Jacobian
jacF = [- k - (k.^2.*x(:,2).*x(:,1).*(Rs - rZ))./50, - (k.^2.*x(:,2).^2.*(Rs - rZ))./100 - (Cmax.^2.*w.^2.*(Rs - rZ))./100;
2.*k.^2.*x(:,2).*(iZ - Ls.*w) + (k.^2.*Ls.*x(:,2).*w.*x(:,1))./100,(Ls.*Cmax.^2.*w.^3)./200 + (Ls.*k.^2.*x(:,2).^2.*w)./200];
end
end
Then my configuration for fsolve looks like this
options = optimoptions('fsolve','Display','iter-detailed','PlotFcn',@optimplotfirstorderopt);
% options.StepTolerance = 1e-13;
options.OptimalityTolerance = 1e-12;
options.FunctionTolerance = 6e-11;
options.MaxIterations = 100000;
options.MaxFunctionEvaluations = 400;%*400;
options.Algorithm = 'trust-region-dogleg';%'trust-region'%'levenberg-marquardt';%
% options.FiniteDifferenceType= 'central';
options.SpecifyObjectiveGradient = true;
fun= @objective;
x0 = [x1',x2'];
% Solve the function fun
[gwc,fval,exitflag,output,jacobianEval] =fsolve(fun,x0,options);
Being the values of the equations
Rs =
0.1640
Ls =
1.1000e-07
Cmax =
7.0000e-11
w =
1.7040e+08
rZ =
12.6518
iZ =
14.5273
K =
0.1007
x0 =
70.56 0.0759
My problem comes because I don't understand why fsolve seems not to iteratate over x(:,1) as i was expecting. I do know that the solution for the above system and parameters should be x1=58.8 and x2=0.0775.
In order to test the convergence of the method I am setting as initial guess x0 = [x1*(1+20/100) 0.0759] = [70.56 0.0759] ( 20 percent error in x1 and a higer value on x2), but the solution given by fsolve is the initial point, why is this? Am I doing something incorrect in my settings?
Thanks in advance
7 commentaires
Torsten
le 12 Sep 2019
What do you get for "res" if you insert the line
res = objective([58.8,0.0775])
before calling fsolve ?
Torsten
le 12 Sep 2019
If you divide the first equation by x1, then solve for x2 in terms of x1, insert the expression in equation 2 and multiply by the denominator, you arrive at a cubic polynomial in x2 that can be solved using "roots".
Torsten
le 12 Sep 2019
Ok, with some constants I get
a1*x1*x2^2 + a2*x1 + a3*x2 = 0 (1st equation after division by x1)
b1*x2^2 + b2*x1*x2^2 + b3*x1 + b4 = 0 (2nd equation)
Now you can either solve the first or the second equation for x1 and insert the expression in the other one.
In the end, you'll get a polynomial of degree 4 in x2 that can be solved using "roots".
Javier
le 12 Sep 2019
Torsten
le 12 Sep 2019
If you have a good starting guess ...
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Systems of Nonlinear Equations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

