a question on fsolve

1 visualizzazione (ultimi 30 giorni)
jinny zhou
jinny zhou il 18 Giu 2012
Dear Madam/Sir,
I am trying to solve a system of nonlinear equations with fsolve.
For example, to solve f(x) = x.^3 - b*10 = 0, where b is a known vector, say 100 by 1.
I tried to solve the equation in vector form or in scalar form (with loops), the results are not always the same from the 2 approaches, depending on the starting values chosen. I am wondering why this is the case? Could you please give me some hints? Thanks a lot!
Problem: sz and sx are not always equal to each other, why?!
please see the codes below:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
rand('state',2);
b = rand(100,1);
fun = @(x)(x.^3 + b*10);
options=optimset('Display','off');
start = -ones(100,1);
sx = fsolve(fun,start,options);
for i = 1:100
ifun = @(x)(x.^3 + 10*b(i));
sz(i,1) = fsolve(@(x)ifun(x), -2,options);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Risposte (1)

Sargondjani
Sargondjani il 18 Giu 2012
the problem in the first case is that matlab assumes that every x will show up in every equation. In other words, it will try to estimate a full Jacobian matrix. If you set: 'JacobPattern',speye(length(start)) in the options, the results should be the same
In this case i definitely advice to include the analytical jacobian, because that will be faster and better

Categorie

Scopri di più su Systems of Nonlinear Equations in Help Center e File Exchange

Tag

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by