Error using matlab.internal.math.interp1 Input coordinates must be real.
global vlast1 vlast2 beta delta theta k0 kt At p1 p2
hold off
hold all
vlast1=20*ones(1,40);
vlast2=vlast1;
k0=0.4:0.4:16;
kt11=k0;
kt12=k0;
beta=0.98;
delta=0.1;
theta=0.36;
A1=1.75;
p11=0.9;
p12=1-p11;
p21=0.4;
p22=1-p21;
A2=0.75;
numits=250;
for k=1:numits
for j=1:40
kt=k0(j);
At=A1;
p1=p11;
p2=p12;
%we are using a bounded function minimization routine here
z=fminbnd(@valfunsto,0.41,15.99);
v1(j)=-valfunsto(z);
kt11(j)=z;
At=A2;
p1=p21;
p2=p22;
z=fminbnd(@valfunsto,0.41,15.99);
v2(j)=-valfunsto(z);
kt12(j)=z;
end
if k/50==round(k/50)
plot(k0,v1,k0,v2)
drawnow
end
vlast1=v1;
vlast2=v2;
end
hold off
%optimal plotting prgram for the plans
%plot(k0,kt11,k0,kt12)
function val=valfunsto(k)
global vlast1 vlast2 beta delta theta k0 kt At p1 p2
g1=interp1(k0,vlast1,k,’linear’);
g2=interp1(k0,vlast2,k,’linear’);
kk=At*kt^theta-k+(1-delta)*kt;
val=log(kk)+beta*(p1*g1+p2*g2);
val=-val;
end
This codes from the textbook The ABCs of RBCs. Once I run them, the error-
Error using matlab.internal.math.interp1
Input coordinates must be real
keeps coming up. Is there anything wrong with the code?global vlast1 vlast2 beta delta theta k0 kt At p1 p2
hold off
hold all
vlast1=20*ones(1,40);
vlast2=vlast1;
k0=0.4:0.4:16;
kt11=k0;
kt12=k0;
beta=0.98;
delta=0.1;
theta=0.36;
A1=1.75;
p11=0.9;
p12=1-p11;
p21=0.4;
p22=1-p21;
A2=0.75;
numits=250;
for k=1:numits
for j=1:40
kt=k0(j);
At=A1;
p1=p11;
p2=p12;
%we are using a bounded function minimization routine here
z=fminbnd(@valfunsto,0.41,15.99);
v1(j)=-valfunsto(z);
kt11(j)=z;
At=A2;
p1=p21;
p2=p22;
z=fminbnd(@valfunsto,0.41,15.99);
v2(j)=-valfunsto(z);
kt12(j)=z;
end
if k/50==round(k/50)
plot(k0,v1,k0,v2)
drawnow
end
vlast1=v1;
vlast2=v2;
end
hold off
%optimal plotting prgram for the plans
%plot(k0,kt11,k0,kt12)
function val=valfunsto(k)
global vlast1 vlast2 beta delta theta k0 kt At p1 p2
g1=interp1(k0,vlast1,k,’linear’);
g2=interp1(k0,vlast2,k,’linear’);
kk=At*kt^theta-k+(1-delta)*kt;
val=log(kk)+beta*(p1*g1+p2*g2);
val=-val;
end
This codes from the textbook The ABCs of RBCs. Once I run them, the error-
Error using matlab.internal.math.interp1
Input coordinates must be real
keeps coming up. Is there anything wrong with the code? global vlast1 vlast2 beta delta theta k0 kt At p1 p2
hold off
hold all
vlast1=20*ones(1,40);
vlast2=vlast1;
k0=0.4:0.4:16;
kt11=k0;
kt12=k0;
beta=0.98;
delta=0.1;
theta=0.36;
A1=1.75;
p11=0.9;
p12=1-p11;
p21=0.4;
p22=1-p21;
A2=0.75;
numits=250;
for k=1:numits
for j=1:40
kt=k0(j);
At=A1;
p1=p11;
p2=p12;
%we are using a bounded function minimization routine here
z=fminbnd(@valfunsto,0.41,15.99);
v1(j)=-valfunsto(z);
kt11(j)=z;
At=A2;
p1=p21;
p2=p22;
z=fminbnd(@valfunsto,0.41,15.99);
v2(j)=-valfunsto(z);
kt12(j)=z;
end
if k/50==round(k/50)
plot(k0,v1,k0,v2)
drawnow
end
vlast1=v1;
vlast2=v2;
end
hold off
%optimal plotting prgram for the plans
%plot(k0,kt11,k0,kt12)
function val=valfunsto(k)
global vlast1 vlast2 beta delta theta k0 kt At p1 p2
g1=interp1(k0,vlast1,k,’linear’);
g2=interp1(k0,vlast2,k,’linear’);
kk=At*kt^theta-k+(1-delta)*kt;
val=log(kk)+beta*(p1*g1+p2*g2);
val=-val;
end
This codes from the textbook The ABCs of RBCs. Once I run them, the error-
Error using matlab.internal.math.interp1
Input coordinates must be real
keeps coming up. Is there anything wrong with the code? interp1 error MATLAB Answers — New Questions