# CubicSplineInterpolation


三次样条插值

函数库:TyMath

# 语法

etp =  CubicSplineInterpolation(knots,A;extrapolation_bc=Throw())

# 说明

etp = CubicSplineInterpolation(knots,A;extrapolation_bc=Throw()) 返回对节点 knots 以及节点对应值 A 采用三次样条插值的插值函数,extrapolation_bc 为边界条件,默认为 Throw() 。 示例

# 示例

一维三次样条插值

创建平面坐标系内散点。

using TyMath
using TyBase
using TyPlot
using Interpolations
x = 1:9
y = [19.21 , 18.15 , 15.36 , 18.10 , 16.89 , 11.32 , 7.45 , 5.24 , 7.01]

进行三次样条插值并绘图。

xq = 1:0.01:9
etp = CubicSplineInterpolation(x,y)
hold("on")
plot(xq,etp(xq))
plot(x,y,"o",markeredgecolor = "k",markerfacecolor = "#FFFF00")
title("三次样条插值")
xlabel("xdata")
ylabel("value")
hold("off")
双三次样条插值

构造初始数据点并绘制原始数据图。

using TyMath
using TyBase
using TyPlot
using Interpolations
f_cub(x,y) = 3*(1-x)^2*exp(-(x^2) - (y+1)^2) - 10*(x/5 - x^3 - y^5)*exp(-x^2-y^2) - 1/3*exp(-(x+1)^2 - y^2)
x = -3:1:3
y = -3:1:3
X,Y = ndgrid(x,y)
Z = f_cub.(X,Y)
mesh(X,Y,Z)
hold("on")
plot3(X,Y,Z,"o",markersize = 10,markeredgecolor = "k",markerfacecolor = "r")
grid("on")
hold("off")

对 x 、 y 都使用三次样条插值并绘图。

etp = CubicSplineInterpolation((x,y),Z,extrapolation_bc=Throw())
xt = -3:0.1:3
yt = xt
Xt,Yt = meshgrid2(xt,yt)
surf(Xt,Yt,etp.(Xt,Yt))

获取 (x,y) = (1.2,2.3) 处的插值结果。

etp(1.2,2.3)
ans = 1.1861370547105412

# 输入参数

knots - 插值节点

原始数据点的网格向量 (自变量)。

数据类型: Int | Float

A - 函数值

网格节点对应函数值 (因变量)。

数据类型: Int | Float

复数支持: 是

extrapolation_bc - 外插边界条件
Throw() (默认) | Flat() | Line() | Reflect() | Periodic()

外插的边界条件,默认为 Throw()。

  • Throw():只对原数据范围内数据进行插值
  • Flat():外插部分设置斜率为 0
  • Linear():采用恒定斜率进行外插
  • Reflect():反射边界条件
  • Periodic():周期性边界条件

# 输出参数

etp - 插值函数

根据原有数据进行插值后得到的插值函数,输入自变量可得到对应插值结果

示例: etp[1]

数据类型: Struct

# 另请参阅

CubicSplineInterpolation | LinearInterpolation