Skip to content

BUG: Fix Samuelson quadratic formula - #1066

Merged
mmcky merged 3 commits into
mainfrom
samuelson-quadratic-formula
Sep 26, 2026
Merged

mmcky merged 3 commits into
mainfrom
samuelson-quadratic-formula

Conversation

@blkboxeconomist

@blkboxeconomist blkboxeconomist commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Two small bugs.

One is a typo in the documentation for the class that uses the formulas for the old version of the Samuelson lecture and the second is a typo in finding the roots of the characteristic equation.

First is self-explanatory once you look at it.

For the second

 The three bad lines are the -\ρ1 prefixes:

discriminant = ρ1**2 + 4 * ρ2> if discriminant == 0:
     roots.append(-ρ1 / 2)
elif discriminant > 0:>     roots.append((-ρ1 + sqrt(discriminant).real) / 2)
      roots.append((-ρ1 - sqrt(discriminant).real) / 2)>     ...
else:
     roots.append((-ρ1 + sqrt(discriminant)) / 2)
     roots.append((-ρ1 - sqrt(discriminant)) / 2)

The polynomial in the lecture is z² − ρ₁ z − ρ₂ = 0, so those should be ρ₁ / 2 and (ρ₁ ± √⋅)/2.

The polynomial is z^2 - ρ1 z - ρ2 = 0, so the roots are
(ρ1 ± sqrt(ρ1^2 + 4 ρ2)) / 2. The by-hand formula in
y_nonstochastic used -ρ1 in every branch.
The Samuelson class and analyze_roots use ρ1 = α+β, ρ2 = -β from
I_t = β(Y_{t-1} - Y_{t-2}). The docstring still had the 1939
consumption-accelerator form α(1+β), -αβ.
@github-actions

github-actions Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

📖 Netlify Preview Ready!

Preview URL: https://pr-1066--sunny-cactus-210e3e.netlify.app

Commit: 76e1100

📚 Changed Lectures


Build Info

The non-raw docstring turned \a and \b in \alpha and \beta into
control characters. Also add the sigma epsilon_t term, since the class
supports a stochastic model.

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

jstac commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Thanks very much, Chase, for bringing this to our attention, and for the PR!

Your two fixes look right to us:

  1. Characteristic roots in y_nonstochastic. The lecture's characteristic polynomial is $z^2 - \rho_1 z - \rho_2$, so the roots are $(\rho_1 \pm \sqrt{\rho_1^2 + 4\rho_2})/2$. The by-hand calculation used $-\rho_1$, so every root it printed had the wrong sign. It also disagreed with the np.roots([1, -ρ1, -ρ2]) calls elsewhere in the lecture.
  2. Samuelson class docstring. The recurrence came from an older version of the lecture. It now matches the model in the text.

I've added one small follow-up commit to the docstring:

  • It's now a raw string (r"""). Otherwise Python reads \a and \b in \alpha and \beta as escape characters.
  • The equation now includes the $\sigma \epsilon_t$ term, since the class supports the stochastic case: $Y_t = (\alpha + \beta) Y_{t-1} - \beta Y_{t-2} + (\gamma + G_t) + \sigma \epsilon_t$.

I ran the lecture end to end on the branch. The by-hand roots now agree with np.roots.

@jstac

jstac commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

@mmcky This looks good to me, pls merge when ready.

@mmcky

mmcky commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

thanks @blkboxeconomist and @jstac.

@mmcky
mmcky merged commit 285b3fe into main Sep 26, 2026
2 checks passed
@mmcky
mmcky deleted the samuelson-quadratic-formula branch September 26, 2026 00:23
@mmcky

mmcky commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

✅ Translation sync completed (zh-cn)

Target repo: QuantEcon/lecture-python.zh-cn
Translation PR: QuantEcon/lecture-python.zh-cn#282
Files synced (1):

  • lectures/samuelson.md

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants