Splines
Splines
BSplineKit.Splines.Spline
— TypeSpline{T} <: Function
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.173575, 0.321662, 0.258585, 0.166439, 0.527015, 0.483022, 0.390663, 0.802763, 0.721983, 0.372347, 0.0301856, 0.0793339, 0.663758]
Spline{T = Float64}(undef, B::AbstractBSplineBasis)
Construct a spline with uninitialised vector of coefficients.
(S::Spline)(x)
Evaluate spline at coordinate x
.
BSplineKit.Splines.coefficients
— Functioncoefficients(S::Spline)
Get B-spline coefficients of the spline.
Base.eltype
— Methodeltype(::Type{<:Spline})
eltype(S::Spline)
Returns type of element returned when evaluating the Spline
.
Base.length
— Methodlength(S::Spline)
Returns the number of coefficients in the spline.
Note that this is equal to the number of basis functions, length(basis(S))
.
BSplineKit.BSplines.basis
— Methodbasis(S::Spline) -> AbstractBSplineBasis
Returns the associated B-spline basis.
BSplineKit.Splines.PeriodicVector
— TypePeriodicVector{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.
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.173575, 0.321662, 0.258585, 0.166439, 0.527015, 0.483022, 0.390663, 0.802763, 0.721983, 0.372347, 0.0301856, 0.0793339, 0.663758]
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.22131, -0.473071, -0.460734, 1.80288, -0.219964, -0.461794, 2.0605, -0.403899, -1.74818, -1.71081, 0.368613, 8.76636]
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: [-26.9438, 0.0616849, 11.3181, -10.1142, -1.20915, 12.6114, -12.322, -6.72141, 0.186876, 10.3971, 83.9775]
Base.diff
— Functiondiff(S::Spline, [op::Derivative = Derivative(1)]) -> Spline
Same as op * S
.
Returns N
-th derivative of spline S
as a new spline.
BSplineKit.Splines.integral
— Functionintegral(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)
.
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
).
Spline wrappers
BSplineKit.Splines.SplineWrapper
— TypeSplineWrapper{S <: Spline} <: Function
Abstract type representing a type that wraps a Spline
.
Such a type implements all common operations on splines, including evaluation, differentiation, etc…
BSplineKit.Splines.spline
— Functionspline(w::SplineWrapper) -> Spline
Returns the Spline
wrapped by the object.