0% found this document useful (0 votes)
23 views5 pages

Classical Assignment

The document contains Python code for simulating and plotting the behavior of a damped harmonic oscillator under three conditions: underdamped, critically damped, and overdamped. It utilizes numpy for calculations and matplotlib for visualizations, showing how displacement changes over time for each damping scenario. Each damping case is plotted separately with appropriate labels and legends.

Uploaded by

muhammadishaq127
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views5 pages

Classical Assignment

The document contains Python code for simulating and plotting the behavior of a damped harmonic oscillator under three conditions: underdamped, critically damped, and overdamped. It utilizes numpy for calculations and matplotlib for visualizations, showing how displacement changes over time for each damping scenario. Each damping case is plotted separately with appropriate labels and legends.

Uploaded by

muhammadishaq127
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Heading (#Heading)

Sub-Heading (## Sub-Heading)


Submitted by (### Submitted by)
Submitted to (### Submitted to)
import numpy as np
import [Link] as plt

# Variables
omega_o = 2
A = 1
B = 0
t = [Link](0, 10, 500)
# For symbols, Win+R-- charmap-- enter-- search symbol-- copy
# Underdamped (γ < ω0)
gamma_under = 0.5
omega_under = [Link](omega_o**2 - gamma_under**2)
x_under = [Link](-gamma_under * t) * (A * [Link](omega_under * t) + B
* [Link](omega_under * t))

# Critically damped (γ = ω0)


gamma_crit = omega_o
x_crit = (A + B * t) * [Link](-gamma_crit * t)

# Overdamped (γ > ω0)


gamma_over = 4
B1, B2 = -gamma_over + [Link](gamma_over**2 - omega_o**2), -
gamma_over - [Link](gamma_over**2 - omega_o**2)
x_over = A * [Link](B1 * t) + B * [Link](B2 * t)

# Plotting
[Link](figsize=(8, 5))
[Link](t, x_under, label="Underdamped", linestyle='-',
color='purple') #r here tells that slash is for symbol.
[Link](t, x_crit, label="Critically Damped", linestyle='--',
color='g')
[Link](t, x_over, label="Overdamped", linestyle='-.', color='r')

[Link]("Time (t)")
[Link]("Displacement (x)")
[Link]("Damped Harmonic Oscillator")
[Link]()
[Link]()
[Link]()
import numpy as np
import [Link] as plt

# Variables
omega_o = 2
A = 1
B = 0
t = [Link](0, 10, 500)

gamma_under = 0.5
omega_under = [Link](omega_o**2 - gamma_under**2)
x_under = [Link](-gamma_under * t) * (A * [Link](omega_under * t) + B
* [Link](omega_under * t))

[Link](t, x_under, label=r"Underdamped", linestyle='-',


color='purple')
[Link]("Time (t)")
[Link]("Displacement (x)")
[Link]("Underdamped Harmonic Oscillator")
[Link]()
[Link]()
[Link]()
import numpy as np
import [Link] as plt

# Variables
omega_o = 2
A = 1
B = 0
t = [Link](0, 10, 500)

gamma_crit = omega_o = 2
x_crit = (A + B * t) * [Link](-gamma_crit * t)

[Link](t, x_crit, label=r"Critically Damped", linestyle='-',


color='g')
[Link]("Time (t)")
[Link]("Displacement (x)")
[Link]("Underdamped Harmonic Oscillator")
[Link]()
[Link]()
[Link]()
import numpy as np
import [Link] as plt

# Variables
omega_o = 2
A = 1
B = 0
t = [Link](0, 10, 500)

gamma_over = 3
B1, B2 = -gamma_over + [Link](gamma_over**2 - omega_o**2), -
gamma_over - [Link](gamma_over**2 - omega_o**2)
x_over = A * [Link](B1 * t) + B * [Link](B2 * t)

[Link](t, x_over, label=r"Overdamped", linestyle='-', color='r')


[Link]("Time (t)")
[Link]("Displacement (x)")
[Link]("Underdamped Harmonic Oscillator")
[Link]()
[Link]()
[Link]()

You might also like