1b.
Write down code to solve this problem for arbitary number of parameters, but make
sure your routine is stable to solve the problem for high values of
σ
%%%%%code for problem 1b%%%%%
%%%wrote the following function and saved as cake1b.m file%%%%%
function F = cake1b(w)
beta = 0.95;
R = 0.25;
sigma = .45;
betaR = (beta * R)^(1/sigma);
T = length(w);
F = ones(T, 1);
wbar = 100;
w = [wbar; w; 0];
for t= 2:(T+1)
F(t1) = betaR*(R*w(t1)w(t))  (R*w(t)w(t+1));
end
%%%%%%placed the following in the command window%%%%%%
plot(1:T+2,w, ':ks');
legend('W')
xlabel('time')
ylabel('W')
title('Plot of W')
pause(.001)
w0 = ones(10, 1);
options=optimset('Display','off');
[w,fval,exitflag] = fsolve(@cake1b,w0,options)
%%%output:
14 end
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document1c. Modify your code to incorporate a new law of motion
%%%%%code for problem 1b%%%%%
%%%wrote the following function and saved as cake1c.m file%%%%%
function F = cake1c(w)
beta = 0.95;
R = 0.25;
sigma = 0.45;
betaR = (beta * R)^(1/sigma);
T = length(w);
F = ones(T, 1);
This is the end of the preview. Sign up
to
access the rest of the document.
 Spring '10
 staff

Click to edit the document details