nonlcon with 2 possible values

조회 수: 1 (최근 30일)
Alessia De Iuliis
Alessia De Iuliis 2021년 3월 4일
답변: Nipun 2024년 6월 7일
I am using fmincon to optimize a space trajectory. My controls are the thrust three directions (radial(Tr), tangential(Tt) and normal(Tn)).
During my trajectory, I want the thrust to be either equal to the maximum possible value (Tmax) available or null. To express this constrain I want to use
sqrt(Tr^2+Tt^2+Tn^2)
ceq=[ or
sqrtT(r^2+Tt^2+Tn^2)-Tmax
How can I express this nonlinear constrain in my script? is it possibile to write the constrain with an or operator?

답변 (1개)

Nipun
Nipun 2024년 6월 7일
Hi Alessia,
I understand that you want to apply a nonlinear constraint to your optimization problem in MATLAB using fmincon, where the thrust can either be zero or the maximum possible value (Tmax). Here's how you can define this constraint:
function [c, ceq] = thrustConstraint(x)
Tmax = ...; % Define your Tmax value here
Tr = x(1); % Radial thrust
Tt = x(2); % Tangential thrust
Tn = x(3); % Normal thrust
thrust = sqrt(Tr^2 + Tt^2 + Tn^2);
% Nonlinear equality constraints
ceq = [thrust; thrust - Tmax];
% No inequality constraints
c = [];
end
When using fmincon, specify this function as the nonlinear constraint function.
Hope this helps.
Regards,
Nipun

카테고리

Help CenterFile Exchange에서 Nonlinear Optimization에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by