Overview of interpolation in Scilab

In this page, we present an overview of interpolation functions in Scilab

Introduction

The creation of a spline-based interpolation is generally made of two steps :

The creation of the spline may require to compute the coefficients of the spline by solving a system of linear equations. As the matrix is tridiagonal, the cost of this resolution is reduced.

In the following functions, these two steps are provided as two separate functions:

In the following functions, one single function performs both the creation and the evaluation of the spline at given points:

There are other functions which make use of interpolation tools to process datas:

Features:

Most of this module is based on the work by Bruno Pincon.

A 1D spline interpolation

The following example is from the help page of the interp function.

a = -8; b = 8;
x = linspace(a,b,20)';
y = sinc(x);
dk = splin(x,y);  // not_a_knot
df = splin(x,y, "fast");
xx = linspace(a,b,800)';
[yyk, yy1k, yy2k] = interp(xx, x, y, dk); 
[yyf, yy1f, yy2f] = interp(xx, x, y, df); 
clf()
subplot(3,1,1)
plot2d(xx, [yyk yyf])
plot2d(x, y, style=-9)
legends(["not_a_knot spline","fast sub-spline","interpolation points"],...
        [1 2 -9], "ur",%f)
xtitle("spline interpolation")
subplot(3,1,2)
plot2d(xx, [yy1k yy1f])
legends(["not_a_knot spline","fast sub-spline"], [1 2], "ur",%f)
xtitle("spline interpolation (derivatives)")
subplot(3,1,3)
plot2d(xx, [yy2k yy2f])
legends(["not_a_knot spline","fast sub-spline"], [1 2], "lr",%f)
xtitle("spline interpolation (second derivatives)")

The previous script produces the following figure.

interpolation_1D.svg

A 2D spline interpolation

The following example shows how to combine splin2d and interp2d to perform a 2D spline interpolation. It performs the interpolation of the cos(x)cos(y) function.

//
// 1. Create the spline
nx = 7;
ny = 15;
x = linspace(0,2*%pi,nx); 
y = linspace(%pi/2,4*%pi,ny); 
z = cos(x')*cos(y);
C = splin2d(x, y, z, "periodic");
//
// 2. Evaluate the spline on a grid
mx = 50;
my = 20;
xx = linspace(%pi,1.5*%pi,mx);
yy = linspace(%pi,2*%pi,my);
[XX,YY] = ndgrid(xx,yy);
zz = interp2d(XX,YY, x, y, C);
//
// 3. Plot the interpolated values
scf();
plot3d(xx, yy, zz)

The previous script produces the following figure.

Interpolation 2D

Acknowledgments

We thank Bruno Pincon for contributing to this module and to the content of this page.

References

public: Overview of interpolation in Scilab (last edited 2011-12-08 11:18:47 by favignana)