Skip to content

[newton_method] Run all three starting values in Exercise 2 solution - #1125

Open
officialasishkumar wants to merge 2 commits into
QuantEcon:mainfrom
officialasishkumar:fix-1115-newton-exercise-2-attempts
Open

officialasishkumar wants to merge 2 commits into
QuantEcon:mainfrom
officialasishkumar:fix-1115-newton-exercise-2-attempts

Conversation

@officialasishkumar

Copy link
Copy Markdown

Fixes #1115

The Exercise 2 solution in newton_method looped over three starting values in a raises-exception cell. The first, $p_0 = (5, 5, 5)$, fails by design (its first Newton step makes prices negative), but the exception ended the loop, so attempts 2 and 3 never ran.

  • Catch the exception for each attempt and print it, so all three run and the failure is still shown; drop the raises-exception tag.
  • Update the text after the cell to explain why the first start fails and that the other two converge to the same equilibrium.
  • Write the tolerance as $10^{-15}$ ($1e-15$ rendered as "1e − 15" in math mode).

I ran the new loop with the lecture's newton and jax_enable_x64: attempt 1 prints "Solution not found with NaN generated"; attempts 2 and 3 converge to (1.4974, 1.4974, 1.4974) in 6 and 8 iterations. %time inside the try passes the exception through as expected.

This is based on current main, which still uses newton; #1073 renames it to newton_nd, so whichever merges second needs that one-word update in this cell.

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 QuantEcon#1115

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The review found no active issues in the updated Newton-method exercise, including its per-attempt exception handling and documented outcomes.

No open issues 🎉

What changed in this PR

Updates the Newton method Exercise 2 solution so every starting value is evaluated while preserving the intentional failure demonstration.

Changes:

  • Catches and prints exceptions per attempt.
  • Uses $10^{-15}$ for the tolerance.
  • Documents the failure and convergence outcomes.
File Description
lectures/​newton_method.md Updates the Exercise 2 code, explanatory text, and tolerance notation.

Review effort: Lite (adaptive)

@mmcky

mmcky commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

@officialasishkumar thanks. This matches #1115 and looks right. I'll resolve the newton → newton_nd conflict from #1073 on your branch. As on #1124, please add an Assisted-by: line to the description and confirm there that you'll answer review yourself.

@mmcky mmcky added the awaiting-response Waiting on the author or reporter to reply label Dec 3, 2026
Resolve the conflict with QuantEcon#1073, which renamed the multivariate
`newton` to `newton_nd`: keep this PR's try/except loop and call
`newton_nd`. Ran locally: attempt 1 reports the NaN failure, and
attempts 2 and 3 converge to (1.4974, 1.4974, 1.4974).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-response Waiting on the author or reporter to reply

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[newton_method] Exercise 2 solution stops after the first starting value

3 participants