Skip to content

[samuelson] Fixing the lecture #561

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

[samuelson] Fixing the lecture #561

wants to merge 8 commits into from

Conversation

bishmaybarik
Copy link
Member

@bishmaybarik bishmaybarik commented Aug 18, 2025

This PR brings the following changes to the lecture:

  • Fixes [samuelson] Incorrect mathematical equation #530 : I have rectified the error in the mathematical equation
  • Fixes [samuelson] Inconsistent usage of ($a$, $b$) and ($\alpha$, $\beta$) #456 : I have updated the lectures to use $a$ and $b$ throughout; and this is consistent with the explanation on text as well
  • Fixes [samuelson] Does not follow Quantecon style guidelines #531 : Making some more changes to follow John's suggestions
    • large code cells with lots of plotting code are typically hidden now -- see, e.g., def param_plot()
    • we might want to truncate the number of decimal points in output such as (1.5371322893124, -0.9024999999999999)
    • we shouldn't have comments in cells, such as ### Test the categorize_solution function -- if necessary, those comments should be ordinary markdown above the cells.
    • I don't think we should have plt.rcParams["figure.figsize"] = (11, 5) #set default figure size
    • the align syntax after "Notice that" and in other places seems nonstandard

This commit rectifies the notations and replaces the greek letters (alpha and beta) with (a and b)
Copy link

github-actions bot commented Aug 18, 2025

@github-actions github-actions bot temporarily deployed to pull request August 18, 2025 15:16 Inactive
@github-actions github-actions bot temporarily deployed to pull request August 18, 2025 15:17 Inactive
@github-actions github-actions bot temporarily deployed to pull request August 20, 2025 06:08 Inactive
@github-actions github-actions bot temporarily deployed to pull request August 20, 2025 06:08 Inactive
@mmcky mmcky added lecture and removed content labels Aug 21, 2025
@bishmaybarik
Copy link
Member Author

I am not sure if I should completely delete the following three lines of code:

### code to reverse-engineer a cycle
### y_t = r^t (c_1 cos(ϕ t) + c2 sin(ϕ t))
###

from this entire code chunk (it can be found here):

### code to reverse-engineer a cycle
### y_t = r^t (c_1 cos(ϕ t) + c2 sin(ϕ t))
###

def f(r, ϕ):
    """
    Takes modulus r and angle ϕ of complex number r exp(j ϕ)
    and creates ρ1 and ρ2 of characteristic polynomial for which
    r exp(j ϕ) and r exp(- j ϕ) are complex roots.

    Returns the multiplier coefficient a and the accelerator coefficient b
    that verifies those roots.
    """
    g1 = cmath.rect(r, ϕ)  # Generate two complex roots
    g2 = cmath.rect(r, -ϕ)
    ρ1 = g1 + g2           # Implied ρ1, ρ2
    ρ2 = -g1 * g2
    b = -ρ2                # Reverse-engineer a and b that validate these
    a = ρ1 - b
    return ρ1, ρ2, a, b

## Now let's use the function in an example
## Here are the example parameters

r = .95
period = 10                # Length of cycle in units of time
ϕ = 2 * math.pi/period

## Apply the function

ρ1, ρ2, a, b = f(r, ϕ)

print(f"a, b = {a}, {b}")
print(f"ρ1, ρ2 = {ρ1}, {ρ2}")

Also, there are comments inside the code cell, like:

## Now let's use the function in an example
## Here are the example parameters

which I think might be a little confusing if people miss out reading each line of the code.


I plan to rewrite the entire thing like this:

def f(r, ϕ):
    """
    Takes modulus r and angle ϕ of complex number r exp(j ϕ)
    and creates ρ1 and ρ2 of characteristic polynomial for which
    r exp(j ϕ) and r exp(- j ϕ) are complex roots.

    Returns the multiplier coefficient a and the accelerator coefficient b
    that verifies those roots.
    """
    g1 = cmath.rect(r, ϕ)  # Generate two complex roots
    g2 = cmath.rect(r, -ϕ)
    ρ1 = g1 + g2           # Implied ρ1, ρ2
    ρ2 = -g1 * g2
    b = -ρ2                # Reverse-engineer a and b that validate these
    a = ρ1 - b
    return ρ1, ρ2, a, b

Now let's use the function in an example. Here are the example parameters:

r = .95
period = 10                # Length of cycle in units of time
ϕ = 2 * math.pi/period

## Apply the function
ρ1, ρ2, a, b = f(r, ϕ)

print(f"a, b = {a}, {b}")
print(f"ρ1, ρ2 = {ρ1}, {ρ2}")

Please let me know your thoughts on this @HumphreyYang and @mmcky. Once you give your inputs, I can make the changes accordingly.

@HumphreyYang
Copy link
Member

I am not sure if I should completely delete the following three lines of code:

### code to reverse-engineer a cycle
### y_t = r^t (c_1 cos(ϕ t) + c2 sin(ϕ t))
###

from this entire code chunk (it can be found here):

### code to reverse-engineer a cycle
### y_t = r^t (c_1 cos(ϕ t) + c2 sin(ϕ t))
###

def f(r, ϕ):
    """
    Takes modulus r and angle ϕ of complex number r exp(j ϕ)
    and creates ρ1 and ρ2 of characteristic polynomial for which
    r exp(j ϕ) and r exp(- j ϕ) are complex roots.

    Returns the multiplier coefficient a and the accelerator coefficient b
    that verifies those roots.
    """
    g1 = cmath.rect(r, ϕ)  # Generate two complex roots
    g2 = cmath.rect(r, -ϕ)
    ρ1 = g1 + g2           # Implied ρ1, ρ2
    ρ2 = -g1 * g2
    b = -ρ2                # Reverse-engineer a and b that validate these
    a = ρ1 - b
    return ρ1, ρ2, a, b

## Now let's use the function in an example
## Here are the example parameters

r = .95
period = 10                # Length of cycle in units of time
ϕ = 2 * math.pi/period

## Apply the function

ρ1, ρ2, a, b = f(r, ϕ)

print(f"a, b = {a}, {b}")
print(f"ρ1, ρ2 = {ρ1}, {ρ2}")

Also, there are comments inside the code cell, like:

## Now let's use the function in an example
## Here are the example parameters

which I think might be a little confusing if people miss out reading each line of the code.

I plan to rewrite the entire thing like this:

def f(r, ϕ):
    """
    Takes modulus r and angle ϕ of complex number r exp(j ϕ)
    and creates ρ1 and ρ2 of characteristic polynomial for which
    r exp(j ϕ) and r exp(- j ϕ) are complex roots.

    Returns the multiplier coefficient a and the accelerator coefficient b
    that verifies those roots.
    """
    g1 = cmath.rect(r, ϕ)  # Generate two complex roots
    g2 = cmath.rect(r, -ϕ)
    ρ1 = g1 + g2           # Implied ρ1, ρ2
    ρ2 = -g1 * g2
    b = -ρ2                # Reverse-engineer a and b that validate these
    a = ρ1 - b
    return ρ1, ρ2, a, b

Now let's use the function in an example. Here are the example parameters:

r = .95
period = 10                # Length of cycle in units of time
ϕ = 2 * math.pi/period

## Apply the function
ρ1, ρ2, a, b = f(r, ϕ)

print(f"a, b = {a}, {b}")
print(f"ρ1, ρ2 = {ρ1}, {ρ2}")

Please let me know your thoughts on this @HumphreyYang and @mmcky. Once you give your inputs, I can make the changes accordingly.

Looks great to me! Thanks so much!

@github-actions github-actions bot temporarily deployed to pull request August 21, 2025 06:05 Inactive
@github-actions github-actions bot temporarily deployed to pull request August 21, 2025 06:22 Inactive
@github-actions github-actions bot temporarily deployed to pull request August 21, 2025 09:34 Inactive
@github-actions github-actions bot temporarily deployed to pull request August 21, 2025 09:35 Inactive
@bishmaybarik bishmaybarik marked this pull request as ready for review August 23, 2025 10:42
@github-actions github-actions bot temporarily deployed to pull request August 23, 2025 11:01 Inactive
@HumphreyYang HumphreyYang requested a review from Copilot August 23, 2025 16:19
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants