Solow Model MATLAB Simulation Code

“Once you start thinking about (how the economy grows), you can’t think about anything else.”
— Robert E. Lucas
The Idea of the Solow Model
Robert Merton Solow, the 1987 Nobel laureate in economics, passed away on December 21, 2023, at the age of 99. This blog post was written in his memory1.
Although the Solow model’s assumptions are fairly strict2 and it has since given way to later models, he pioneered the neoclassical analytical paradigm of “economic growth”, and the “total factor productivity” (the Solow residual) that his conclusions produced has become one of the most important evaluation indicators of a contemporary economy.
Its conceptual framework is:
- Decompose the contribution to economic growth (output) into several basic factors: labor, capital, technological progress, population growth…
- The process of economic growth is the process of factor changes; we can try to characterize the dynamic process of factor growth.
- There is convergence in the dynamic changes of factors; the time-path of a factor moving from non-convergence to convergence is a balanced growth path of an economy.
Take the formula above, for example; simply put, it characterizes the relationship between the per-capita capital growth rate ($\dot{k}$) and the per-capita capital stock (${k}$).
Convergence means that after per-capita capital grows to a certain level, the growth rate becomes hard to increase further and instead approaches 0. In the formula, this is: $△k=0=\dot{k}=f(k)$.
Like the Malthusian population trap: when per-capita income rises, people get richer and are more likely to have children; the population grows, and per-capita income falls. When per-capita income falls, people get poorer and have fewer children; the population shrinks, and per-capita income rises again. This back-and-forth — the process that makes per-capita income tend toward stability — is the process in which per-capita income and its growth rate restrain each other.
The Solow model does further decomposition on top of this.
- A lower starting point means progress may be faster; a higher starting point means progress may be slower.
- What the Solow model tries to explain is the phenomenon that “low-income countries develop faster than high-income countries in the early stage”. For example, after World War II, postwar Asian countries entered a golden age of development. After the war people preferred saving, which also inspired Solow to assume an exogenous saving rate.
- The convergence property of the Solow model later inspired scholars to discuss whether the economic levels of high-income and developing countries would converge. See another blog post, Convergence: From the “Limit of a Formula” to the “Limit of Growth”.
Here I mainly introduce the MATLAB plotting code, so I won’t go into the mathematical proof. For a more detailed explanation of the Solow model, see:
- Solow Model
- Intermediate Macroeconomics | Lecture 3: The Solow Growth Model
- Advanced Macroeconomics Notes (Romer Edition)
The two core steady states of the Solow model:
Solving for the steady state:
$$ \dot{k}=sf(k)-(n+\delta)k=0 $$Solving for the golden rule:
$$ f^{\prime}(k_{\mathrm{gold}})=n+\delta $$MATLAB Convergence Plot

The plotting code is divided into four parts:
- Set parameters: initial per-capita capital, depreciation rate, saving rate, technological progress rate, total factor productivity growth rate, population growth rate, number of periods, and capital input elasticity.
| |
- Set the functions: $$f(k)=Ak^\alpha$$ $$\dot{k_t}=sf(k_t)-(n+g+d)k_t$$
| |
- Convergence condition:
naturally, this is $\dot{k_t}=sf(k_t)-(n+g+d)k_t=0$. So the logic of the code below is to compare
sy(k1,1)andnd(k1,1). When they are not equal, it increases or decreases per-capita capital $k$ based on the greater-than or less-than sign.
Here we set the capital motion equation to $\dot{k_t}=sf(k_t)-(n+g+d)k_t$, and based on its sign we set k to increase or decrease by one.
Actually, when considering the discrete case, the most precise expression is:
$$\dot{k_t}=\frac{sf(k_t)-dk_t}{1+g+n}$$that is:
$${k_{t+1}}=\frac{sf(k_t)+(1-d)k_t}{1+n+g}$$The equilibrium condition means ${k_{t+1}}={k_{t}}$; substituting and simplifying, only at equilibrium convergence can it be simplified to $0=\dot{k_t}=sf(k_t)-(n+g+d)k_t$. But out of equilibrium ($\dot{k_t} \neq 0$), writing the motion equation as $\dot{k_t}=sf(k_t)-(n+g+d)k_t$ is not rigorous.
For economics, both R and MATLAB are close to being defeated by Python. The remaining advantage of R is that statisticians at top journals will prioritize developing R packages.
Like Stata, MATLAB still holds the mainstream for now because most papers distribute code as .m and .do files. As models get more complex, Python has a bigger advantage in optimizing code and tuning algorithms for computation. I have seen quite a few new researchers doing macro models online starting to switch from MATLAB to Python to optimize their computation.
| |
- Plotting code
For example:
| |
The complete code is as follows:
| |
MATLAB Phase Diagram: Different Initial Capital
Compare two economies with all other parameters identical, differing only in initial per-capita capital $k_1$ (and thus in convergence direction).
Under the given parameters, the Solow model’s per-capita capital converges to a level of 149.8. So if a country’s initial per-capita capital is above this value, it will fall; if below, it will rise.
| |
MATLAB Shock Plot: Different Saving Rates
The core figure of modern macro DSGE models is one that shows how factors change after being hit by a shock.
The Solow model assumes the saving rate is exogenous. The code below assumes an initial saving rate of 0.4; with an initial per-capita capital of 6, the saving rate is later adjusted to 0.5.
What it finally computes is per-capita capital, per-capita output, the per-capita output growth rate (take logs of output then first-difference: $\log y_t-\log y_{t-1}\approx\frac{y_t-y_{t-1}}{y_{t-1}}$), and per-capita consumption.

| |

