Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions lectures/newton_method.md
Original file line number Diff line number Diff line change
Expand Up @@ -1090,7 +1090,7 @@ $$
\end{aligned}
$$

Set the tolerance to $1e-15$ for more accurate output.
Set the tolerance to $10^{-15}$ for more accurate output.

```{exercise-end}
```
Expand All @@ -1112,16 +1112,21 @@ initLs = [jnp.repeat(5.0, 3), jnp.ones(3), jnp.array([4.5, 0.1, 4.0])]
Let's run through each initial guess and check the output

```{code-cell} ipython3
:tags: [raises-exception]

for attempt, init in enumerate(initLs, start=1):
print(f"Attempt {attempt}: Starting value is {init} \n")
%time p = newton_nd(lambda p: e(p, A, b, c), init, tol=1e-15, max_iter=15)
try:
%time p = newton_nd(lambda p: e(p, A, b, c), init, tol=1e-15, max_iter=15)
except Exception as err:
print(f"Failed: {err}")
print("-" * 64)
```

We can see that Newton's method may fail for some starting values.

The first starting value $p_0 = (5, 5, 5)$ fails because its first Newton step overshoots to negative prices, so $\sqrt{p}$ is not defined and the iteration breaks down.

The other two starting values converge to the same equilibrium.

Sometimes it may take a few initial guesses to achieve convergence.

Substitute the result back to the formula to check our result using the second initial guess which converges
Expand Down
Loading