Код: Выделить всё
import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt
# function that returns dy/dt
def model(y,t):
k = 0.3
dydt = -k * y
return dydt
# initial condition
y0 = 5
# time points
t = np.linspace(0,20)
# solve ODE
y = odeint(model,y0,t)
# plot results
plt.plot(t,y)
plt.xlabel('time')
plt.ylabel('y(t)')
plt.show()

Что делать, если мне не нужно строить график, мне нужно только числовое решение для x = 3.
У меня есть этот код интерполяции, но решение неточно по сравнению с Sympy:
Код: Выделить всё
print(" At time 3, my result will be " ,np.interp(3, x, y))
Подробнее здесь: https://stackoverflow.com/questions/786 ... ion-to-ode