# encoding: utf-8 from sympy import * x=Symbol("x") n=int(input("输入要计算的拉格朗日差值是几阶:")) X=[] Y=[] for i in range(0,n+1): X.append(int(input("输入x的各值:"))) for i in range(0,n+1): Y.append(int(input("输入y的各值:"))) print(X,Y) L=0.0 for i in range(0,n+1): fz=1.0 fm=1.0 for j in range(0,n+1): if(i==j): continue fz=fz*(x-X[j]) fm=fm*(X[i]-X[j]) l=fz/fm*Y[i] L=L+l L=L.subs(x,float(input("输入x的值:"))) print(L)
python简单实现拉格朗日差值计算
最新推荐文章于 2023-02-08 12:34:51 发布