- 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.
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
0 个评论
采纳的回答
Gayatri
2024-4-3
Hi Bibhudatta,
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)
Please refer the below documentation for ‘optimoptions’ function:
I Hope it helps!
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!