Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Python Help in logic for amplitude vs frequency

  1. Mar 29, 2016 #1

    ChrisVer

    User Avatar
    Gold Member

    I am trying to solve the problem 4.8 found http://phys.csuchico.edu/ayars/312/Handouts/comp-phys-python.pdf [Broken] at pdf's page 115-6 [book's page 107-8].

    My code so far is:
    Code (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: May 7, 2017
  2. jcsd
  3. Mar 29, 2016 #2

    BvU

    User Avatar
    Science Advisor
    Homework Helper
    Gold Member

    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
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted



Similar Discussions: Help in logic for amplitude vs frequency
Loading...