Hello there thank you for the reply. What happened is that I transcribed the code from someone else and that error I carelessly carried over.
My issue persists even when I set out the line of code that runs the internal solver. I can get an answer but it is an answer which doesn’t make sense from the perspective of an Euler equation where future consumption is valued less than present consumption. The inequality constraint is not used optimally because consumption in both periods doesn’t equal the budget.
using JuMP
using Ipopt
function Euler(x...)
beta = 0.9
t = 2
x = [i for i in x]
logx = log.(x)
answer = -(beta .^ ((transpose(1:1:t) .- 1) * logx))
return answer[1]
end
##
m = Model(Ipopt.Optimizer)
@variable(m, x[1:2] >= eps())
@NLconstraint(m, x[1]+x[2] <=20)
register(m, :Euler, 2, Euler, autodiff=true)
@NLobjective(m, Min, Euler(x...))
# set_start_value(x[1], 10.0) setting starting values gives me errors
# set_start_value(x[2], 10.0) setting starting values gives me errors
optimize!(m)
@show value.(x)
I don’t know if you are familiar with MATLAB but what is inexplicable to me is why I can get the solver to converge perfectly on the right answer every time but I am having so much difficulty using Julia for the same basic problem
function V = FlowUtility(T, Beta, C)
%
% PURPOSE: calculates the total utility of consumption assuming an
% additively separable utility function and discount rate Beta
%
% INPUTS: C : Tx1 vector of independent variable
% T : scalar time
% Beta : scalar discount rate
%
% OUTPUT: V : -utility
% c = C(:,1);
t = 1:1:T;
V = Beta.^(t-1)*log(C);
V = -V;
return
Beta = 0.9;
T = 2;
K1 = 20;
lb = eps*ones(2,1);
ub = 20*ones(2,1);
guess = 10*ones(2,1);
A = ones(1,2)
opt = optimset('TolFun', 1E-20, 'TolX',...
1E-20, 'algorithm','sqp');
c = fmincon(@(C) FlowUtility(T,Beta,C),...
guess,A,K1,[],[],lb,...
ub,[],opt)