Warning when runing fsolve
Show older comments
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
Answers (1)
John D'Errico
on 13 Nov 2018
0 votes
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.)
Categories
Find more on Mathematics 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!