Convert fortran code to Matlab code C - Get result as complex numbers
Afficher commentaires plus anciens
Hello,
I tried to convert a fortran code to matlab code. I don't know why I get very weird resutl after running my Malab code (the result comprise of complex numbers).
Here is the fortran code http://www.jonathanheathcote.com/Macro2/FYMHW1
If someone could see what did I do wrong in converting, please kindly help me. Thanks so much.
% set parameter values
%
theta = 0.4; % production parameter
beta = 0.95; % subjective discount factor
delta = 0.1; % capital depreciation rate
A=6.0476;
% Horizon
T=38; %which is "capt" in fortran code
% Sequence of capital and consumption
kseq=zeros(T+1,1);
cseq=zeros(T+1,1);
%Initial capital
kseq(1)=10;
% Guess the range of initial consumption
cguessl=1;
cguessh=10;
%Iteration parameter
iter=0;
tol=0.01;
while gapk > 0.01 && iter < 1000
cguess=0.5*(cguessl+cguessh);
cseq(1)=cguess;
for i = 2:T+1
%Law of motion of capital
kseq(i) = A*(kseq(i-1))^theta+(1-delta)*kseq(i-1)-cseq(i-1);
%check whether capital goes negative, if so reduce guess for
%consumption c(1)
if kseq(i)<0
cguessh=cguess;
else
cseq(i)=beta*(1+theta*A*(kseq(i))^(theta-1)-delta)*cseq(i-1);
end
end
%Check terminal capital and adjust bounds of cguess effectively
if kseq(T+1)>0
cguessl=cguess;
else
cguessh=cguess;
end
gapk = abs(kseq(T+1));
iter=iter+1;
end
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Fortran with MATLAB dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!