Solving nonlinear equations using fmincon

조회 수: 28 (최근 30일)
MByk
MByk 2020년 7월 28일
댓글: Star Strider 2020년 7월 28일
Hello, I have 4 nonlinear equations with 4 unknows (x(1), x(2), x(3), x(4)). I can get solutions using "lsqnonlin" and "fsolve" but I'am having an error message when I use fmincon. How can I fix it? I also tried to create a function and put all equations inside but it is not working either. Thanks for the help.
Obj_Fun = @(x)[ ... ] % 4 equations in each row.
lb = [-1,-1,-1,-1];
ub = [1,1,1,1];
A = [];
b = [];
Aeq = [];
beq = [];
x0 = rand(1,4);
[x,fval,exitflag,output] = fmincon(Obj_Fun,x0,A,b,Aeq,beq,lb,ub)
Error using fmincon (line 635)
Supplied objective function must return a scalar value.
Error in FMinCon_Testing (line 30)
[x,fval,exitflag,output] = fmincon(Obj_Fun,x0,A,b,Aeq,beq, ...

채택된 답변

Star Strider
Star Strider 2020년 7월 28일
The error is straightforward:
Error using fmincon (line 635)
Supplied objective function must return a scalar value.
This is the reason fsolve works, since it is a root-finding algorithm.
In order for this to work with fmincon (and certain other optimisation functions), you would need to do something like this:
[x,fval,exitflag,output] = fmincon(@(x)norm(Obj_Fun(x)),x0,A,b,Aeq,beq,lb,ub)
That will llikely work with fmincon. Whether it produces the desired result is less certain.
.
  댓글 수: 2
MByk
MByk 2020년 7월 28일
Yes! Thank you. :)
Star Strider
Star Strider 2020년 7월 28일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Systems of Nonlinear Equations에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by