111
This commit is contained in:
13
68-1.py
13
68-1.py
@@ -1,17 +1,15 @@
|
||||
|
||||
import math
|
||||
|
||||
list_x = [10,11,12,13]
|
||||
list_y = [2.3026,2.3979,2.4849,2.5649]
|
||||
|
||||
# 定义原函数和其导函数计算结果
|
||||
def FxDiff_n(x,n):
|
||||
result = 0
|
||||
if n == 0:
|
||||
# 下面改成原函数 ####################3########################################
|
||||
result = math.log(x)
|
||||
else:
|
||||
# 下面改成n阶导数 ##############################################################################
|
||||
result = (-1)**(n+1) * math.factorial(n-1) / (x**n)
|
||||
|
||||
return result
|
||||
|
||||
# 获取与待求x最接近的两个点
|
||||
@@ -71,8 +69,11 @@ def LagrangeInterpolation(x,list_x,list_y):
|
||||
result += temp * list_y[i]
|
||||
return result
|
||||
|
||||
|
||||
list_x = [10,11,12,13] #改成题干的数值#############################
|
||||
list_y = [2.3026,2.3979,2.4849,2.5649] #改成题干的数值#############################
|
||||
if __name__ == "__main__":
|
||||
print("线性插值 ln11.75 结果为%f, 截断误差%f" % LinearInterpolation(11.75,list_x,list_y))
|
||||
print("抛物线插值 ln11.75 结果为%f, 截断误差%f" % ParabolaInterpolation(11.75,list_x,list_y))
|
||||
print("线性插值 ln11.75 结果为%f, 截断误差%f" % LinearInterpolation(11.75,list_x,list_y)) #改成题干的数值#############################
|
||||
print("抛物线插值 ln11.75 结果为%f, 截断误差%f" % ParabolaInterpolation(11.75,list_x,list_y)) #改成题干的数值#############################
|
||||
|
||||
# print(LagrangeInterpolation(11.75,list_x,list_y))
|
||||
|
||||
Reference in New Issue
Block a user