Consider a law of motion for the Solow growth model, in which the trajectory of capital is determined non-linearly:

$$ k_{t+1} = Ask_{t}^\alpha + (1-\delta)k_t $$

Here \(k\) is capital stock, and \([A,s, \alpha, \delta] \) are positive parameters.

The following code excerpts are from

g(k;p) is a function that represents the capital transition function, given the parameter set p and argument k.

g(k; p) = p.A * p.s * k^p.α + (1-p.δ)*k

Then ts_plot takes 5 arguments, where the first argument is a function. Note that the function contains iteration loop that allows for the storage of updated values of capital in each index of vector x. Then it returns the output plot.

using Plots 

function ts_plot(f, xmin, xmax, x0; ts_length=6)
    x = zeros(ts_length)
    x[1] = x0
    for t in 1:(ts_length-1)
        x[t+1] = f(x[t])
    plot(1:ts_length, x, ylim=(xmin, xmax), linecolor=:blue, lw=2, alpha=0.7)
    scatter!(x, mc=:blue, alpha=0.7, legend=false)

Lastly, the capital stock starts with 0.25, and the parameter values are determined. Note that p is a NamedTuple with 6 arguments, defined to encapsulate all parameters. Invoking ts_plot produces following plot.

p = (A=2, s=0.3, α=0.3, δ=0.4, xmin=0, xmax=4)

ts_plot(k -> g(k; p), p.xmin, p.xmax, k0)