Я пишу программу для решения дифференциального уравнения в форме x '' (t) + w ^ 2 (t) * x (t) = 0, поэтому я использовал odeint. Однако всякий раз, когда он не начинается с 0, он ставит первую точку относительно того, что 0 должно было быть
sin (t) при запуске с t = -1
sin (t), начиная с t = 0
, на рисунках четко видны проблемы
import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import odeint
def omega(t):
return 1
def dU_dt(U, t):
return [U[1], -U[0] * ((omega(t)) ** 2)]
x0 = 0 # This is the initial condition x(0)
x1 = 1 # This is the initial condition x'(0)
U0 = [x0, x1]
pi = np.pi
start = -1
stop = 2 * pi
N = 10 ** 2
xs = np.linspace(start, stop, N)
Us, info = odeint(dU_dt, U0, xs, rtol=1e-10, full_output=True)
ys = Us[:, 0]
plt.xlabel('t')
plt.ylabel('x')
plt.axvline(x=0.0, color=(0, 0, 0))
plt.axhline(y=0.0, color=(0, 0, 0))
plt.plot(xs, ys)
for i in range(len(xs)):
print(xs[i], ys[i])
plt.show()