Non linear optimisation using solver based approach

2 次查看(过去 30 天)
I have been assigned to minimize x(1)^2+x(2)^2+x(3)^2 subject to 1-x(2)^-1*x(3)>=0,x(1)-x(3)>=0,x(1)-x(2)^2+x(2)*x(3)-4=0,0<=x(1)<=5,0<=x(2)<=3,0<=x(3)<=3.
I have written the following script for the above optimization problem:
% Solver based approach for non linear problem
%define the objective function
f=@(x) (x(1)^2+x(2)^2+x(3)^2);
%initial feasible solution
x0=[0 0 0];
A=[0 -1 1;-1 0 1];b=[0;0];%linear inequality constraints
Aeq=[];beq=[];
lb=[0;0;0];ub=[5;3;3];%define the bounds
c=[];%there is no non linear inequality
ceq=@(x) (x(1)-x(2)^2+x(2)*x(3)-4);%non linear equality constraint
nlcon=@(x) deal(c,ceq(x));
[x,fval]=fmincon(f,x0,A,b,Aeq,beq,lb,ub,nlcon)
I am getting the values 4,0.0003,0.0002 and these values meet all the conditions except one which is x(1)-x(2)^2+x(2)*x(3)-4=0. With the above values, this expression becomes -0.00000003 which is not 0 obviously
Kindly check and give feedback and suggest corrections

采纳的回答

Gayatri
Gayatri 2024-4-3
Hi Bibhudatta,
  • Given the optimization problem and the MATLAB script, it appears that you have encountered a common issue in numerical optimization which is the tolerance of the solution. This discrepancy is likely due to the tolerance settings of the ‘fmincon’ solver.
  • You can adjust the tolerance settings of ‘fmincon’ using the ‘optimoptions' function.
Here's how you can adjust the tolerance settings in your script:
% Define the objective function
f = @(x) (x(1)^2 + x(2)^2 + x(3)^2);
% Initial feasible solution
x0 = [0, 0, 0];
% Linear inequality constraints
A = [0, -1, 1; -1, 0, 1];
b = [0; 0];
% Bounds
lb = [0; 0; 0];
ub = [5; 3; 3];
% Nonlinear equality constraint
ceq = @(x) (x(1) - x(2)^2 + x(2)*x(3) - 4);
nlcon = @(x) deal([], ceq(x));
% Create options with a tighter constraint tolerance
options = optimoptions('fmincon', 'ConstraintTolerance', 1e-10);
% Solve the optimization problem with the specified options
[x, fval] = fmincon(f, x0, A, b, [], [], lb, ub, nlcon, options)
Local minimum found that satisfies the constraints. Optimization completed because the objective function is non-decreasing in feasible directions, to within the value of the optimality tolerance, and constraints are satisfied to within the value of the constraint tolerance.
x = 1x3
4.0000 0.0001 0.0001
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
fval = 16.0000
Please refer the below documentation for ‘optimoptions’ function:
I Hope it helps!

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Solver Outputs and Iterative Display 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by