From 14696062fb73b4b9c75879389f8f5aa49434a2e2 Mon Sep 17 00:00:00 2001 From: Asish Kumar Date: Wed, 11 Nov 2026 11:10:48 +0000 Subject: [PATCH] [newton_method] Run all three starting values in Exercise 2 solution The solution looped over three initial price vectors in a cell tagged raises-exception. The first, p0 = (5, 5, 5), fails by design (its first Newton step makes prices negative, so sqrt(p) is NaN), but the exception ended the loop, so the other two starting values, which both converge to the same equilibrium, never ran. Catch the exception for each attempt and report it, so all three run, and drop the raises-exception tag. Update the text to explain why the first start fails and that the others converge. Also write the tolerance as 10^{-15}, since $1e-15$ rendered as '1e - 15' in math mode. Fixes #1115 --- lectures/newton_method.md | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lectures/newton_method.md b/lectures/newton_method.md index de9781892..42fd0a0a7 100644 --- a/lectures/newton_method.md +++ b/lectures/newton_method.md @@ -1058,7 +1058,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} ``` @@ -1080,16 +1080,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(lambda p: e(p, A, b, c), init, tol=1e-15, max_iter=15) + try: + %time p = newton(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