Issues in the constraint functions of the Optimization Problem solving

5 views (last 30 days)
Vivek on 31 Jan 2023
Edited: Torsten on 2 Feb 2023
I want to add more than two constraints which are linear, nonlinear and with both equality and inequality signs. As per the MATLAB documentation the examples shown are mostly of same variables which are written as array Examples.
I am using the following shown constraint for the optimisation. The constraint function is named as "area", this same function is called for the 'nonlcon' (default function for constraints).
#1 The equations commented are also to be considered as Constraints for the Optimisation. Do MATLAB optimisation considers this kind of constraint equations?
#2 How to check whether all constraints are satisfied.
function [c,ceq]= area(x0)
M=5;
x0=[5,8];
M2=m(M,x0(1));
M3=m(M2,x0(2));
M4=m(M3,(x0(1)+x0(2)));
beta1=b(M,(x0(1)));
beta2=b(M2,(x0(2)));
beta3=b(M3,((x0(1)+x0(2))));
% M*sin(beta1)==M2*sin(beta2) & M2*sin(beta2)==M3*sin(beta3)
% (M4/M) <= 0.38
% beta1,beta2,beta3 < 62 degrees (This can be written in terms of Thetas)
% Some more constraints will be added
c=[];
ceq = log(2.4/((2.8*M*(sin(beta1)^2))-0.4)) + log(2.4/((2.8*M2*(sin(beta2)^2))-0.4)) + log(P(x0))
end
Below code shows the use of constraint function 'area' in the optimisation algorithm as "nonlcon".
%Initial Condition
% x0=[5,5] ;
% Lower bounds
lb=[1,1];
% Upper Bounds
ub=[30,40];
%constraint
nonlcon=@area
opts = optimoptions('fmincon','PlotFcn',["optimplotx","optimplotfunccount","optimplotfvalconstr","optimplotfval"],'Display','iter')
opts1 = optimoptions(opts,'MaxIterations',50,'StepTolerance',1e-9,'ConstraintTolerance',1e-9)
The optimisation is stopped between saying the below shown statement and then after enabling Feasibility Mode also the error is shown which is also mentioned in the end.
Converged to an infeasible point.
fmincon stopped because the size of the current step is less than
the value of the step size tolerance but constraints are not
satisfied to within the value of the constraint tolerance.
<stopping criteria details>
Consider enabling the interior point method feasibility mode.
%Initial Condition
x0=[5,5] ;
% Lower bounds
lb=[1,1];
% Upper Bounds
ub=[30,40];
%constraint
nonlcon=@area
opts = optimoptions('fmincon','PlotFcn',["optimplotx","optimplotfunccount","optimplotfvalconstr","optimplotfval"],'Display','iter', ...
'Algorithm','interior-point','EnableFeasibilityMode',true)
opts1 = optimoptions(opts,'MaxIterations',50,'StepTolerance',1e-9,'ConstraintTolerance',1e-9); % Recommended
Converged to an infeasible point.
fmincon stopped because it is unable to find a point locally that satisfies
the constraints within the value of the constraint tolerance.
<stopping criteria details>
Even after changing the Constraint Tolerance it is not helping. Tried in the range 1e-9 to 1e-3
Thank you!
Vivek on 1 Feb 2023
The m and b are the external functions used to calculate the 'Mach' and 'Beta' for the given 'x0'
Vivek on 1 Feb 2023
@Walter Roberson These angles will be used in objective function and other constriants also . If we convert it to sind() the same range will be used in Objective function i.e., [-1,1]. So I guess it will change the values in Objective function.

Sulaymon Eshkabilov on 31 Jan 2023
Edited: Sulaymon Eshkabilov on 31 Jan 2023
There should be elementwise operations in ceq formulation if M2, beta1, beta2 and P are vectors.

Matt J on 31 Jan 2023
Edited: Matt J on 31 Jan 2023
function [c,ceq]= area(x0)
M=5;
% x0=[5,8];
M2=m(M,x0(1));
M3=m(M2,x0(2));
M4=m(M3,(x0(1)+x0(2)));
beta1=b(M,(x0(1)))*180/pi;
beta2=b(M2,(x0(2)))*180/pi;
beta3=b(M3,((x0(1)+x0(2))))*180/pi;
c(1)=M4-0.38*M;
c(2:4)=[beta1,beta2,beta3]-62;
ceq(1) = log(2.4/((2.8*M*(sin(beta1)^2))-0.4)) + log(2.4/((2.8*M2*(sin(beta2)^2))-0.4)) + log(P(x0));
ceq(2) = M*sin(beta1)-M2*sin(beta2) ;
ceq(3) = M2*sin(beta2)-M3*sin(beta3) ;
end
Matt J on 2 Feb 2023
@Vivek I think you need to consider the possibility that your constraints might truly be infeasible. First, however, you should plot the constraint functions over the bounded region lb<=x<=ub and see if they are simultaneously satisfied anywhere. Because you only have two unknowns, this should be tractable. If you discover a region where they are satisfied, you should choose your initial guess x0 to lie in/near that region.
Torsten on 2 Feb 2023
Edited: Torsten on 2 Feb 2023
Using exponential function will change the range of all numbers and it cant be used in further calculations.
Taking the exponential of a constraint does not change anything in the range of the parameters.
It doesn't matter whether you set
log(x)-2 = 0
or
exp(log(x)-2) = exp(0)
as a constraint.

Categories

Find more on Solver Outputs and Iterative Display in Help Center and File Exchange

R2022a

Community Treasure Hunt

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

Start Hunting!