From a7bd2092a4fb818637d5a5fd26d43cb91fd57f33 Mon Sep 17 00:00:00 2001 From: 123 <629825095@qq.com> Date: Fri, 13 Jun 2025 20:24:37 +0800 Subject: [PATCH] 111 --- 68-1.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/68-1.py b/68-1.py index a451c33..66d1c16 100644 --- a/68-1.py +++ b/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))