a question on fsolve

2 次查看(过去 30 天)
jinny zhou
jinny zhou 2012-6-18
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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%

回答(1 个)

Sargondjani
Sargondjani 2012-6-18
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

类别

Help CenterFile Exchange 中查找有关 Systems of Nonlinear Equations 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by