Interpolation by 2dimensional bicubic splines
This functionality does not run in MATLAB.
numeric::cubicSpline2d([x_{0}, x_{1}, …, x_{n}]
, [y_{0}, y_{1}, …, y_{m}]
, z
, <[xBC, yBC]
>, <Symbolic>)
numeric::cubicSpline2d([ x_{0},
x_{1}, ...], [ y_{0}, y_{1},
...], z)
returns the bicubic spline function interpolating
data z_{i, j} over
a rectangular mesh (x_{i}, y_{j}).
The call S := numeric::cubicSpline2d([x_{0},
…, x_{n}], [y_{0},
…, y_{n}], z, Option)
yields
the cubic spline function S interpolating
the data (x_{i}, y_{j}, z_{i, j}),
i.e, S(x_{i}, y_{j})
= z_{i, j} for i =
0, …, n, j =
0, …, m. The spline
function is a piecewise bicubic polynomial: on the ‘patch'
,
it has the representation
with suitable coefficients a_{i, j}^{(u, v)} depending
on the patch. The spline S and
its partial derivatives S_{x}, S_{y}, S_{xx}, S_{xy}, S_{yy}, S_{xxy}, S_{xyy}, S_{xxyy} are
continous functions over the entire x, y plane.
In the xdirection, S
extends
the polynomial representation on the boundary patches
and
to
and
,
respectively. The same holds with respect to the ydirection.
By default, NotAKnot
boundary conditions
are assumed, i.e., the partial derivatives S_{xxx}, S_{yyy}, …, S_{xxxyyy},
are continuous at the points with xcoordinates x_{1} and x_{n 
1} or ycoordinates y_{1} and y_{m 
1}.
By default, all input data are converted to floatingpoint numbers.
This conversion may be suppressed by the option Symbolic
.
Without the option Symbolic
, the abscissae x_{i}, y_{j} must
be numerical real values in ascending order. If these data are not
ordered, then numeric::cubicSpline2d
reorders the
abscissae internally, issuing a warning.
The function S
returned by numeric::cubicSpline2d
may
be called with two, three, four, or five arguments, respectively:
The call S(x, y)
returns an arithmetical
expression if x and y are
numerical expressions. A float is returned if either x or y is
a float and all parameters involved can be converted to floats.
If either x or y contains
symbolic objects, the symbolic call S(x, y)
is
returned.
The call S(x, y, [u, v])
with nonnegative
integers u
, v
returns the partial
derivative
of
the spline. If either x or y contain
symbolic objects, the symbolic call S(x, y, [u, v])
is
returned. The result is 0 if
either u > 3 or v >
3. The calls S(x, y, [0, 0])
and S(x,
y)
are equivalent.
The call S(x, y, i, j)
with nonnegative
integers i
, j
returns the polynomial
representation of the spline on the patch p_{i, j}.
Here, x and y may
be arbitrary numerical or symbolic arithmetical expressions. Internally, (x, y) are
assumed to lie in the patch p_{i, j}.
The call S(x, y, i, j, [u, v])
with
nonnegative integers i
, j
, u
, v
returns
the polynomial representation of the partial derivatives of the spline
function. In this call, x and y may
be arbitrary numerical or symbolic arithmetical expressions which
are assumed to lie in the patch p_{i, j}.
The result is 0 if either u >
3 or v >
3. The calls S(x, y, i, j, [0, 0])
and S(x,
y, i, j)
are equivalent.
If S
is generated with symbolic abscissae x_{i}, y_{j} (necessarily
using the option Symbolic
), the call S(x,
y, [ u , v ])
is returned symbolically. The call S(x,
y, i, j, [ u , v ])
must be used for symbolic abscissae!
We demonstrate some calls with numerical input data. The function f(x, y) = sin(2 π (x + y)) with 0 ≤ x ≤ 1, 0 ≤ y ≤ 1 is to be interpolated by n + 1 = 11 equidistant points in the xdirection and m + 1 = 13 equidistant points in the ydirection:
f := (x, y) > sin((x + y)*2*PI): n := 10: x := [i/n $ i = 0..n]: m := 12: y := [j/m $ j = 0..m]: z := array(0..n, 0..m, [[f(i/n, j/m) $ j = 0..m] $ i = 0..n]): S1 := numeric::cubicSpline2d(x, y, z, [NotAKnot, NotAKnot]): S2 := numeric::cubicSpline2d(x, y, z, [Natural, Natural]): S3 := numeric::cubicSpline2d(x, y, z, [NotAKnot, Periodic]):
We consider Complete
boundary conditions
in the ydirection.
They consist of the values f_{y}(x_{i}, y_{0})
= f_{y}(x_{i},
0) = 2 π cos(2 π x_{i}) and f_{y}(x_{i}, y_{m})
= f_{y}(x_{i},
1) = 2 π cos(2 π x_{i}):
ybc:= [[2*PI*cos(2*PI*i/n) $ i = 0..n], [2*PI*cos(2*PI*i/n) $ i = 0..n]]: S4 := numeric::cubicSpline2d(x, y, z, [Periodic, Complete = ybc]):
At the mesh points (x_{i}, y_{j}), the input data z_{i, j} are reproduced:
x := 4/n: y := 8/m: float(f(x, y)), S1(x, y), S2(x, y), S3(x, y), S4(x, y)
Interpolation between the mesh points depends on the boundary condition:
x := 0.92: y:= 0.55: S1(x, y), S2(x, y), S3(x, y), S4(x, y)
The approximation of the function value f(0.92,
0.55) is good for the NotAKnot
, Periodic
,
and Complete
boundary conditions. The Natural
boundary
conditions are less appropriate because the second partial derivatives
of the function f do
not vanish at the boundaries. Consequently, the approximation error
of S2
is larger than the other approximation errors:
z := float(f(x, y)): S1(x, y)  z, S2(x, y)  z, S3(x, y)  z, S4(x, y)  z
This is the bicubic polynomial in X
, Y
defining
the spline S1
on the patch
,
:
expand(S1(X, Y, 0, 3))
delete f, n, m, ybc, x, y, z, S1, S2, S3, S4:
We demonstrate some calls with symbolic data. With the option Symbolic
,
exact arithmetic is used:
S := numeric::cubicSpline2d( [i $ i = 0..3], [j $ j = 0..4], array(0..3, 0..4, [[z.i.j $ j = 0..4] $ i = 0..3]), Symbolic ):
S(1/2, 3/2)
This is the bicubic polynomial in X, Y defining the spline with x_{0} = 0 ≤ X ≤ x_{1} = 1, y_{1} = 1 ≤ Y ≤ y_{2} = 2:
expand(S(X, Y, 0, 1))
delete S:
We consider a spline interpolation of the function with  1 ≤ x ≤ 1,  1 ≤ y ≤ 1:
n := 10: xmesh := [1 + 2*i/n $ i = 0..n]: m := 12: ymesh := [1 + 2*j/n $ j = 0..m]: f := (x, y) > exp(x^2  y^2): z := array(0..n, 0..m, [[f(1 + 2*i/n, 1 + 2*j/m) $ j=0..m] $ i = 0..n]): S := numeric::cubicSpline2d(xmesh, ymesh, z):
We plot the spline function S(x, y):
plotfunc3d(S(x, y), x = 1 .. 1, y = 1 .. 1):
We plot the partial derivative S_{xxxyyy}(x, y). It is constant on each patch with jumps at the boundaries of the patches. The renderer uses [5 n + 1, 5 m + 1] mesh points: in each direction, 4 extra points between adjacent mesh points of the spline are used for the graphical representation:
plotfunc3d(S(x, y, [3, 3])/10, x = 1 .. 1, y = 1 .. 1, Mesh = [5*n + 1, 5*m+ 1])
delete n, xmesh, m, ymesh, f, z, S:
We demonstrate the spline interpretation of a surface. We consider a sphere parametrized by spherical coordinates u, v with 0 ≤ u ≤ 2 π, 0 ≤ v ≤ π:
.
We interpolate the functions x, y, z over
a rectangular mesh in the uvplane.
Since x, y and
(trivally) z are 2 πperiodic
in u,
we choose Periodic
boundary conditions for u.
For v,
we choose Complete
boundary conditions with boundary
values of the first partial vderivative
fitting the parametrization:
x:= (u, v) > cos(u)*sin(v): x_v := diff(x(u, v), v): y:= (u, v) > sin(u)*sin(v): y_v := diff(y(u, v), v): z:= (u, v) > cos(v): z_v := diff(z(u, v), v): n := 4: umesh := [i*2*PI/n $ i = 0..n]: m := 4: vmesh := [j*PI/m $ j = 0..m]: vBC := Complete = [ [subs(x_v, u = umesh[i], v = vmesh[1]) $ i = 1 .. n+1], [subs(x_v, u = umesh[i], v = vmesh[n + 1]) $ i = 1 .. n+1]]: X := numeric::cubicSpline2d(umesh, vmesh, array(0..n, 0..m, [[x(i*2*PI/n, j*PI/m) $ j=0..m] $ i=0..n]), [Periodic, vBC]): vBC := Complete = [ [subs(y_v, u = umesh[i], v = vmesh[1]) $ i = 1 .. n+1], [subs(y_v, u = umesh[i], v = vmesh[n + 1]) $ i = 1 .. n+1]]: Y := numeric::cubicSpline2d(umesh, vmesh, array(0..n, 0..m, [[y(i*2*PI/n, j*PI/m) $ j=0..m] $ i=0..n]), [Periodic, vBC]): vBC := Complete = [ [subs(z_v, u = umesh[i], v = vmesh[1]) $ i = 1 .. n+1], [subs(z_v, u = umesh[i], v = vmesh[n + 1]) $ i = 1 .. n+1]]: Z := numeric::cubicSpline2d(umesh, vmesh, array(0..n, 0..m, [[z(i*2*PI/n, j*PI/m) $ j=0..m] $ i=0..n]), [Periodic, vBC]):
With only (n + 1)×(m + 1) = 5×5 mesh points, the spline surface yields a respectable approximation of a sphere. The interpolation nodes are added to the plot as blue points:
plot( plot::Surface([X(u, v), Y(u, v), Z(u, v)], u = 0..2*PI, v = 0..PI, Mesh = [5*n + 1, 5*m + 1], Color = RGB::Red), plot::Point3d(x(umesh[i], vmesh[j]), y(umesh[i], vmesh[j]), z(umesh[i], vmesh[j]), PointSize = 2*unit::mm, Color = RGB::Blue ) $ i = 1..n+1 $ j = 1..m+1 ):
delete x, x_v, y, y_v, z, z_v, n, m, umesh, vmesh, vBC, X, Y, Z:

The xcoordinates of the nodes: distinct numerical real values in ascending order 

The ycoordinates of the nodes: distinct numerical real values in ascending order 

The function values: an array of the form 

The type of the boundary condition: the boundary condition in
the x
or ydirection
may be one of the flags
In the ydirection,
these value may be passed in the form 

With this option, no conversion of the input data to floating point numbers occurs. Symbolic abscissae x_{i}, y_{j} are accepted. The ordering x_{0} < x_{1} < … < x_{n}, y_{0} < y_{1} < … < y_{m} is assumed. This ordering is not checked even if the node coordinates are numerical! 

With the default boundary condition This boundary condition is recommended if no information on the behaviour of the data near the mesh boundaries is available. 

The boundary condition This boundary condition is recommended if it is known that the data correspond to a surface with vanishing curvature near the mesh boundaries. 

The boundary condition
Or , Respectively. With this option, the input data z_{0, j}, z_{n, j}, respectively z_{i, 0}, z_{i, m}, must coincide. Otherwise, an error is raised. This boundary condition is recommended if the interpolation is to represent a periodic function. 

Option, specified as The The Symbolic data a_{k}, b_{k} are accepted. This boundary condition is recommended if the data z_{i, j} correpond to a function with known values of the first partial derivatives at the mesh boundaries. 
Spline function: a MuPAD^{®} procedure.