参考资料来源:
(1)https://idesolver.readthedocs.io/en/latest/quickstart.html
(2)https://idesolver.readthedocs.io/en/latest/manual.html
一、IDESolver包模块安装
为应用IDESolver包计算积分-微分方程的解,需要在python环境安装IDESolver包模块,安装命令为(pip install idesolver)。
二、待求解的积分-微分方程
假设需要求解以下积分-微分方程(IDE)
三、编写python代码求解IDE
利用IDESolver函数计算其数值解,首先建立IDESolver样本,并将关于待求解的IDE的相关信息传递给该样本进行刻画,样本的格式如下所示
对比该样本与待计算的IDE可以得到以下表达式子
编写代码如下
from idesolver import IDESolver
import matplotlib.pyplot as plt
import numpy as np
from idesolver import IDESolver
solver = IDESolver(
x = np.linspace(0, 2, 100),
y_0 = 0,
c = lambda x, y: y - (.5 * x**2) + (10 / (5 - x)) - np.log(1 + x**2),
d = lambda x: 1 / 4,
k = lambda x, s: x / (1 + s),
f = lambda y: y,
lower_bound = lambda x: 0,
upper_bound = lambda x: 2,
)
solver.solve()
solver.x
solver.y
绘图显示计算的结果
fig = plt.figure()
ax = fig.add_subplot()
plt.rcParams['font.sans-serif'] = ['SimHei']
ax.plot(solver.x, solver.y, label = 'IDESolver 数值解曲线', linestyle = '-', linewidth = 3)
ax.set_title(f'求解过程整体容忍误差 = {solver.global_error_tolerance}')
ax.set_xlabel(r'$x$')
ax.set_ylabel(r'$y(x)$')
plt.show()