276
Appendix B: Software
In the loop, we use (11.1)–(11.4) to step the variables forward in time. After the
loop completes, the variables are plotted and the axes annotated.
% solow.m
clear all; close all;
k0=1;
% initial capital
delta=0.1;
% depreciation of capital
lambda=1;
% technology level
sigma=0.15;
% fraction of output to re-invest
Theta=0.7;
% Cobb-Douglas exponent of production
N=300;
% number of generations
kk=zeros(N,1); yy=kk; ii=kk; % initialize storage
kk(1)=k0;
% set values at initial time
yy(1)=lambda*k0ˆTheta;
ii(1)=sigma*yy(1);
for t=1:N-1
% and loop over later times
kk(t+1)=(1-delta)*kk(t)+ii(t); % (11.4)
yy(t+1)=lambda*kk(t)ˆTheta;
% (11.1)
ii(t+1)=sigma*yy(t+1);
% (11.3)
end
tt=1:N;
plot(tt,kk,’k’,tt,yy,’k-.’,tt,ii,’k--’,’LineWidth’,2);
xlabel(’Time step t’);
ylabel(’k_t, y_t, i_t’)
legend(’Capital k_t’,’Output y_t’,’Investment i_t’)
B.8 The Donkey’s Solution
The script donkeys_solution.m calculates the optimum trajectory for the donkey as discussed in Sect. 11.5. First the parameters of the model are defined and used
to set up the matrix A, which encodes (11.49). This system of equations is solved in
the next step, which returns the integration constants c 3 and c 4 . The other two integration constants c 1 and c 2 are known from the main part of the text. Subsequently,
we insert the integration constants in (11.47) and (11.46) to prepare inline functions
x1 and x2 for the position of the donkey and its speed. Plotting both variables and
annotating the axes completes this script.
% donkeys_solution.m
clear all; close all
alpha=0.1;
% friction constant
L=100;
% distance to cover in [m]
T=20;
% time for the travel in [s]
t=0:0.1:T;
Précédent

- 282/292

Suivant