No solution with fsolve. Why do fsolve stop before doing any iterations?
3 views (last 30 days)
Show older comments
I have a system with 7 Equations and 7 variables. I think the system should be solvable, but there might be misspecifications I have overlooked(I have tried for days). When trying to solve matlab tells me that the system is without a solution before preforming any iterations. Display Message:
Norm of First-order Trust-region
Iteration Func-count f(x) step optimality radius
0 8 25.9606 0 1
fsolve stopped because the sum of squared function values, r, has gradient with
relative norm 0.000000e+00; this is less than options.TolFun = 1.000000e-01.
However, r = 2.596059e+01, exceeds sqrt(options.TolFun) = 3.162278e-01.
So the solution stops before doing iterations. Why is this and how do I fix it?
I have attetched the m-files, but they are a bit messy. Pasting the main features bellow. Call file:
x0 = [1.0 , 1.0 , 0.5 , 1.5 , 1.5 , 0.5 , 0.1];
options=optimset('Display', 'iter-detailed', 'Diagnostics', 'on' );
[z,fval,exitflag,output] = fsolve(@testsig,x0,options)
Function:
Function:
function G = sig(x)
global in1 in1f beta tauf l lf y yf B rr d PY aa h c b p
% Inputs from 1: y, yf, d, l, lf
x = zeros(7,1);
G = zeros(size(x));
G(1) = 1/(1+x(7)) - beta*x(1)*sum(((1-d)./(y-(1+x(7)).*(1-d)*B+(1+x(7)).*(1-d)*x(3)-l+(1+rr)*x(4))).*PY);
G(2) = 1/(1+rr) - beta*x(1)*sum((1./(y-(1+x(7)).*(1-d)*B+(1+x(7)).*(1-d)*x(3)-l+(1+rr)*x(4))).*PY);
G(3) = x(1) + x(3) + x(4) - in1;
G(4) = 1/(1+x(7)) - beta*x(2)*sum(((1-d)./(yf -tauf+(1+x(3)).*(1-d)*x(5)-lf+(1+rr)*x(6))).*PY);
G(5) = 1/(1+rr) - beta*x(2)*sum((1./(yf -tauf+(1+x(3)).*(1-d)*x(5)-lf+(1+rr)*x(6))).*PY);
G(6) = x(2) + x(5) + x(6) - in1f;
G(7) = B - x(3) - x(5);
All help is appreciated!
0 Comments
Answers (1)
Alan Weiss
on 18 Feb 2014
The gradient of your function is zero at x0. Perhaps you can start at a different point, or double-check that your "sig" function is doing what you think it should be doing. See the suggestions on what to do when fsolve fails.
Alan Weiss
MATLAB mathematical toolbox documentation
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!