Conversation
…e mathematical equation
This commit rectifies the notations and replaces the greek letters (alpha and beta) with (a and b)
|
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 parameterswhich 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, bNow 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! |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
|
📖 Netlify Preview Ready! Preview URL: https://pr-561--sunny-cactus-210e3e.netlify.app (2ea34d3) 📚 Changed Lecture Pages: samuelson |
|
📖 Netlify Preview Ready! Preview URL: https://pr-561--sunny-cactus-210e3e.netlify.app (fac1303) 📚 Changed Lecture Pages: samuelson |
|
📖 Netlify Preview Ready! Preview URL: https://pr-561--sunny-cactus-210e3e.netlify.app (509a5de) 📚 Changed Lecture Pages: samuelson |
|
@HumphreyYang I have:
Do you want to do a final check and then we can merge this. |
|
Hi @bishmaybarik and @mmcky, I have made some big changes to make the code in the lecture cleaner in 5c8f323. Some main changes are:
Please let me know what you think! |
|
📖 Netlify Preview Ready! Preview URL: https://pr-561--sunny-cactus-210e3e.netlify.app (5c8f323) 📚 Changed Lecture Pages: samuelson |
|
📖 Netlify Preview Ready! Preview URL: https://pr-561--sunny-cactus-210e3e.netlify.app (d4ad185) 📚 Changed Lecture Pages: samuelson |
|
📖 Netlify Preview Ready! Preview URL: https://pr-561--sunny-cactus-210e3e.netlify.app (c0e6bc1) 📚 Changed Lecture Pages: samuelson |
|
thanks @HumphreyYang -- these are big changes and lots of reorganisation. @bishmaybarik would you mind to read the updated version and let me know your thoughts on these changes? |
Thanks for making such significant changes @HumphreyYang . Sure @mmcky , I am reviewing it right now and will let you know my thoughts on this as soon as possible. |
These are nice changes @HumphreyYang ! @mmcky I have gone through the entire lecture, and these are some of my quick thoughts:
Additionally, I reviewed the mathematical calculations and verified the results produced by the code. The math appears to be correct, and upon comparing this version with the previous one, I found that the outputs are consistent. P.S. This is a great way to write codes -- I’m learning a lot from @HumphreyYang! |
|
thanks @bishmaybarik for your proof read and review -- it is greatly appreciated. Thanks @HumphreyYang for your updates and review as well. @HumphreyYang let me know when you're happy for this to be merged. |
|
Many thanks @bishmaybarik @HumphreyYang . Very nice work. |
|
thanks @jstac. |
This PR brings the following changes to the lecture:
def param_plot()(1.5371322893124, -0.9024999999999999)### Test the categorize_solution function-- if necessary, those comments should be ordinary markdown above the cells.plt.rcParams["figure.figsize"] = (11, 5) #set default figure sizeAdditional tasks
blackover code-cells for PEP8 / code style compliance (line-length=80)