x' = f(x,y,t)
y' = g(x,y,t)给出了x0和y0与t0的初始条件。在t0到a的范围内找到解决方案图。
我尝试过对非耦合方程这样做,但似乎也有一个问题。我必须准确地使用这个函数来解决这个问题,所以其他函数不是选项。
from numpy import *
from matplotlib import pyplot as plt
def f(t,x):
return -x
import scipy
from scipy import integrate as inte
solution = inte.RK45(f, 0 , [1] , 10 ,1, 0.001, e**-6)
print (solution)我希望输出是所有值的数组。
但我得到的是<scipy.integrate._ivp.rk.RK45 at 0x1988ba806d8>。
发布于 2019-05-30 10:28:54
您需要使用调用step()函数收集数据:
from math import e
from scipy import integrate as inte
def f(t,x):
return -x
solution = inte.RK45(f, 0 , [1] , 10 ,1, 0.001, e**-6)
# collect data
t_values = []
y_values = []
for i in range(100):
# get solution step state
solution.step()
t_values.append(solution.t)
y_values.append(solution.y[0])
# break loop after modeling is finished
if solution.status == 'finished':
break
data = zip(t_values, y_values)输出:
(0.12831714796342164, 0.879574381033538)
(1.1283171479634215, 0.3239765636806864)
(2.1283171479634215, 0.11933136762238628)
(3.1283171479634215, 0.043953720407578944)
(4.128317147963422, 0.01618962035012491)
(5.128317147963422, 0.005963176828962677)
(6.128317147963422, 0.002196436798667919)
(7.128317147963422, 0.0008090208875093502)
(8.128317147963422, 0.00029798936023261037)
(9.128317147963422, 0.0001097594143523445)
(10, 4.5927433621121034e-05)https://stackoverflow.com/questions/56376061
复制相似问题