Minimize multivariable function with multivariable nonlinear constraints in MATLAB
조회 수: 4 (최근 30일)
이전 댓글 표시
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
Torsten
2023년 10월 23일
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.
답변 (2개)
Bruno Luong
2023년 10월 23일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Nonlinear Optimization에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!