python - Solving System of Differential Equations using SciPy -
i'm trying solve following system of differential equations using scipy:
q1''(t) + m/l1 * q2''(t) + r1/l1 * q1'(t) + 1/(c1 * l1) * q1(t) = 0 q2''(t) + m/l2 * q1''(t) + r2/l2 * q2'(t) + 1/(c2 * l2) * q2(t) = 0
i'm trying use scipy.integrate.odeint obtain numerical solution. substitution:
y[0] = q1 y[1] = q1' y[2] = q1'' y[3] = q2 y[4] = q2' y[5] = q2''
i used following code solution.
def deriv(y, t): return np.array([ y[1], (-ml1 * y[5] - r1l1 * y[1] - y[0] / c1l1), ?? y[4], (-ml2 * y[2] - r2l2 * y[4] - y[3] / c2l2), ?? ]) def main(): t = np.arange(0.0, 500.0, 0.01) initial_cond = [ 1.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] sol = integrate.odeint(deriv, initial_cond, t) print(sol)
my question put derivatives of q1''(t) , q2''(t). there different substitution can use instead?
you have 2 coupled second order equations. when system converted system of first order equations, there 4 equations, not six.
do little algebra hand solve vector [q1''(t), q2''(t)] in terms of q1(t), q1'(t), q2(t) , q2'(t). (for example, can use fact inverse of matrix [[1, m/l1], [m/l1, 1]] [[1, -m/l1], [-m/l1, 1]]/(1-(m/l1)**2), if m/l1 not 1.) define state vector y [q1(t), q1'(t), q2(t), q2'(t)]. vector need return deriv
is
y[0]'(t) = q1'(t) = y[1] y[1]'(t) = q1''(t) = (expression found using algebra, q1(t), q1'(t), q2(t) , q2'(t) replaced y[0], y[1], y[2], y[3], resp.) y[2]'(t) = q2'(t) = y[3] y[3]'(t) = q2''(t) = (expression found using algebra, q1(t), q1'(t), q2(t) , q2'(t) replaced y[0], y[1], y[2], y[3], resp.)
Comments
Post a Comment