Splines

Splines

BSplineKit.Splines.SplineType
Spline{T}

Represents a spline function.


Spline(B::AbstractBSplineBasis, coefs::AbstractVector)

Construct a spline from a B-spline basis and a vector of B-spline coefficients.

Examples

julia> B = BSplineBasis(BSplineOrder(4), -1:0.2:1);

julia> coefs = rand(length(B));

julia> S = Spline(B, coefs)
13-element Spline{Float64}:
 basis: 13-element BSplineBasis of order 4, domain [-1.0, 1.0]
 order: 4
 knots: [-1.0, -1.0, -1.0, -1.0, -0.8, -0.6, -0.4, -0.2, 0.0, 0.2, 0.4, 0.6, 0.8, 1.0, 1.0, 1.0, 1.0]
 coefficients: [0.815921, 0.076499, 0.433472, 0.672844, 0.468371, 0.348423, 0.868621, 0.0831675, 0.369734, 0.401199, 0.990734, 0.565907, 0.984855]

Spline{T = Float64}(undef, B::AbstractBSplineBasis)

Construct a spline with uninitialised vector of coefficients.


(S::Spline)(x)

Evaluate spline at coordinate x.

source
Base.eltypeMethod
eltype(::Type{<:Spline})
eltype(S::Spline)

Returns type of element returned when evaluating the Spline.

source
Base.lengthMethod
length(S::Spline)

Returns the number of coefficients in the spline.

Note that this is equal to the number of basis functions, length(basis(S)).

source
BSplineKit.Splines.PeriodicVectorType
PeriodicVector{T} <: AbstractVector{T}

Describes a periodic (or "circular") vector wrapping a regular vector.

Used to store the coefficients of periodic splines.

The vector has an effective length N associated to a single period, but it is possible to index it outside of this "main" interval.

This is similar to BSplines.PeriodicKnots. It is simpler though, since here there is no notion of coordinates or of a period L. Periodicity is only manifest in the indexation of the vector, e.g. a PeriodicVector vs satisfies vs[i + N] == vs[i].


PeriodicVector(cs::AbstractVector)

Wraps coefficient vector cs such that it can be indexed in a periodic manner.

source

Derivatives and integrals

Base.:*Function
*(op::Derivative, S::Spline) -> Spline

Returns N-th derivative of spline S as a new spline.

See also diff.

Examples

julia> B = BSplineBasis(BSplineOrder(4), -1:0.2:1);

julia> S = Spline(B, rand(length(B)))
13-element Spline{Float64}:
 basis: 13-element BSplineBasis of order 4, domain [-1.0, 1.0]
 order: 4
 knots: [-1.0, -1.0, -1.0, -1.0, -0.8, -0.6, -0.4, -0.2, 0.0, 0.2, 0.4, 0.6, 0.8, 1.0, 1.0, 1.0, 1.0]
 coefficients: [0.461501, 0.619799, 0.654451, 0.667213, 0.334672, 0.618022, 0.967496, 0.900014, 0.611195, 0.469467, 0.221618, 0.80084, 0.269533]

julia> Derivative(0) * S === S
true

julia> Derivative(1) * S
12-element Spline{Float64}:
 basis: 12-element BSplineBasis of order 3, domain [-1.0, 1.0]
 order: 3
 knots: [-1.0, -1.0, -1.0, -0.8, -0.6, -0.4, -0.2, 0.0, 0.2, 0.4, 0.6, 0.8, 1.0, 1.0, 1.0]
 coefficients: [2.37448, 0.259885, 0.0638088, -1.6627, 1.41675, 1.74737, -0.33741, -1.44409, -0.708643, -1.23925, 4.34416, -7.9696]

julia> Derivative(2) * S
11-element Spline{Float64}:
 basis: 11-element BSplineBasis of order 2, domain [-1.0, 1.0]
 order: 2
 knots: [-1.0, -1.0, -0.8, -0.6, -0.4, -0.2, 0.0, 0.2, 0.4, 0.6, 0.8, 1.0, 1.0]
 coefficients: [-21.146, -0.98038, -8.63255, 15.3972, 1.65313, -10.4239, -5.53341, 3.67724, -2.65301, 27.917, -123.138]
source
Base.diffFunction
diff(S::Spline, [op::Derivative = Derivative(1)]) -> Spline

Same as op * S.

Returns N-th derivative of spline S as a new spline.

source
BSplineKit.Splines.integralFunction
integral(S::Spline)

Returns an antiderivative of the given spline as a new spline.

The algorithm is described in de Boor 2001, p. 127.

Note that the integral spline I returned by this function is defined up to a constant. By convention, here the returned spline I is zero at the left boundary of the domain. One usually cares about the integral of S from point a to point b, which can be obtained as I(b) - I(a).

Periodic splines

Note that the integral of a periodic function is in general not periodic. For periodic splines (backed by a PeriodicBSplineBasis), this function returns a non-periodic spline (backed by a regular BSplineBasis).

source

Spline wrappers

BSplineKit.Splines.SplineWrapperType
SplineWrapper{S <: Spline}

Abstract type representing a type that wraps a Spline.

Such a type implements all common operations on splines, including evaluation, differentiation, etc…

source