GitHub

@@ -15,15 +15,6 @@ kernelspec:

1515

:depth: 2

1616

```

171718-

In addition to what's in Anaconda, this lecture will require the following library:

19-20-

```{code-cell} ipython

21-

---

22-

tags: [hide-output]

23-

---

24-

!pip install interpolation

25-

```

26-2718

## Overview

28192920

In this lecture we continue the study of {doc}`the cake eating problem <cake_eating_problem>`.

@@ -47,9 +38,7 @@ We will use the following imports:

47384839

```{code-cell} ipython

4940

import matplotlib.pyplot as plt

50-

plt.rcParams["figure.figsize"] = (11, 5) #set default figure size

5141

import numpy as np

52-

from interpolation import interp

5342

from scipy.optimize import minimize_scalar, bisect

5443

```

5544

@@ -211,7 +200,7 @@ class CakeEating:

211200

"""

212201213202

u, β = self.u, self.β

214-

v = lambda x: interp(self.x_grid, v_array, x)

203+

v = lambda x: np.interp(x, self.x_grid, v_array)

215204216205

return u(c) + β * v(x - c)

217206

```

@@ -533,7 +522,7 @@ class OptimalGrowth(CakeEating):

533522

"""

534523535524

u, β, α = self.u, self.β, self.α

536-

v = lambda x: interp(self.x_grid, v_array, x)

525+

v = lambda x: np.interp(x, self.x_grid, v_array)

537526538527

return u(c) + β * v((x - c)**α)

539528

```

@@ -609,7 +598,7 @@ def K(σ_array, ce):

609598

u_prime, β, x_grid = ce.u_prime, ce.β, ce.x_grid

610599

σ_new = np.empty_like(σ_array)

611600612-

σ = lambda x: interp(x_grid, σ_array, x)

601+

σ = lambda x: np.interp(x, x_grid, σ_array)

613602614603

def euler_diff(c, x):

615604

return u_prime(c) - β * u_prime(σ(x - c))

Read the original on github.com ↗