Non linear optimisation using solver based approach

2 ビュー (過去 30 日間)
Bibhudatta
Bibhudatta 2024 年 4 月 3 日
コメント済み: Bibhudatta 2024 年 4 月 5 日
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!
  1 件のコメント
Bibhudatta
Bibhudatta 2024 年 4 月 5 日
Thanks Gayatri , this really helped .

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSolver 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