我想用初始条件求解这个微分方程:y??+2y?+2y=cos(2x):
y(1)=2,y?(2)=0.5
y?(1)=1,y?(2)=0.8
y(1)=0,y(2)=1
它的代码是:
import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt
def dU_dx(U, x):
return [U[1], -2*U[1] - 2*U[0] + np.cos(2*x)]
U0 = [1,0]
xs = np.linspace(0, 10, 200)
Us = odeint(dU_dx, U0, xs)
ys = Us[:,0]
plt.xlabel("x")
plt.ylabel("y")
plt.title("Damped harmonic oscillator")
plt.plot(xs,ys);
Run Code Online (Sandbox Code Playgroud)
我怎样才能实现它?