Too many output parameters error in Fsolve when I turn Jacobian On

2 views (last 30 days)
Hi all
why do I get Too many output parameters error in Fsolve when I turn Jacobian On ? I have 9 variables to solve , where can be the problem ? and does the Jacobian matrix calculation help me if this is the iteration report ? :
Iteration Func-count f(x) step optimality radius
0 10 6.09647e+006 3.27e+005 1
1 20 5.00637e+006 1 2.98e+005 1
2 30 2.7289e+006 2.5 2.24e+005 2.5
3 40 37481.6 6.25 1.99e+004 6.25
4 50 5.77916 1.28439 192 15.6
5 60 2.82227e-007 0.0169644 0.0368 15.6
6 70 1.34282e-021 4.00165e-006 3.17e-009 15.6
7 80 8.78879e-025 2.98649e-013 1.58e-010 15.6
  2 Comments
Geoff Hayes
Geoff Hayes on 6 Jun 2019
farzad - please show the code that generates this error so that we can see what you are passing into the function and what you are expecting as outputs. The error messages is telling you that are expecting more output parameters than will actually be returned by the function.
farzad
farzad on 7 Jun 2019
Sorry can't share the code, I am solving for 9 variables, are they too many for Matlab 2007 ?

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 7 Jun 2019
When you turn on Jacobian, then you need to return the Jacobian as a second output, but only when it is asked for. You need to test nargout for that.
function [obj, J] = fun_to_solve(x)
obj = x.^2 - 10*x + 5;
if nargout > 1
J = 2.*x - 10;
end
end
  4 Comments
farzad
farzad on 7 Jun 2019
Thank you
Here you habe one function and the jacobian is the derivative of that one function, in my case I have muktuple functions, how Wil my Jacobian look like?
Walter Roberson
Walter Roberson on 7 Jun 2019
"If fun returns a vector (matrix) of m components and x has length n, where n is the length of x0, the Jacobian J is an m-by-n matrix where J(i,j) is the partial derivative of F(i) with respect to x(j). (The Jacobian J is the transpose of the gradient of F.)"

Sign in to comment.

More Answers (0)

Categories

Find more on Systems of Nonlinear Equations in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!