# 结果展示函数
def ShowAns(l,u,c,M):
print('*****************l**********')
print(l)
print('*****************u**********')
print(u)
print('*****************c**********')
print(c)
print('*****************M**********')
print(M)
pass
# 然后建立样条分段函数
# 并绘制图像
# 求出 M,再添加自然边界条件(前后加 0)
fake_M = Chasing(u3,Diag,ld,d,False)
M = np.zeros(fake_M.size+2)
M[1:M.size-1] = fake_M
# print(M)
# 建立三次样条插值函数(分段)
def MSpline3(data_x,data_y,M,h,x):
assert x >= 0, "the x value is undefind(wrong)"
# 以免输入错误的数据
index = x//2 + 1
# 对应 x 的 value 和矩阵中次序的关系
# 限制下标的范围(在边界最后一个值会有一个溢出,控制一下)
index = int(index)
if index==27: index=26
# 根据 M 值建立三次样条插值的方程(带入方程表达式)
V1 = pow(data_x[index]-x,3)*M[index-1]/12
V2 = pow(x-data_x[index-1],3)*M[index]/12
V3 = (data_y[index-1]-4*M[index-1]/6)*(data_x[index]-x)/2
V4 = (data_y[index]-4*M[index]/6)*(x-data_x[index-1])/2
return V1+V2+V3+V4
# 绘制三次样条插值后的图像
x_plot = np.linspace(0,52,5000)
y_plot = np.array([MSpline3(x,y,M,h,t) for t in x_plot])
LineLens = 0
# Part2 求曲线长度,使用第一型线积分的策略
# 对曲线长度进行分段求和
for i in range(len(x_plot)-1):
temp= np.square(x_plot[i+1]-x_plot[i])+np.square(y_plot[i+1]-y_plot[i])