Too many output parameters error in Fsolve when I turn Jacobian On
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
Geoff Hayes
2019-6-6
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.
采纳的回答
Walter Roberson
2019-6-7
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 个评论
Walter Roberson
2019-6-7
"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.)"
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Systems of Nonlinear Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!