111
This commit is contained in:
18
279-3.py
18
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)}")
|
||||
print(f"{x:.2f}\t{y:.10f}\t\t{real_fx(x):.10f}\t\t\t{abs(y - real_fx(x)):.5f}")
|
||||
Reference in New Issue
Block a user