二次样条插值
# encoding:utf-8 import numpy as np import matplotlib.pyplot as plt # 关键点 x = [2.0, 4.5, 7.0, 9.0, 11.0] y = [1.5, 2.5, 1.5, 0.5, 5.0] def main(): # 检查长度 if len(x) != len(y): print('error! len(x) != len(y)') return # 第一个点到第二个点之间使用直线连接,计算斜率和截距 slope = (y[1] - y[0]) / (x[1] - x[0]) intercept = y[0] - slope * x[0] bivariate_primary_plot(0, slope, intercept, x[0], x[1]) # 第二个点到最后一个点之间使用二次函数拟合 for i in range(1, len(x) - 1): # 2 * x1 * a + b = y1' # x1 * x1 * a + x1 * b + c = y1 # x2 * x2 * a + x2 * b + c = y2 a11 = 2 * x[i] a12 = 1 a13 = 0 b1 = slope a21 = x[i] * x[i] a22 = x[i] a23 = 1 b2 = y[i]