# Gradient optimization problem with fmincon

1 view (last 30 days)
Dai Nguyen on 19 May 2021
Edited: Torsten on 20 May 2021
Hi I'm currently working on an optimzation problem where I need to optimization a design dimension to minimize the ROI with Sequential Quadratic Programing with fmincon. However, I don't really know how the fmincon work and how my constrain will need to implement into the code. I'm new to matlab
Thank you for your time,
Here is my equation and constrain that I want to put in Matlab  with r is the radius and l is the length of the tank
Dai Nguyen on 19 May 2021
yeah you are right it doesn't depends. I think in this case imma minimize the volume

Sulaymon Eshkabilov on 19 May 2021
Here is a simple solution to your exercise. Adjust your constrains for r (radius) and l (length).
% NOTE: RL(1) is R and RL(2) is L.
ROI =@(RL) (.05*(509.7*pi(RL(1)^3+RL(1)^2*RL(2))+5.505e3*RL(1)^2)-509.7*pi*(RL(1)^3+RL(1)^2*RL(2))+5.505e3*RL(1)^2)/(509.7*pi*(RL(1)^3+RL(1)^2*RL(2))+5.505e3*RL(1)^3);
Rb = [0,0];
% NOTE: 0<=R<=5; 0<=L<=15; Thus, Rb= [0, 0]; and Lb = [5, 15];
Lb = [5, 15];
% No Other constraints are considered here
A = [];
b = [];
Aeq = [];
beq = [];
x0 = (Lb + Rb)/2;
RL = fmincon(ROI,x0,A,b,Aeq,beq,Lb,Rb);
R = RL(1);
L = RL(2);
fprintf('Found values: R = %f [ft] L = %f [ft] \n', [R, L])
Good luck.
Torsten on 20 May 2021
Edited: Torsten on 20 May 2021
The first constraint is linear, the second is superfluous and the third can be put in function "nonlcon".
Read the documentation of fmincon for more details.