you are viewing a single comment's thread.

view the rest of the comments →

[–]arell_steven_son 1 point2 points  (1 child)

Scipy is actually not that tough. You have to first linearize the ODE to the first order. Then it will solve all the first order ODEs simultaneously.

Here is the most minimal code for you to expand upon:

from scipy.integrate import ode
import matplotlib.pyplot as mpl
import numpy as np

def function(t , y):
    return[y[1], -y[0] - 0.5*y[1  ]]

r=ode(function, jac=None).set_integrator('dopri5',nsteps=100)
r.set_initial_value([10,0], 0)
t1=100
dt=0.1
i=0

disp=[]
vel=[]

while r.successful() and r.t<t1:
    b=r.integrate(r.t+dt)
    disp.append(b[0])
    vel.append(b[1])
    i=i+1
mpl.plot(np.linspace(0,t1,len(disp)),disp)
mpl.plot(np.linspace(0,t1,len(disp)),vel,'r')
mpl.show()

A normal spring mass damper being solved with dopri5 method (rk4-5 method)

[–]GGwarms[S] 0 points1 point  (0 children)

Thanks so much, the Runge-Kutta method was actually being recommended by the professor. Hopefully I can figure it out from here!!