[newton_method] Exercise 2 solution stops after the first starting value
Maintainers usually reply within 1 day
@officialasishkumar is already working on this.
Since Nov 11, 2026.
- #1125 by @officialasishkumar — open
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 82/100
- Issue type
- Documentation
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- markdown, python
- Domain
- documentation
Research direction
Read lectures/newton_method.md around lines 1082–1095: the loop in the raises-exception cell and the paragraph that follows it. Confirm whether #1073 has landed so the multivariate call uses newton_nd, then wrap each attempt in try/except, drop the tag, and rewrite the prose so attempts 2 and 3 are reported as converging. Also fix the tolerance at line 1061 to $10^{-15}$ or inline code. Done when the built page shows all three attempts, the attempt-1 failure, and matching text.
Written by the indexing model from the issue text.
Description
While reviewing #1073 I noticed that the Exercise 2 solution only ever shows the first of its three starting values. The live page shows the same thing: the solution's output ends with the traceback from attempt 1.
What happens
The solution loops over the three initial price vectors in a cell tagged raises-exception (lines 1082–1090). Attempt 1, $p_0 = (5, 5, 5)$, fails as intended. Its first Newton step overshoots to $p \approx (-0.337, -0.337, -0.337)$, so $\sqrt{p}$ is NaN and newton raises "Solution not found with NaN generated". That exception ends the loop, so attempts 2 and 3 never run.
Here is what each starting value does when run on its own with the lecture's newton (tol=1e-15, max_iter=15):
| Attempt | Starting value | Outcome |
|---|---|---|
| 1 | $(5, 5, 5)$ | Fails at iteration 2, because the first step makes prices negative |
| 2 | $(1, 1, 1)$ | Converges in 6 iterations to $(1.4974, 1.4974, 1.4974)$ |
| 3 | $(4.5, 0.1, 4)$ | Converges in 8 iterations to the same point |
The text after the cell (lines 1091–1095) says it "may take a few initial guesses to achieve convergence", then checks "the second initial guess which converges". That reads as though the third guess failed too, but it converges. It just never runs.
Relation to #575
#575 asked about the exception in this cell. It was closed because the failure is deliberate: the exercise is meant to show that Newton's method can fail, and that should stay. This issue is narrower. The failure on attempt 1 shouldn't hide attempts 2 and 3. Making it "fail more gracefully" was offered as an option in #575.
Suggested change
- Catch the exception for each attempt, so all three run and the failure is still reported. Then drop the
raises-exceptiontag:
for attempt, init in enumerate(initLs, start=1):
print(f"Attempt {attempt}: Starting value is {init} \n")
try:
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)
With the current IPython, %time passes the exception through, so it can stay inside the try if we want to keep the timings.
-
Update the text after the cell to match. The first starting value fails because its first step takes prices negative, and the other two converge to the same equilibrium. The overshoot is also a useful teaching point about why Newton's method can fail.
-
While there: line 1061 writes the tolerance as
$1e-15$, which renders in math mode as "1e − 15". Use$10^{-15}$or plain1e-15in backticks instead.
Timing
#1073 renames the multivariate newton to newton_nd in this cell (the snippet above already uses the new name), so this is easiest to do after #1073 merges.
- Dominant language
- TeX
- Stars
- 129
- Forks
- 61
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 12
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from QuantEcon/lecture-python.myst
-
Link Checker ReportOpenautomated issue linkchecker report
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
QuantEcon/lecture-python.myst#1130 ·
Maintainers usually reply within 1 day
-
phillips_drifts_volatilities: `kalman_forward` pairs each observation with the previous date's volatilityPossibly taken @bennibyx claimed this 7 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
QuantEcon/lecture-python.myst#1108 · 1 comment ·
Maintainers usually reply within 1 day
-
Link Checker ReportOpenautomated issue linkchecker report
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
QuantEcon/lecture-python.myst#1098 ·
Maintainers usually reply within 1 day
-
Link Checker ReportOpenautomated issue linkchecker report
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
QuantEcon/lecture-python.myst#1094 ·
Maintainers usually reply within 1 day
-
Link Checker ReportOpenautomated issue linkchecker report
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
QuantEcon/lecture-python.myst#1062 ·
Maintainers usually reply within 1 day
All issues in QuantEcon/lecture-python.myst
Similar issues
-
5-minutes algorithm all-levels any-language beginner-friendly community documentation easy first-timers-only good first issue hacktoberfest help wanted learning no-code-needed open-source python students
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Huerte/algo-solutions-python#281 ·
Maintainers usually reply within 1 day
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
LinkedEarth/Pyleoclim_util#718 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
daniel-ospina/tortoise#13049 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 76/100
ComposioHQ/awesome-claude-skills#2469 ·
Maintainers usually reply within 15 days
-
Difficulty 1/5 1-3 hours Newbie friendliness 85/100
nf-osi/nf-metadata-dictionary#1062 ·
Maintainers usually reply within 1 day