Skip to content Skip to sidebar Skip to footer

Trying To Solve 2 First Order Differential Equations, Python

I am trying to solve these 2 equations bellow and I am having no luck, if anyone can point out where i am going wrong that would be great thanks! def f(t,alpha): return t*t/(2*

Solution 1:

Try using scipy. Look this example:

from scipy.integrate import odeint
from pylab import * # for plotting commandsdefderiv(y,t, alpha): # return derivatives of the array y #edit: put an extra arg#use the arg whatever you want
    a = -2.0
    b = -0.1return array([ y[1], a*y[0]+b*y[1] ])

time = linspace(0.0,10.0,1000)
yinit = array([0.0005,0.2]) # initial values
alpha = 123#declare the extra(s) agrg
y = odeint(deriv,yinit,time,args=(alpha, )) #pass the extras args as tuple
figure()

plot(time,y[:,0]) # y[:,0] is the first column of y
xlabel('t')
ylabel('y')
show()

Result: enter image description here

Font: http://bulldog2.redlands.edu/facultyfolder/deweerd/tutorials/Tutorial-ODEs.pdf

An interesting link: http://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.integrate.ode.html

Post a Comment for "Trying To Solve 2 First Order Differential Equations, Python"