Using fmincon with nonlinear equalities

1 Ansicht (letzte 30 Tage)
Kimberley
Kimberley am 14 Mai 2014
Beantwortet: Alan Weiss am 14 Mai 2014
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.

Antworten (1)

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

Kategorien

Mehr zu Problem-Based Optimization Setup finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by