Minimize multivariable function with multivariable nonlinear constraints in MATLAB
21 views (last 30 days)
Show older comments
Hi !
So I'm trying to :
- minimize a function (non linear and multivariable)
- with constraints also non linear, multivariable and with inequations (maybe we can use slack variables) and equations
And for now I've tried this
x=[H, P, L, A, B, M]; %name of my variables
fun=@(x) (x(1)*x(3)*cos(x(4))); %function to minimize
nonlcon = % ??????
x0=[0,0 ,0 ,0 ,0 ,0] %I will have to find a first solution
A=[x(3)*cos(x4), x(6)*cos(x5),x(3)*sin(x4)+ x(6)*sin(x5)]; %constraints with inequality
b=[12.5, 12.5,25]; %boundary for constraints with inequality
Aeq=[x(1)*cos(x(2)), x(3)*cos(x(4))]; %constraints with equality
beq=[x(1)-14,x(6)*cos(x5)]; %boundary for constraints with inequality
x = fmincon(fun,x0,A,b,Aeq,beq);
but this only works for linear constraint and can't understand how works nonlcon in
Can you help, thanks :)
1 Comment
Torsten
on 23 Oct 2023
I'm not sure which nonlinear constraints you try to set with your A, b, Aeq and beq.
A and Aeq must have 6 columns and b and beq must have as many rows as A resp. Aeq in order that
A*x <= b or Aeq*x = beq
make sense.
Answers (2)
Bruno Luong
on 23 Oct 2023
x0 = [0;0;0;0;0;0];
x = fmincon(@mycost,x0,[],[],[],[], [],[],@mycon)
function f = mycost(x)
f = (x(1)*x(3)*cos(x(4)));
end
function [c,ceq] = mycon(x)
A=[x(3)*cos(x(4));
x(6)*cos(x(5));
x(3)*sin(x(4))+ x(6)*sin(x(5))];
b = [12.5; 12.5; 25];
c = A-b;
Aeq=[x(1)*cos(x(2));
x(3)*cos(x(4))]; %constraints with equality
beq=[x(1)-14;
x(6)*cos(x(5))];
ceq = Aeq-beq;
end
0 Comments
See Also
Categories
Find more on Systems of Nonlinear Equations 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!