Help in logic for amplitude vs frequency

Click For Summary
SUMMARY

The discussion focuses on solving problem 4.8 from a physics resource, specifically addressing the challenge of plotting amplitude versus frequency (omega) in a damped driven harmonic oscillator scenario. The user has implemented a numerical solution using the Runge-Kutta method via the 'rungekuta4' function from the 'mytools' module, with parameters such as mass (MASS), spring constant (K), and damping coefficient (MU) defined. The primary issue identified is the inability to vary the frequency (omega) in the existing code to generate the desired plot.

PREREQUISITES
  • Understanding of differential equations and their numerical solutions
  • Familiarity with Python programming and libraries such as NumPy and Matplotlib
  • Knowledge of harmonic oscillators and concepts of amplitude and frequency
  • Experience with the Runge-Kutta method for solving ordinary differential equations
NEXT STEPS
  • Modify the existing code to incorporate a loop that varies the omega parameter and collects amplitude data
  • Research the mathematical formulation of the damped driven harmonic oscillator to understand its behavior
  • Learn how to use Matplotlib to create multiple plots on the same graph for amplitude vs. frequency
  • Explore optimization techniques for improving the performance of the Runge-Kutta implementation
USEFUL FOR

Physics students, computational physicists, and software developers working on simulations of dynamic systems will benefit from this discussion.

ChrisVer
Science Advisor
Messages
3,372
Reaction score
465
I am trying to solve the problem 4.8 found http://phys.csuchico.edu/ayars/312/Handouts/comp-phys-python.pdf at pdf's page 115-6 [book's page 107-8].

My code so far is:
Python:
from mytools import rungekuta4
from pylab import *

#set globals
G=9.81
MASS=1.0
K=42.0
MU=0.15
A=1.
OMEGA=0.01

#set diff solver variables
N=1000
tau=5.
dt= tau/float(N-1)
t=linspace(0,tau,N)

def Fexternal(A,w,t):
    return A*cos(w*t)

def springmass(xv_vector,time):
    # x' =v
    # v' = -k/m x +/- mu g + F[t]
    diff0= xv_vector[1]
    if diff0>0:
        diff1= -(K/MASS)*xv_vector[0] - MU*G +  F(A,OMEGA,time) / MASS
    else:
        diff1= -(K/MASS)*xv_vector[0] + MU*G + F(A,OMEGA,time) / MASS

    return array([diff0,diff1])

xo=1.0
vo=0.0

y=zeros([N,2])
y[0,0]=xo
y[0,1]=vo

for i in range(N-1):
     y[i+1]= rungekuta4(y[i],t[i],dt,springmass)

plot(t,y[:,0],'r-')
show()

My problem is that I cannot see how I can make the w a variable... So that I could plot the amplitude vs the omega...
 
Last edited by a moderator:
Technology news on Phys.org
Yes, it's a bit weird they ask this in a chapter where most of the material is about integrating differential equations. I think here you really need the expressions for the damped driven harmonic oscillator
 

Similar threads

Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
5K
  • · Replies 16 ·
Replies
16
Views
3K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 6 ·
Replies
6
Views
3K