I want to pass an array input signal to ordinary differential equations solver 'odeint' instead of defining a function. Much like the linear solver lsim :
tout, yout, xout = lsim(sys, U=input_sig(time), T=time)
Which is much more convenient than defining a input function as it allows to generate various input signal and operate on them (windowing or whatever)
In the following is a modified example from the odeint scipy documentation where i define input_sig as a function of t
import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import odeint
def input_sig(t):
return np.sin(2 * np.pi * 50 * t)
def pend(y, t, b, c):
theta, omega = y
dydt = [omega, -b*omega -c*np.sin(theta) -input_sig(t)]
return dydt
b = 0.25
c = 5.0
y0 = [0, 0.0]
t = np.linspace(0, 10, 101)
sol = odeint(pend, y0, t, args=(b, c))
# what i would like to do is
# sol = odeint(pend, y0, t, input_sig(t), args=(b, c))
# where input_sig(t) is an array
plt.plot(t, sol, label=['theta(t)','omega(t)'])
plt.legend(loc='best')
plt.xlabel('t')
plt.grid()
plt.show()
Any ideas ? i don't mind using other solvers than odeint, i don't know if it's possible... Thank You!