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

2 个评论

Torsten
Torsten 2018-11-13
编辑:Torsten 2018-11-13
Why do you use "fsolve" for a linear system of equations ?
Write your system as
A*x=b
and solve for x using
x=A\b
Best wishes
Torsten.
thanks, I will try it.

请先登录,再进行评论。

回答(1 个)

John D'Errico
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.
  1. A system with more equations than unknowns will generally never have an exact solution. This is why fsolve burped at you.
  2. 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)
  3. 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.
  4. 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 的更多信息

标签

提问:

2018-11-13

评论:

2018-11-13

Community Treasure Hunt

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

Start Hunting!

Translated by