Python 2nd order ODE solution with quad function

I am studying the dynamics of a damped, controlled pendulum with a second-order ODE defined as so , and in particular I will program:

d ^ 2y / dt ^ 2 + c * dy / dt + sin (y) = a * cos (wt)

import numpy as np
import matplotlib.pyplot as plt
from scipy import integrate


def pendeq(t,y,a,c,w):
    y0 = -c*y[1] - np.sin(y[0]) + a*np.cos(w*t)
    y1 = y[1]
    z = np.array([y0, y1])
    return z

a = 2.1
c = 1e-4
w = 0.666667     # driving angular frequency

t = np.array([0, 5000])   # interval of integration
y = np.array([0, 0])      # initial conditions

yp = integrate.quad(pendeq, t[0], t[1], args=(y,a,c,w))

This problem really looks like I need help solving a second-order nonlinear ODE in python , but I get an error

Supplied function does not return a valid float.

What am I doing wrong?

+4
source share
1 answer

integrate.quadrequires that the provided function ( pendeq, in your case) returns only a float . Your function returns an array.

+3

All Articles