- 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
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Gayatri
le 3 Avr 2024
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!
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Solver Outputs and Iterative Display dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!