Solow-Swan Growth Model Analytical Solution, Numerical Solution, Linearization, and Relaxation

Production Functions

Box-Cox Transformation

Let us introduce symbols for output (Y), stock (K , labor (N), and (A).

ClearAll τ, yy, kk, nn, aa ∗ do not use caps for Mma symbols! ∗ Macroeconomists usually focus on relationshipsL that can be written as τ yy aa @ Š α ∗ τ kk + β ∗ τDnnH L eq1 = %; yy τ@ ê Š Dα τ kk +@ β τD nn @ D aa

 Y A   K    N (1) B F‡ @ D @ D Usually   0, 1 and   1  .

AH particularlyê L H popularL H choiceL for  is the Box-Cox transformation: ClearAll τH, x,L b xb − 1 τ x_ := b @ D eq1 @ D yy b −1 + −1 + kkb α −1 + nnb β aa Š + b b b

I M H L H L Implied Production Technology Let us look at the implied production technology. We can determine the implied relationship between output and inputs by using Solve:

ClearAll yy, kk, nn ∗ do not use caps for Mma symbols! ∗ Solve eq1, yy Flatten Simplify Quiet bc`yy = %;

@ D H 1 L yy → @aa 1 + −D1êê+ kkb α + êê−1 + nnb β b êê

: I I M I M M > 2 Solow_continuous.nb

1 b Y = A 1 − α − β + αKb + βNb (2)

You are most familiar with this whenê   1  . IH L M Constant

ces`yy = bc`yy . β → 1 − α Simplify

1 yy → aa −nnb −1 + α + kkb α b ê 8 < êê 1 b Y A  Kb  1   Nb (3) : ‡ I H L M > This is known as the constantê of substitution (CES) production function. A H L E Linear Production Technology

When b ‡ 1, the CES becomes the linear production function lpt`yy = bc`yy . b → 1 Simplify yy → aa 1 + −1 + kk α + −1 + nn β

Y = A 1 − α − βê +8α K + β

Y ‡ AHHK  1  L N L (5) Cobb-Douglas Production Technology H H L L When b  0, we get a log-linear technology.

Clear x, b Limit τ x , b → 0 Log x @ D @ @ D D x (Here’s one way to see that this is the case. Let Y ‡ e and use L’Hopital’s rule to show  Y  x.) So our@ D production relationship is linear in logs: + α + β ln Y  ln A ln K ln L H L (6) bc`yy yy . bc`yy b0`yy = Limit %, b → 0

1 yyê→ aa 1 + −1 + kkb α + −1 + nnb β b @ D 1 aa 1 + −1 + kkb α + −1 + nnb β b : I I M I M M > aa kkα nnβ I I M I M M Y = A Kα Nβ (7) When   1   this gives us the famous Cobb and Douglas (1927) production function (previously used by Wicksell). Solow_continuous.nb 3

b0`yy . β → 1 − α

Y  A K N1 (8) ê 8 < Application

Growth Accounting Solow Model: Analytical Solution

Population Growth but No Technical Change

ClearAll s, aa, k, α, δ, n

Fundamental@ DynamicD Equation Define capital per capita k : K N. nt Assuming N  N0 e n  0 , capital per capita evolves according to    K N K k   ê N N N H L  (17) K   n k N  The accounting relationship K  S   K makes this  S k   n   k (18) N We assume the behavior S  s Y , and we define y  Y N, so we get the fundamental dynamic equa- tion of theH SolowL model:  k  s y    n k (19) ê Production Technology H L Under constant returns to scale in capital and labor, Y = F K, N y = Y N = F K N, 1 = f k (20) We often assume a Cobb-Douglas production technology, so that @ D Y = AKα N1−α ê @ ê D @ D (21) y = A kα

y k_ := aa ∗ kα

@ D 4 Solow_continuous.nb

Production Technology: Graphical Illustration To illustrate this technology graphically, we need to assume values for our model parameters.

∗ choose parameters to match NFR ∗ prms`core = aa → 5.0, α → 0.36, β → 0.9, δ → 0.075, n → 0.01 ; Plot y k . prms`core, k, 0, 20 , HPlotLabel → "Cobb−Douglas ProductionL Function", AxesLabel → k, y 8 < @ @ D ê 8 < CobbDouglas Production Function y 8

14

12

10

8

6

4

2

k 5 10 15 20

Steady State of the Solow-Swan Model: C-D Technology

Solve vs. Reduce Recall our fundamental dynamic equation for the Solow-Swan model. With a Cobb-Douglas production technology this becomes  k  s A k    n k (22)

kdot k_ := s ∗ aa ∗ kα − δ + n ∗ k  At the steadyH stateL we have k  0, so we can see that

@ D 1 H L s A k = 1−α (23) ss δ+n To get this solution from Mathematica, we need to make our assumptions explicit. But because of the non-integerI M exponent on k, this is not quite enough. Solve primarily handles polynomial (or even ratio- nal) functions.

$Assumptions = 1 > s > 0 && aa > 0 && k ≥ 0 && k0 > 0 && 1 > α > 0 && 1 > δ > 0 && 1 > n > 0 && γ ≥ 0; Solve kdot k Š 0, k

Solve::nsmet: This system cannot be solved with the methods available to Solve.  α Solve@aa k @s D− k n + δD Š 0, k

When Solve fails, we can sometimes succeed by turning to Reduce, which also looks for a fuller charac- terization@ of the possibleH Lsolutions.D Solow_continuous.nb 5

Reduce s ∗ aa ∗ kα − δ + n ∗ k Š 0 && k ≥ 0, k, Reals Simplify

1 n + δ −1+α k Š 0 Š k @ aa s H L D êê Note that Reduce characterizes solutions as equalities. »» The first solution is a good reminder that there is more than one steady state. The second solution yields the result we were looking for. s ∗ aa 1 ss`k = Power , n + δ 1 − α 1 aa s 1−α n + δ B F In sum, the non-trivial steady state of the model can be characterized in terms of this steady-state value ofK k: O

1 s A k = 1−α (24) ss n+δ

Transformations Can Help Solve I M To help Mathematica along, look for ways to rewrite the equality we are trying to solve.

Solve kdot k k Š 0, k Simplify

Solve::ifun: Inverse functions are being used by Solve, so some solutions may not be found; use Reduce for complete solution information.  @ @ D ê D êê 1 n + δ −1+α k → aa s Note that Solve returns the solutions it finds as rules. :: >> The other obvious transformation does not work immediately (in Mathematica 9).

Solve kdot k kα Š 0, k Simplify

Solve::nsmet: This system cannot be solved with the methods available to Solve.  Solve@k−α aa@ Dkêα s − k n + Dδ êêŠ 0, k

However, we can again push things along by giving Mathematica a some guidance. Here is one approa@ch: H H LL D FullSimplify kdot k kα Solve % Š 0, k Simplify − 1−α + δ aa s k n @ @ D ê D Solve::ifun@ : Inverse functionsD êê are being used by Solve, so someHsolutionsL may not be found; use Reduce for complete solution information.  1 n + δ −1+α k → aa s

A related approach is to recognize that if we define z  k1 we can solve a linear equation in z: :: >> 6 Solow_continuous.nb

Clear α, s, aa, δ, n, z Solve s ∗ aa − δ + n ∗ z Š 0, z ss`z = z . % 1 @aa s D z → @ H L D n + δ ê P T aa s :n:+ δ >>

We then reverse the transformation to find the implied soln for kss.

1 ss`z 1−α % Š ss`k

1 aa s 1−α n + δ True K O Graphical Illustration of the Steady State

prms`s20 = Append prms`core, s → 0.20 ; Plot Evaluate s ∗ aa ∗ kα, δ + n ∗ k . prms`s20 , k, 0, 60 , AxesLabel → k, "s y\n δ+n k" , PlotLegends → "s y", " δ+n k" , Epilog → Gray, Dashed@ , Line ss`k,D0 , ss`k, s ∗ y ss`k . prms`s20 @ @8 H L < ê D 8 < s y n k 8 H L < 8 H L < 8 @88 < 8 @ D<< ê D

4

s y 3 n k

2

H L 1

k 10 20 30 40 50 60

Solutions for y and c Our steady-state value of k implies values for y and c.

Clear ss`y, ss`c ss`y, ss`c = y ss`k Simplify, 1 − s ∗ ss`y aa s α aa s α aa @ 1−α , aa D1 − s 1−α 8 n + δ < 8 @ D êên + δ H L <

: K O H L K O > Solow_continuous.nb 7

Comparative Statics ss`kyc = ss`k, ss`y, ss`c ; ss`exogs = s, aa, δ, n ; ss`dkdx = D ss`k, ss`exogs Simplify ss`dkdx 8 Sign Simplify< ss`k8 1 1< −1 −1 ss`dkdx Š @ 8, , ,êê s −1 + α aa −1 + α H −1L+ α H n +Lδ −1 + α n + δ

1,I1, −M1, −1 I M I M I M : > TrueH L H L H L H L H L H L 8 < ss`dydx = D ss`y, ss`exogs Simplify ss`dydx Sign Simplify α ss`y 1 1 −1 −1 ss`dydx Š @ 8 , <,D êê , Simplify 1 − α s α ∗ aa n + δ n + δ êê êê α α 1 1 aa s aa s aa s aa s aa α 1−α 1−α α 1−α α 1−α n+δ n+δ n+δ n+δ − , : , , > êê s −1 + α 1 − α s −H1 + α L sH −1 +Lα

1, 1, −I1, −M1 I M I M I M : > True H L H L H L 8 < Exercise: explain why the following is false. (Hint: compare each element, and review the definition of y .) ss`dydx Š D y k , k . k → ss`k ∗ ss`dkdx Simplify

False@D H @ @ D D ê L êê 8 Solow_continuous.nb

plot01 = Plot s ∗ aa ∗ kα, δ + n ∗ k . prms`s20, k, 0, 60 ; GraphicsGrid Show plot01, Plot s ∗ aa ∗ kα . s → s ∗ 1.1 . prms`s20, k, 0, 60@8 , PlotStyleH → RedL ,

10 20 30 40 50 60 10 20 30 40 50 60 increase  increase n 5 5 4 4 3 3 2 2 1 1

10 20 30 40 50 60 10 20 30 40 50 60

The effects on c are slightly more complicated. An increase in s may either raise or lower consumption, depending on whether  is greater than or smaller than s. (We will come back to this.) This is because an increase in s raises k and thus raises y, but it reduces how much is consumed from any given income.

ss`dcdx = D 1 − s ss`y, ss`exogs Simplify ss`dcdx Sign Simplify α ss`y α − s 1 −1 −1 ss`dcdx Š @1H− s L 8 <,D êê , , Simplify 1 − α 1 − s s α α ∗ aa n + δ n + δ êê êê α α 1 1 aa s aa s aa s aa s aa s − α 1−α −1 + s 1−α −1 + s α 1−α −1 + s α 1−α n+δ n+δ n+δ n+δ H L , : , − , −> êê s −1 + α H−1 + αL sH −1 +Lα H L s −1 + α

−SignH s L− αI , 1M, −1,H−1 L I M H L I M H L I M : > True H L H L H L 8 @ D < Golden Rule The “golden rule of capital accumulation” sets steady-state consumption as high as possible. Given our Cobb-Douglas functional form, we can solve quickly for the optimal saving rate.

ss`c = y ss`k − n + δ ss`k FullSimplify Solve D ss`c, s Š 0, s

Let us approach@ D thisH moreL slowlyêê and gain some intuition in the process. Our comparative@ @ staticsD showD us that increasing the saving rate raises the steady-state per capita capital stock (and thus income per capita). Of course, if the saving rate is higher and income is higher, the effect on consumption is unclear. Since consumption per capita is 1  s f k , in the steady-state, we want to

H L @ D Solow_continuous.nb 9 Let us approach this more slowly and gain some intuition in the process. Our comparative statics show us that increasing the saving rate raises the steady-state per capita capital stock (and thus income per capita). Of course, if the saving rate is higher and income is higher, the effect on consumption is unclear. Since consumption per capita is 1  s f k , in the steady-state, we want to maxs,k 1 − s f k (25) s.t. s f k = n + δ k H L @ D gr`objH= 1 −Ls @f Dk + λ s f k − n + δ k λ = λ dsk D @gr`objD H , sL, k, ; gr`focs = dskλ ∗ 1, 1, λ Š 0 Thread; Labeled H L @ D H @ D H L L TableForm@ gr`focs88 , TableHeadings<

A DMore Traditional Presentation @8

Let us think of css as a function of kss, and then make css as big as possible. Clear css, kss, n, δ, gold`k css kss_ := y kss − n + δ kss Solve D css k , k Š 0, k Flatten Simplify Quiet gr`k =@k . %; D @ D @ D H L gr`c =@css@ gr`k@ D D SimplifyD êê; êê êê ∗ must êhave c>0 ∗ kmin, kmax = kss . Solve css kss Š 0, kss . prms`s20 Quiet; Plot css k@ . prms`s20D êê , k, kmin, kmax , AxesLabel → "kss", "css" , HEpilog → Thin, GrayL , Dashed, Line kmin, gr`c , kmax, gr`c . prms`s20 8 < ê @ @ D D ê êê @ @ D ê 8 < 8 < 8 @88 < 8 << ê D

Analytical Transition Dynamics  Recall that we found that k  s A k    n k. This describes the dynamic evolution of the system. We can simulate this numerically, but we would like to have some analytical results. We would like an analytical solution not just for the steady state but also for the transition path. H L Transformation Following Sato (1963 REStud) or Lewis (1983 SIAM), we transform the non-linear differential equation  k  s A k    n k into a linear differential equation, which can be easily solved analytically. We will use a familiar trick: defining z  k1 so that

= − α −α (26) z 1 Hk kL  Plugging k  s A k    n k into this gives −α α z = H1 − αL k s A k − δ + n k 1−α = 1 − α s A − δ + n k (27) H L = 1 − α s A − 1 − α δ + n z H L H H L L CHECKH WORK:L I H L M RemoveH zL, k H L H L ClearAll z, zdot, k, k0, t, α z k_ := k1−α @ D zdot = D z k t , t @ D zdot . k' t → s ∗ aa ∗ k t α − δ + n ∗ k t FullSimplify %@Š D1 − α ∗ s ∗ aa − 1 − α ∗ δ + n ∗ z k t Simplify @ @ @ DD D Generalê 8 Solution@ D @ D H L @ D< êê H L H L H L @ @ DD êê  Recall that the general solution of y  a y  b is given by y   b  C ea t, where C is a constant of intergra-  a tion determined by y 0  y0. Our expression for z is in this form, with a   1     n and b  1   s A. So our general solution is

s A z t = + C ã− 1−α δ+n t (28) δ+n H L H L H L H L s A So z approaches itsH steady-stateL H L value of over time. n @ D Using DSolve In Mathematica, we can use DSolve to find the analytical solution to linear DEs:

Remove z ClearAll t, α, s, aa, δ, n, z0 ztsoln01 = DSolve z' t Š 1 − α s ∗ aa − 1 − α δ + n z t , z 0 Š z0 , z, t 1 @ D Note that the@ solution is a function Dof t. This looks a bit messy, so let us simplify it: z t_ := z . ztsoln01@8 @ Dt H L H L H L @ D @ D < DP T z t Simplify Apart

@ D H ê L@ D @ D êê êê Solow_continuous.nb 11

A s A s  1 n t z t   z0   (29) n   n   or equivalently H L H L

H L − 1−α n+δ t δz = δz0 ã (30) This makes it clear that over time z is closing the gap between it and its steady-state value. Half the gap H L H L is closed when z  1 2 z0. Solve Log 1 2 Š − 1 − α n + δ t, t % . prms`core H ê L @ @ ê D H L H L D Solvingê for k[t] Finally, we would like an expression for k t . Recalling that z  k1 we get

1 A s A s 1 1 1 n t (31) k t   k0   n   n   H L CHECK WORK using Mathematica:H L H L H L ClearAll k, k0 1 1−α k t_ := z t 1−α . z0 → k0 ; aa s aa s 1 k t Š Power@ D + k01−α − ãt −1+α n+δ , Simplify n + δ n + δ 1 − α @ D @ D ê 9 =   VERIFICATION: verify this solution by formingH LkH andL showing that this into k  s k    n k identi- cally.@ D B K O F êê The obvious Mathematica test works out less than ideally: H L test = D k t , t Š s ∗ aa ∗ k t α − n + δ k t Simplify We can verify that by inspection but I had to play around to get Mathematica 9 to recognize it directly.

test = D@k@tD, tD Š s ∗ aa ∗ k@tDα − Hn + δL k@tD êê PowerExpand FullSimplify % PowerExpand Simplify

A minor @manipulation@ D D leads to immediate@ D H success,L @ D however.êê êê testêê = D k t , t êêk t Š s ∗ aa ∗ k t α−1 − n + δ PowerExpand FullSimplify

Transition Paths @ @ D D ê @ D @ D H L êê êê Assume that the economy is in a steady state initially. If the saving rate increases once and for all, what does the transition to the new steady state look like? The initial steady state level of k, y, c is given by

Clear "ss01`∗" ∗ the steady state values ∗ H L ss`kyc = ss`k, y ss`k , 1 − s ∗ y ss`k @ D HWe will begin at an initial steady state.L We increase saving at t  0. The increased saving rate implies a new value8 for the steady@ state.D H To plotL the@ transitionD< from the initial to the new steady state, we need to work with numerical values for our model parameters. 12 Solow_continuous.nb

ss20`k, ss20`y, ss20`c = ss`kyc . prms`s20 ∗ initial steady state ∗ prms`s30 = Append prms`core, s → .30 ; ss30`k, ss30`y, ss30`c = ss`kyc . prms`s30 ∗ new steady state ∗ 8 < ê H L @ D 8Plot the transition from the initial< to the newê steady state.H L ClearAll aa, s, n, δ, k, k0, α ∗ recall our analytical solution for k given prms and k0 ∗ aa s aa s 1 −α − +α +δ an`k t_ @:= Power + k01 D − ãt 1 n , n + δ n + δ 1 − α H L ∗ construct the time paths when savingH jumpsL H Lat time 0∗ xp01`s@ t_D := PiecewiseB K 0.2, t < 0 O, 0.3 F xp01`k t_ := Piecewise ss20`k, t < 0 , an`k t . prms`s30 . k0 → ss20`k xp01`yH t_ := aa ∗ Power xp01`k t , α . prms`core L xp01`c@t_D := 1 − xp01`s@8t8 ∗ xp01`y<

1 aa ∗ s aa ∗ s −α kt = + k01−α − ã α−1 n+δ t 1 ; n + δ H L H L nH+Lδ xp01`kt = kt . s → xp01`s t H L.Hprms`coreL . k0 → ss`k . prms`s20 ; α xp01`ytK = aa ∗Kxp01`kt . prms`coreO ; O xp01`ct = 1 − xp01`s t ∗ xp01`yt . prms`core; ê 8 @ D< ê ê 8 ê < ê H @ DL ê Solow_continuous.nb 13

tstart = −10; tstop = 120; ∗ saving shock at 0 ∗ xp01`p12 = Plot xp01`kt, t, tstart, tstop , AxesLabel → t, "k t " , PlotRange → All, 0, 30 ; xp01`p22H = Plot xp01`ytL, t, −10, tstop , AxesLabel → t, "y t " , PlotRange →@ All, 0, 83 ; < xp01`p21 = Plot 8xp01`ctH ,L

Transition Paths using NDSolve We can use NDSolve to solve the Solow-Swan model numerically and plot our solution. Our law of motion remains:

k = s A kα − δ + n k (32)

ClearAll k NDSolve k' t Š xp01`s t ∗ aa ∗ k t α − n + δ k t , k 0 Š ss20`k . prms`core, H L k, t, tstart, tstop % @ D nm01`k =@8k .@%D1 @ D @ D H L @ D @ D < ê nm01`pkt8 = Plot nm01`k

Plot nm01`k t − xp01`k t , t, tstart, tstop , ImageSize → Small The errors@8 for income and consumption

ClearAll@ yn@, cnD ; @ D 8 < D GraphicsRow Plot nm01`y t − xp01`y t , t, tstart, tstop , PlotLabel → "income error" , Plot nm01`c@ tD − xp01`c t , t, tstart, tstop , PlotLabel → "consumption error" @8 @ @ D @ D 8 < D @ @ D @ D 8 < D

Solow-Swan model: Linearization

Review: Linearization Around a Steady State

Recall the first-order Taylor approximation of a function f :

Series f k , k, kss, 1 Normal  Application@ @ D to8 k  f k

where   f k . We know the analytical solution: k  t k  k0 e H L (36) DSolve δk' t Š λ δk t , δk 0 Š δk0 , δk t , t

Application@8 @ toD the Solow-Swan@ D @ D Model< @ D D Recall our steady-state solution:

ClearAll s, aa, k, kss, α, δ, n, λ ss`k

Recall our@ fundamental dynamics: D kdot k Linearize the dynamic adjustment process around the steady state:

Series@ Dkdot k , k, k0, 1 Normal ∗ linearization around k0 ∗ % . k − k0 → δk . k0 → ss`k Simplify ∗ evaluate at kss ∗

@ @ D 8

kdot k ∗ find the derivative ∗ dfdk = D s ∗ aa ∗ kα − δ + n ∗ k, k dfdk@ŠDα s aa kα−1 − δ + n Simplify H∗ evaluate derivative atL the steady state ∗ dfdkss =@dfdk . k →H ss`kL SimplifyD H L êê HSo linearizing around the steady state by means of a first-orderL Taylor approximation gives  k   1   n ê 8k < êê (37) We have written the linear approximation as a homogeneous linear difference equation, so the solution is H L H L δk=δk0 ã α−1 n+δ t (38) We can restate this in terms of levels: the solution to the linear-approximation DE is H L H L   1 n t k  kss  k0  kss e (39) Linear ApproximationH L H LTransition Paths H L We can now describe the evolution of an economy that experiences a once and for all increase in s. The initial steady state level of k is given by

ss`k xp20`kss = ss`k . prms`s20; The paths k t , y t , c t can then be written as Mathematica function:

ss20`k = ss`k . êprms`s20; la01`k t_ := @ D @ D @ D Piecewise ss20`k, t < 0 , ss`k + ss20`k − ss`k ã− 1−α δ+n t . prms`s30 ê @ D H L H L la01`y t_ := aa ∗ la01`k t α . prms`core; A88 << H L ê E la01`c t_ = 1 − xp01`s t ∗ la01`y t ; la01`c t @ D @ D ê Next, plot@ theD timeH paths: @ DL @ D tstart@= D−10; tstop = 120; prms`s30 la01`pkt = Plot la01`k t , t, tstart, tstop , AxesLabel → t, "k t " , AxesOrigin → 0, 0 , PlotStyle → Red ; la01`pyt = Plot la01`y t , t, tstart, tstop , AxesLabel → t, "y t " , AxesOrigin →@ 0, 0 @, PlotStyleD 8 → Red ; < la01`pct = Plot 8la01`cH tL ,< t, tstart, tstop8 ,

H L 16 Solow_continuous.nb

Show la01`pkt, xp01`pkt

Plot la01`k t − xp01`k t , t, tstart, tstop @ D

@ @ D @ D 8

Relaxation Algorithm

The material on relaxation is based on: Lecture Notes in Quantitative Dynamic by Thomas Steger, University of Leipzig. The object is to apply a relaxation (i.e., successive approximation) algorithm to a discretization of our differential equation. "The relaxation method determines the solution by starting with a guess and improving it, iteratively. As the iteration improves the solution, the result is said to relax to the true solution." (Press et al., p. 765)

Background: ODEs

Consider an autonomous system of N ordinary differential equations (ODEs), with n1 constraints on the initial values, supplemented by N  n1 final conditions. (It is easy enough to include “running equations” (i.e., static equations satisfied at every t) as well, should we need them. Also, we can accommodate T  .)  x t  f x t B[x(0)]=0 (40) F[x(T)]=0 H L @ H LD N N N n1 N n2 with f :    , B :    , F :    , where n1  n2  N. N A solution is a function x  x t which maps each t+ into a unique x∈ such that this system is satisfied.

Discretization @ D  We will approximate the system x  f x by a "finite difference equation". First, create a “time mesh”

mT  t0, t1, t2, ..., tM . (In the simplest case, the mesh equals successive natural numbers.) We will only consider  times in the time mesh: t  mT. Since x  f x , it will be approximately true that H L x  x  t  t f x (41) v1 8 v v1 v < v for all v  0, 1, 2, ..., M  1 . Here we adoptH L the shorthand that x denotes the value of x at tv for v  0, 1, 2, ..., M , and x  x  x 2 for v{0,1,2,...,M-1}. A good solution for the x will push the differ- H L @ Dv v1 v ence between the two sides towards 0. So we are trying to solve 8 < xv+1 − xv − tv+1 − tv f xv Š 0 (42) 8 < H L ê Looking for zeros is the job of root-finding algorithms, and that is the approach we will use.

Notice: TheH initial problemL @ of Dsolving an ODE has been transformed into a problem of solving a set of N M algebraic equations. N M + N = N M + 1  . (43) ð of finite difference equation ð of boundary conditions Corresponding, we are trying to find N M  1 values, the M  1 different values of each of the N variables. A

solution consists of a set of points xv with v  0, H1, 2, ...L, M in the state space of dimension N (approximating the solution trajectory). H L 8 < Solow_continuous.nb 17

Corresponding, we are trying to find N M  1 values, the M  1 different values of each of the N variables. A

solution consists of a set of points xv with v  0, 1, 2, ..., M in the state space of dimension N (approximating the solution trajectory). H L Background on FindRoot 8 <

ClearAll f1 f1 x_List := ArrayReshape Cos x 1, 1 , Sin x 1, 2 , −Sin x 2, 1 , Cos x 2, 2 , 2, 2 ∗ Cos ð@ 1D ,Sin ð 2 ,−Sin ð 3 ,Cos ð 4 ∗ @ D f1 ArrayReshape@8 π@ 3P, π T3D, π 3@, πP 3 ,TD 2, 2 @ P TD @ P TD< 8

FindRoot@ needs initial@8 valuesê forê eachê variable.ê < Here8 we< DinitializeD the entire time path to the final steady- state value.@8 @ D< 8 @8 ê ê ê ê < 8

8 @ D @ D< ê @ D Example: Solution@ by Discretization8

ClearAll x, x0, x1, x2, x3 sys = x0 − 1,

@ x1 + x0 D x1 − x0 + 3 Power , 3 , : 2 x2 + x1 x2 − x1 + 3 Power , 3 , B 2 F x3 + x2 x3 − x2 + 3 Power , 3 B 2 F

initVals = x0, 1B , x1, 1 ,F x2, 1 , x3, 1 ; xm`soln = FindRoot sys, initVals > 88 < 8 < 8 < 8 << @ D 18 Solow_continuous.nb

ListLinePlot Transpose 0, 3, 6, 9 , x0, x1, x2, x3 . xm`soln , PlotMarkers → Automatic, AxesOrigin → 0, 0

Example with@ Indexed@8 8Variables< 8 < ê

mT = Range 0, 150, 3 ; ∗ a time mesh with dtŠ3 ∗ Length mT

We do not want@ to createD allH those variables by hand. In MaLthematica, we can use indexed variables. ClearAll@ xD iT = Range 0, Length mT − 1 ; ∗ time indexes; first index is 0 ∗ x v + 1 + x v sysCore =@TableD x v + 1 − x v + 3 Power , 3 , v, Most iT ; 2 @ @ D D H L sysCore ;; 5 Column @ D @ D vars = Table x Bv @, v,DiT @; D B F 8 @ D

ClearAll x DSolve x' t Š −x t 3, x 0 Š 1 , x, t Quiet asolnVals = Map x . % 1 , mT N; ∗ analytical solution values ∗ @ D GraphicsRow ListLinePlotA9 @ D asolnVals@ D @,Dxm02`vals= E, êêPlotRange → All , ListLinePlot@Transposeê P T mTD ,êê xm02`valsH − asolnVals asolnVals ,L PlotRange@8→ All @8 < D @ @8 H L ê

ClearAll x RecurrenceTable

@ D x v + 1 + x v x v + 1 − x v Š −3 ∗ Power , 3 , x 0 Š 1.0 , x, v, 0, 50 B 2 @ D @ D Simplest: @ DApplication@ D to theB Solow-SwanF Model@ D > 8

Recall the fundamental dynamic equation:

k = s A kα − δ + n k (45)

Setting Up the System H L ClearAll fxv, err, x, k mT = Range 0, 150 ; ∗ so dt=1 ∗ iT = Range 0, Length mT − 1 ; ∗ zero−based integer indexes ∗ kdot k @. prms`s30 ∗ Dthe numerical f ∗ ∗ use indexed@ variablesD H : indexL by eq number and time step ∗ fxv = % . @k → x v +@1 +Dx vD H 2 L ∗ create@ D ê the main Herror equations hereL, dt=1 ∗ ss`sysCoreH = Table x v + 1 − x v − 1.0 fxv, v, Most iT ; ∗discretizationL ∗ ∗ imposeê 8initialH @ andD or@finalDL ê

ssn`kt = vars . ssn`soln; ∗ rlx`kt=Table sol i,2 , i,1, nX nM,nX ; alternative approach ∗ ssn`yt = aa ∗ ssn`ktα . prms`s30; ssn`ct = 1 − sê ∗ ssn`yt . prms`s30; H @ @@ DD 8 H L

rlx`pkt = ListPlot Transpose vT, rlx`kt , PlotRange → All, AxesLabel → t, "k t " , PlotStyle → Red, PointSize Small ; rlx`pyt = ListPlot Transpose vT, rlx`yt , PlotRange → All, AxesLabel → t,@"y t " , PlotStyle@8 →

Dynamic Inefficiency8

prms`s40 = Append prms`core, s → 0.4 Static Comparison: if we compare steady states, consumption is of course lower away from the Golden Rule. @ D 1 − s ss`kα . prms`s40 1 − s ss`kα . prms`core . s → 0.36

HDynamicL Comparison:ê more important, we could raise consumption every period by raising the saving Hrate toL the goldenê rule. ê 8 < ss40`k = ss`k . prms`s40; Plot 1 − s ss`kα . prms`s40, 1 − s an`k t α . prms`core . s → 0.36 . k0 → ss40`k , t, 0, 150 , êPlotRange → All, AxesOrigin → 0, 3 @8H L ê DynamicH L Efficiency@ D ê ê 8 < ê 8 << 8 < 8

Cass-Koopmans Model