# Optimization problem: matlab inbuilt function "getIpOptions" generates an error in fmincon

8 views (last 30 days)
suleiman abdullahi on 1 Jun 2020
Edited: suleiman abdullahi on 1 Jun 2020
This code is used to generated the minimum quantities of two good given a cost constraints. it is a simple optimization problem using "fmincon", however when i run the code i get this problem
%{
Unrecognized function or variable 'getIpOptions'.
Error in fmincon (line 822)
options = getIpOptions(options,sizes.nVar,mEq,flags.constr,defaultopt,10,0.01);
Error in langrangian (line 5)
[x,fval] = fmincon(@volume,[1 1],[],[],[],[],[0 0],[],@mycons);
%}
clear ;
clc;
close all;
[x,fval] = fmincon(@utility,[1 1],[],[],[],[],[0 0],[], @mycons);
% the utility function to be maximimzed
function u = utility(x)
u = x(1)^(1/3)*x(2)^(2/3);
end
% subject to the cost function below
function s = cost(x)
s = 10*x(1) + 4*x(2);
end
function[c,ceq] = mycons(x)
c = cost(x) - 100 ; % the cost function is less than 100 (equality constraint)
ceq = [] ; % we dont have non-linear equality constraints
end

Alan Weiss on 1 Jun 2020
You are trying to maximize utility, so you should minimize the negative of the utility. The following code runs without error for me:
[x,fval] = fmincon(@utility,[1 1],[],[],[],[],[0 0],[], @mycons)
% the utility function to be maximimzed
function u = utility(x)
u = x(1)^(1/3)*x(2)^(2/3);
u = -u;
end
% subject to the cost function below
function s = cost(x)
s = 10*x(1) + 4*x(2);
end
function[c,ceq] = mycons(x)
c = cost(x) - 100 ; % the cost function is less than 100 (equality constraint)
ceq = [] ; % we dont have non-linear equality constraints
end
Alan Weiss
MATLAB mathematical toolbox documentation

suleiman abdullahi on 1 Jun 2020
Thanks for effort, however, i still get this error even after copy-pasting your code:
% {
Unrecognized function or variable 'getIpOptions'.
Error in fmincon (line 822)
options = getIpOptions (options, sizes.nVar, mEq, flags.constr, defaultopt, 10,0.01);
Error in langrangian (line 5)
[x, fval] = fmincon (@volume, [1 1], [], [], [], [], [0 0], [], @ mycons);
%}
Alan Weiss on 1 Jun 2020
You might need to reinstall MATLAB®. Or at least Optimization Toolbox™.
Alan Weiss
MATLAB mathematical toolbox documentation
suleiman abdullahi on 1 Jun 2020