This commit is contained in:
lwj
2025-06-14 13:35:33 +08:00
parent 7cb8285891
commit 3a41897ba2

View File

@@ -12,15 +12,15 @@ def ClassicRK(x0,y0,h,xk,fxy):
result.append((x0,y0)) result.append((x0,y0))
return result return result
#把下面参数换成题干的#################
if __name__=="__main__": if __name__=="__main__":
x0 = 0 x0 = 0 #x的左边界换成题干里面的#################
y0 = -1 y0 = -1 #y的初始值换成题干里面的#################
fxy = lambda x,y: x + y fxy = lambda x,y: x + y #f(x,y)换成题干里面的#################
real_fx = lambda x: -x-1 real_fx = lambda x: -x-1 #真实函数换成题干里面的#################
h = 0.1 h = 0.1 #步长换成题干里面的#################
xk = 2 xk = 2 #x的右边界换成题干里面的#################
result = ClassicRK(x0, y0, h, xk, fxy) 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: for x, y in result:
print(f"{x:.2f}\t{y}\t{real_fx(x)}") print(f"{x:.2f}\t{y:.10f}\t\t{real_fx(x):.10f}\t\t\t{abs(y - real_fx(x)):.5f}")