Plot BSpline and derivatives


In [1]:
import BSpline
reload("BSpline")


Warning: replacing module BSpline

Plot spline functions


In [2]:
import PyPlot


INFO: Loading help data...

In [3]:
M = 4
bs = BSpline.BSplineT(M,1.,6.,6)
num_basis = BSpline.num_basis(bs);

In [4]:
X = [-2:0.01:9]
psiX = zeros(length(X), num_basis)
BSpline.bspline_basismatrix!(psiX, bs, X)
PyPlot.plot(X, psiX);


Plot Derivatives


In [5]:
X = [-2:0.01:9]
BSpline.derivative_bspline_basismatrix!(psiX, bs, X)
PyPlot.plot(X, psiX);



In [6]:
using DualNumbers

In [7]:
dualDeriv = zeros(length(X))
for j=0:num_basis-1
for i=1:length(X)
    x = dual(X[i], 1)
    y = BSpline.bspline_basis(j, bs, x)
    dualDeriv[i] = epsilon(y)
end
    @show maximum(abs(dualDeriv-psiX[:,j+1]))
end


maximum(abs(dualDeriv - psiX[:,j + 1])) => 2.7755575615628914e-16
maximum(abs(dualDeriv - psiX[:,j + 1])) => 3.3306690738754696e-16
maximum(abs(dualDeriv - psiX[:,j + 1])) => 2.220446049250313e-16
maximum(abs(dualDeriv - psiX[:,j + 1])) => 3.3306690738754696e-16
maximum(abs(dualDeriv - psiX[:,j + 1])) => 2.7755575615628914e-16
maximum(abs(dualDeriv - psiX[:,j + 1])) => 2.220446049250313e-16
maximum(abs(dualDeriv - psiX[:,j + 1])) => 3.3306690738754696e-16
maximum(abs(dualDeriv - psiX[:,j + 1])) => 2.220446049250313e-16

In [8]:
X = [-2:0.01:9]
BSpline.derivative2_bspline_basismatrix!(psiX, bs, X)
PyPlot.plot(X, psiX);



In [9]:
dualDeriv = zeros(length(X))
for j=0:num_basis-1
for i=1:length(X)
    x = dual(X[i], 1)
    y = BSpline.derivative_bspline_basis(j, bs, x)
    dualDeriv[i] = epsilon(y)
end
    @show maximum(abs(dualDeriv-psiX[:,j+1]))
end


maximum(abs(dualDeriv - psiX[:,j + 1])) => 4.440892098500626e-16
maximum(abs(dualDeriv - psiX[:,j + 1])) => 2.220446049250313e-16
maximum(abs(dualDeriv - psiX[:,j + 1])) => 4.440892098500626e-16
maximum(abs(dualDeriv - psiX[:,j + 1])) => 4.440892098500626e-16
maximum(abs(dualDeriv - psiX[:,j + 1])) => 4.440892098500626e-16
maximum(abs(dualDeriv - psiX[:,j + 1])) => 2.220446049250313e-16
maximum(abs(dualDeriv - psiX[:,j + 1])) => 2.220446049250313e-16
maximum(abs(dualDeriv - psiX[:,j + 1])) => 2.220446049250313e-16

In [ ]: