简体   繁体   中英

Solving System of Differential Equations using SciPy

I'm trying to solve the 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 to use scipy.integrate.odeint to obtain a numerical solution. With the substitution:

Y[0] = q1
Y[1] = q1'
Y[2] = q1''
Y[3] = q2
Y[4] = q2'
Y[5] = q2''

I used the following code to get the 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 is what do I put for the derivatives of q1''(t) and q2''(t). Is there a different substitution I can use instead?

You have two coupled second order equations. When this system is converted to a system of first order equations, there will be four equations, not six.

Do a little algebra by hand to solve for the vector [q1''(t), q2''(t)] in terms of q1(t), q1'(t), q2(t) and q2'(t). (For example, you can use that fact the inverse of the matrix [[1, M/L1], [M/L1, 1]] is [[1, -M/L1], [-M/L1, 1]]/(1-(M/L1)**2), if M/L1 is not 1.) Define your state vector Y to be [q1(t), q1'(t), q2(t), q2'(t)]. Then the vector that you need to return from deriv is

Y[0]'(t) = q1'(t)  = Y[1]
Y[1]'(t) = q1''(t) = (expression you found using algebra, with q1(t), q1'(t), q2(t) and q2'(t) replaced with Y[0], Y[1], Y[2], Y[3], resp.)
Y[2]'(t) = q2'(t)  = Y[3]
Y[3]'(t) = q2''(t) = (expression you found using algebra, with q1(t), q1'(t), q2(t) and q2'(t) replaced with Y[0], Y[1], Y[2], Y[3], resp.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM