From 3a41897ba2ce28bcc4071e71cd2892c6c3a5d7f5 Mon Sep 17 00:00:00 2001 From: 123 <629825095@qq.com> Date: Sat, 14 Jun 2025 13:35:33 +0800 Subject: [PATCH] 111 --- 279-3.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/279-3.py b/279-3.py index 9c81095..f3b5fa6 100644 --- a/279-3.py +++ b/279-3.py @@ -12,15 +12,15 @@ def ClassicRK(x0,y0,h,xk,fxy): result.append((x0,y0)) return result - +#把下面参数换成题干的################# if __name__=="__main__": - x0 = 0 - y0 = -1 - fxy = lambda x,y: x + y - real_fx = lambda x: -x-1 - h = 0.1 - xk = 2 + x0 = 0 #x的左边界换成题干里面的################# + y0 = -1 #y的初始值换成题干里面的################# + fxy = lambda x,y: x + y #f(x,y)换成题干里面的################# + real_fx = lambda x: -x-1 #真实函数换成题干里面的################# + h = 0.1 #步长换成题干里面的################# + xk = 2 #x的右边界换成题干里面的################# result = ClassicRK(x0, y0, h, xk, fxy) - print("x\ty\t\treal_y") + print("x\ty\t\treal_y\t\t\t误差") for x, y in result: - print(f"{x:.2f}\t{y}\t{real_fx(x)}") \ No newline at end of file + print(f"{x:.2f}\t{y:.10f}\t\t{real_fx(x):.10f}\t\t\t{abs(y - real_fx(x)):.5f}") \ No newline at end of file