0
votes

I am working on an optimization problem where I want to maximize utility while searching over variables lx_init and kx_init. Each time I solve an issue with fmincon another one pops up. The error right now is..

"Not enough input arguments." "Failure in initial objective function evaluation. FMINCON cannot continue."

I have tried to trace back the error in debug mode but tracing back my error is proving difficult. The function is able to be evaluated on its own and spit back a value so I know the error is in the fmincon function. My Matlab experience is very minimal. I am sure there are other syntax errors I am guilty of and too naive to see. I will provide all variables so the code can be replicated.

A second question: I want to maximize my utility value here but also find the values of x and y given once the utility is maximized. However, we are also maximizing over lx_init and kx_init. How do I get the function to return x and y? Right now it is just returning the utility value.

Here is my function I am optimizing

function [utility, x, y] = utility_with_prod(gamma_X, gamma_Y, alpha_LX, alpha_KX, alpha_LY, alpha_KY, alpha_uX, sigma_U, sigma_X, sigma_Y, L_bar, K_bar, lx_init, kx_init)
   % X's production function
   x = gamma_X*((alpha_LX*lx_init^((sigma_X-1)/sigma_X)) + ((alpha_KX)*kx_init^((sigma_X-1)/sigma_X)))^(sigma_X/(sigma_X-1));

   % Y's production function
   y = gamma_Y*((alpha_LY*(L_bar-lx_init)^((sigma_Y-1)/sigma_Y)) + ((alpha_KY)*(K_bar-kx_init)^((sigma_Y-1)/sigma_Y)))^(sigma_Y/(sigma_Y-1));

   % utility function with nested production function
   utility = -(((alpha_uX*x^((sigma_U-1)/sigma_U)) + ((1-alpha_uX)*y^((sigma_U-1)/sigma_U)))^(sigma_U/(sigma_U-1)));
end

Here are my initial values

sigma_U= 0.5038;
sigma_X= 0.5029;
sigma_Y= 0.5029;

alpha_uX= 0.000236017865342454;

alpha_LX= 0.180813595922536;
alpha_KX= 0.819186404077464;
gamma_X= 1.768587207836113;

alpha_LY= 0.505368332690592;
alpha_KY= 0.494631667309408;
gamma_Y= 1.999942066647923;

lx_init = 1;
kx_init = 2;
L_bar = 3;
K_bar = 3;
x0 = [lx_init, kx_init];

and the optimization

utility = @(lx_init, kx_init)utility_with_prod(gamma_X, gamma_Y, alpha_LX, alpha_KX, alpha_LY, alpha_KY, alpha_uX, sigma_U, sigma_X, sigma_Y, L_bar, K_bar, lx_init, kx_init)

[optimal_lx_kx, utility_max, exitflag] = fmincon(utility, x0, [],[]) 
1
Your optimization problem does not involve any constraints, please consider using fminunc instead of fmincon in that case.Robert

1 Answers

1
votes
  • x0 in fmincon is a vector, that's an n by 1 matrix or 1 by n, here 1 by 2 ---> x0 = [lx_init, kx_init];

  • Function handle @(lx_init, kx_init) is different from @([lx_init, kx_init]).

    @([lx_init, kx_init])accepts only one input.

    @(lx_init, kx_init) accepts only two inputs, no more, no less

  • Also input variable should not be predefined value

  • Change @(lx_init, kx_init) to @(x) where x(1) = lx_init and x(2) = kx_init

To sum up

utility = @(lx_init, kx_init)utility_with_prod(gamma_X, gamma_Y, alpha_LX,alpha_KX, alpha_LY, alpha_KY, alpha_uX, sigma_U, sigma_X, sigma_Y, L_bar, K_bar, lx_init, kx_init)

is replaced by

utility = @(x)utility_with_prod(gamma_X, gamma_Y, alpha_LX, alpha_KX, alpha_LY, alpha_KY, alpha_uX, sigma_U, sigma_X, sigma_Y, L_bar, K_bar, x(1), x(2))