Using fmincon with nonlinear equalities

조회 수: 1 (최근 30일)
Kimberley
Kimberley 2014년 5월 14일
답변: Alan Weiss 2014년 5월 14일
Hi,
I have an optimization problem where the objective is linear as are the constraints so I have been using Linprog to solve it. Here is my current code...
lb = zeros(4,1);
lb(1) = 2;
lb(3) = 31.350;
lb(4) = 31.350;
ub = Inf(4,1);
ub(4) = 33;
ub(3) = 33;
A = zeros(2,4);
A(1,1) = .024632; A(1,2) = .02383; A(1,3) = -1; b(1) = -32.300;
A(2,1) = .0605; A(2,2) = .017796; A(2,4) = -1; b(2) = -31.280;
Aeq = zeros(2,4); beq = zeros(2,1);
f = zeros(4,1);
f(1) = -1;
f(2)= -1;
[x fval] = linprog(f,A,b,Aeq,beq,lb,ub);
Now I want to add another constraint that is not linear. I know I have to change the solver to fmincon, but as I understand it you can't just add nonlinear constraints to the command window, you have to make a file for them. And I also have to create a file for my objective function?
Can someone please explain to me the changes I need to make to go from using linprog to fmincon.
Thank you.

답변 (1개)

Alan Weiss
Alan Weiss 2014년 5월 14일
You can use this for your objective function:
fun = @(x)f'*x;
For nonlinear constraints, see the documentation.
Alan Weiss
MATLAB mathematical toolbox documentation

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by