Warning when runing fsolve
显示 更早的评论
When I run fsolve, there's a warning:
Warning: Trust-region-dogleg algorithm of FSOLVE cannot handle non-square systems; using Levenberg-Marquardt algorithm instead.
My code is here,and the four result have one negative number which is not what it shuold be.
x0 = [0 0 0 0];
options=optimset('Display','iter');
x = fsolve(@(x)myfun(x,f,u_R,u_G,u_B),x0);
function F = myfun(x,f,u_R,u_G,u_B)
F1=(f(1))-(x(1)*u_R(1,1)+x(2)*u_R(1,2)+x(3)*u_R(1,3)+x(4)*u_R(1,4))*10;
F2=(f(2))-(x(1)*u_G(1,1)+x(2)*u_G(1,2)+x(3)*u_G(1,3)+x(4)*u_G(1,4))*10;
F3=(f(3))-(x(1)*u_B(1,1)+x(2)*u_B(1,2)+x(3)*u_B(1,3)+x(4)*u_B(1,4))*10;
F4=(f(4))-(x(1)*u_R(2,1)+x(2)*u_R(2,2)+x(3)*u_R(2,3)+x(4)*u_R(2,4))*6000;
F5=(f(5))-(x(1)*u_G(2,1)+x(2)*u_G(2,2)+x(3)*u_G(2,3)+x(4)*u_G(2,4))*4000;
F6=(f(6))-(x(1)*u_B(2,1)+x(2)*u_B(2,2)+x(3)*u_B(2,3)+x(4)*u_B(2,4))*1000;
F=[F1;F2;F3;F4;F5;F6];
end
回答(1 个)
John D'Errico
2018-11-13
0 个投票
You don't tell us what the parameters are, so we cannot help you more. But you can help yourself easily by use of the proper tools.
- A system with more equations than unknowns will generally never have an exact solution. This is why fsolve burped at you.
- Using a nonlinear solver to solve a linear problem is silly. The solution will be inefficient, nor will it be as accurate as a linear solver. Instead, use backslash, or any tool designed to solve a linear system of equations. (help slash)
- Do you even know a non-negative solution exists? Just because you want the solution to be non-negative, does not mean you will get what you want.
- If you desire a non-negative solution, then use lsqnonneg. It will find the best possible non-negative solution (subject to tolerances.)
类别
在 帮助中心 和 File Exchange 中查找有关 Mathematics 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!