% Rsolution of cocacola can problem
clear all 
close all
clc
global PI c
% d is x(1)
% h is x(2)
 % Let the price c=10
 c=10;
 PI=3.14;
x0=[5;9]; % initial guess 
A=[2 -1]; %inequality contstriants
B=[0];
Aeq=[]; % we don't have equality constraints , empty brackets 
Beq=[];
LB=[5;4]; %lower and upper bounds
UB=[8;20];
options=optimset('display','iter','MaxFunEvals',1000);
optimsolution=fmincon(@cost,x0,A,B,Aeq,Beq,LB,UB,@nonlinearconst,options)


 
 function y=cost(x)
 global c PI
 y=c*PI*(x(1).*x(2)+(x(1)).^2/4);
 end
 
function [c,ceq] = nonlinearconst(x)
global PI
c = [];% we don't have nonlinear ineqaulity constraints
ceq = PI*(x(1))^2*x(2)/4-250;
end