[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Fixing octave-forge spline
From: |
Joe Koski |
Subject: |
Fixing octave-forge spline |
Date: |
Fri, 30 Jan 2004 13:16:27 -0700 |
User-agent: |
Microsoft-Entourage/10.1.4.030702.0 |
A while back I submitted a "bug report" regarding the use of the
octave-forge spline routine. It apparently repeated an already known
problem. For completeness, here is my e-mail sent Dec. 29.
================
In substituting the octave-forge spline.m for the Matlab interp1 routine, I
discovered that, while interp1 apparently returns a fit, csape.m crashes
when presented with three points in the spline fit. Example:
octave:1> x=rand(1:3)
x =
0.45231 0.39556 0.48169
octave:2> y=rand(1:3)
y =
0.73379 0.42766 0.69522
octave:3> pp=spline(x,y)
error: `ldg' undefined near line 169 column 29
error: evaluating argument list element number 1
error: evaluating assignment expression near line 169, column 18
error: evaluating if command near line 59, column 3
error: called from `csape' in file
`/sw/share/octave/2.1.46/site/m/octave-forge/splines/csape.m'
error: evaluating assignment expression near line 33, column 7
error: called from `spline' in file
`/sw/share/octave/2.1.46/site/m/octave-forge/splines/spline.m'
error: evaluating assignment expression near line 3, column 3
octave:3>
When given four points, spline returns a value. For three points, shouldn't
spline/csape return either an error message or a value for pp? Apparently
interp1 does return pp for three points.
Joe Koski
==============
In order to get my data analysis routine to work, I modified spline.m as
follows.
Original spline.m:
=================
## Author: Kai Habel <address@hidden>
## Date: 3. dec 2000
## 2001-02-08 Paul Kienzle
## * copied from csapi.m
function ret = spline (x, y, xi)
ret = csape (x, y, 'not-a-knot');
if (nargin == 3)
ret = ppval (ret, xi);
endif
endfunction
=================
My replacement:
=================
function ret = spline (x, y, xi)
lx=length(x);
if(lx ==3)
ret = csape (x, y, 'variational');
else
ret = csape (x, y, 'not-a-knot');
end
if (nargin == 3)
ret = ppval (ret, xi);
endif
Endfunction
=================
This change got the data analysis routine to work with seemingly reasonable
answers. My assumption (correct or incorrect) was that csape was running out
of spline boundary conditions, and 'not-a-knot' was not a correct choice for
a case with only three data points. I chose 'variational' because it gives a
"natural" spline, one of the two options ("clamped" and "free") given in my
1985 edition of Burden and Faires. I'm most certainly not an expert on
spline routines.
Is this the correct modification? If it is, then csape.m should trap the
three-point 'nat-a-knot' case and replace it with 'variational' (or some
other boundary condition) and a warning message.
Thanks for any input or suggestions.
Joe Koski
-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.org
How to fund new projects: http://www.octave.org/funding.html
Subscription information: http://www.octave.org/archive.html
-------------------------------------------------------------
- Fixing octave-forge spline,
Joe Koski <=