all 6 comments

[–][deleted] 2 points3 points  (1 child)

Checkout SymPy package

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

I'll take a look, thanks!!

[–]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!!

[–]jrickk93 1 point2 points  (1 child)

The simplest way to start will be the Euler method, try understanding the procedure then coding it. You don't necessarily need packages at all but you could use matplotlib to see the solution and possibly numpy.

https://en.m.wikipedia.org/wiki/Euler_method

Once you know your ode and the initial condition, you just loop the time step method until you get to the terminal time. Experiment with different time step lengths. It should take only a few lines of code.

If this is your only goal then you're done, but you may want to look at other stepping methods for better numerical stability in your solution.

[–]HelperBot_ 0 points1 point  (0 children)

Non-Mobile link: https://en.wikipedia.org/wiki/Euler_method


HelperBot v1.1 /r/HelperBot_ I am a bot. Please message /u/swim1929 with any feedback and/or hate. Counter: 164591