1 | initial version |
I've had difficulty getting Sage to handle Python functions, like your sqstim
, in differential equations. Sage wants to execute sqstim(t) immediately when it is called in the desolve_odeint command.
Here is an option using numpy and scipy.
import numpy as np
from scipy.integrate import odeint
def eqns(y,t):
V=y[0]
w=y[1]
dydt = [1/100.*(-w+(V^3-V)+sqstim(t)), V-0.2*w]
return(dydt)
tspan=np.linspace(0,100,1000)
sol = odeint(eqns, [0.1,0.1], tspan)
tV = zip(tspan,[s[0] for s in sol])
tw = zip(tspan,[s[1] for s in sol])
Then, you can plot easily using Sage commands.
line(tV,color='red')
and
line(tw)