[Scilab-users] Cubic spline

Rafael Guerra jrafaelbguerra at hotmail.com
Sun Sep 11 18:48:28 CEST 2016


Hi,

The code line using interp1 and the spline method seems to perform "not_a_knot" cubic spline interpolation, as demonstrated by the simple test here below:


x0 = [0 1 2 3 4];

y0 = [0 -1 0 2 1];

x = 0:0.05:4;

y1 = interp1(x0,y0,x,'spline');

d = splin(x0, y0,"not_a_knot");

e = splin(x0, y0,"natural");

y2 = interp(x, x0, y0, d);

y3 = interp(x, x0, y0, e);

clf();

plot(x,y1,'blue',x,y2,'--green',x,y3,'red',x0,y0,'Xblack')


What do you mean by your result is “OK, but it's not perfect, compared to a Fortran script”?
Could you provide a snapshot?

Regards,
Rafae;

From: Claus Futtrup
Sent: Friday, September 09, 2016 8:34 PM
To: International users mailing list for Scilab. <users at lists.scilab.org>
Subject: [Scilab-users] Cubic spline

Hi there

In Scilab I've used interp1 to calculate a cubic spline interpolation, like this:

a(:,1) = interp1(log(f3),a1,log(f),'spline');

a = amplitude (magnitude). f3 is a frequency (27000 linear spaced data), a1 is the original data, f is the resampled 1200 frequencies (log-spaced), where I need the spline to interpolate some data for me.

Above should work OK, but it's not perfect, compared to a Fortran script. The fortran script calculates with its own cubic spline routine, utilizing LAPACK (DGTTRF and DGTTRS) to solve for polynomial coefficients.

The question is - above code line with the interp1 spline, which kind of spline is it?

Digging into interp, I see multiple options. Digging into splin, I also see multiple options.

I looks like the interp1 is using "natural" spline - is this correct?

It's strange because the splin help documentation doesn't recommend this. It says: Don't use the natural type unless the underlying function have zero second end points derivatives.

This might be my problem.

The Scilab help for interp1 doesn't give any examples, but does mention I can add an "extrap" method. Could this be any of the suggestions in the splin documentation. For example, could I write:

a(:,1) = interp1(log(f3),a1,log(f),'spline','not-a-knot');

?

P.S. Since not-a-knot is mentioned as the default for the splin function, I think it should also be made the default for interp1 ... just my two cents.

/Claus
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20160911/7cbba00f/attachment.htm>


More information about the users mailing list