python 三次样条插值拟合车门曲线
背景介绍
数值分析课上要求使用计算机编程实现三次样条插值拟合车门曲线
参考文章
https://blog.csdn.net/qq_34442920/article/details/87692680
特别功能
x= np.array([0,1,2,3,4,5,6,7,8,9,10,13]) 可增加任意多数,
注意y也要增加相应的数。
其中固支使用的是固支边界条件,s‘(x0) = f0’ = f’(x0); s’(xn)=fn’=f’(xn)
代码展示
import numpy as np
import matplotlib.pyplot as plt
from pylab import mpl
mpl.rcParams['font.sans-serif'] = ['SimHei']
x=np.array([0,1,2,3,4,5,6,7,8,9,10,13])#共n+1组数据
y=np.array([2.51,3.30,4.04,4.70,5.22,5.54,5.78,5.40,5.57,5.70,5.8,5.90])
n=len(x)-1 #方便n的后续使用
h=np.zeros(n)
for i in range (0,n):
h[i]=x[i+1]-x[i]
u=np.zeros(n-1)
l=np.zeros(n-1)
for i in range (0,n-1):
u[i]=h[i]/(h[i]+h[i+1])
l[i]=1-u[i]
d=np.zeros(n-1)
for i in range(1,n-2):