![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/7d378883e2d510c65bb4541960280c40.png)
代码实现
from matplotlib import pyplot as plt
def y(x, y):
y = 1.1 * y - (0.2 * x) / y
return float("%.2f" % y)
def collection(x0, y0, h):
x1 = x0 + h
yp = y0 + h * y(x0, y0)
yc = y0 + h * y(x1, yp)
y1 = (1 / 2) * (yc + yp)
return float("%.2f" % x1), float("%.2f" % y1)
def xy_list(x, y):
x_list.append(x)
y_list.append(y)
def draw(x_list, y_list):
plt.figure(figsize=(10, 10), dpi=100)
plt.scatter(x_list, y_list)
plt.show()
if __name__ == '__main__':
x_list = []
y_list = []
result = collection(0, 1, h=0.1)
print('x1:', result[0], 'y1:', result[1])
xy_list(result[0], result[1])
for i in range(100):
result = collection(result[0], result[1], 0.1)
xy_list(result[0], result[1])
print('x{}:'.format(i + 2), result[0], 'y{}:'.format(i + 2), result[1])
draw(x_list, y_list)
运行截图
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/190686b20176266257e934bb4afbf662.png)