r756 - in packages: . libmath-spline-perl libmath-spline-perl/branches libmath-spline-perl/branches/upstream libmath-spline-perl/branches/upstream/current

Carlo Segre segre-guest@costa.debian.org
Mon, 14 Mar 2005 07:00:18 +0100


Author: segre-guest
Date: 2005-03-14 07:00:17 +0100 (Mon, 14 Mar 2005)
New Revision: 756

Added:
   packages/libmath-spline-perl/
   packages/libmath-spline-perl/branches/
   packages/libmath-spline-perl/branches/upstream/
   packages/libmath-spline-perl/branches/upstream/current/
   packages/libmath-spline-perl/branches/upstream/current/MANIFEST
   packages/libmath-spline-perl/branches/upstream/current/Makefile.PL
   packages/libmath-spline-perl/branches/upstream/current/README
   packages/libmath-spline-perl/branches/upstream/current/Release
   packages/libmath-spline-perl/branches/upstream/current/Spline.pm
   packages/libmath-spline-perl/tags/
Log:
[svn-inject] Installing original source of libmath-spline-perl

Added: packages/libmath-spline-perl/branches/upstream/current/MANIFEST
===================================================================
--- packages/libmath-spline-perl/branches/upstream/current/MANIFEST	2005-03-14 05:55:08 UTC (rev 755)
+++ packages/libmath-spline-perl/branches/upstream/current/MANIFEST	2005-03-14 06:00:17 UTC (rev 756)
@@ -0,0 +1,5 @@
+MANIFEST
+README
+Release
+Makefile.PL
+Spline.pm
\ No newline at end of file

Added: packages/libmath-spline-perl/branches/upstream/current/Makefile.PL
===================================================================
--- packages/libmath-spline-perl/branches/upstream/current/Makefile.PL	2005-03-14 05:55:08 UTC (rev 755)
+++ packages/libmath-spline-perl/branches/upstream/current/Makefile.PL	2005-03-14 06:00:17 UTC (rev 756)
@@ -0,0 +1,12 @@
+use ExtUtils::MakeMaker;
+use Config;
+
+$Version = '0.01';
+
+WriteMakefile(
+               'NAME'     => 'Math::Spline',
+               'LINKTYPE' => '$(INST_PM)',
+               'VERSION'  => $Version,
+               'dist'     => { SUFFIX => 'gz', COMPRESS => 'gzip -f' },
+               'clean' 	  => {'FILES' => '*~'},
+);

Added: packages/libmath-spline-perl/branches/upstream/current/README
===================================================================
--- packages/libmath-spline-perl/branches/upstream/current/README	2005-03-14 05:55:08 UTC (rev 755)
+++ packages/libmath-spline-perl/branches/upstream/current/README	2005-03-14 06:00:17 UTC (rev 756)
@@ -0,0 +1,17 @@
+Perl Module Math::Spline - 0.01
+
+     Copyright (c) 1995 John A.R. Williams. All rights reserved.
+     This program is free software; you can redistribute it and/or
+     modify it under the same terms as Perl itself.
+
+To install, unzip and untar the archive. In the directory created type
+
+perl Makefile.pl
+make install
+
+Documentation is in the module file and will be added onto
+perllocal.pod as usual.
+
+The perl package Math::Derivative is required by this module.
+
+I can be contacted at <Email: J.A.R.Williams@aston.ac.uk>
\ No newline at end of file

Added: packages/libmath-spline-perl/branches/upstream/current/Release
===================================================================
--- packages/libmath-spline-perl/branches/upstream/current/Release	2005-03-14 05:55:08 UTC (rev 755)
+++ packages/libmath-spline-perl/branches/upstream/current/Release	2005-03-14 06:00:17 UTC (rev 756)
@@ -0,0 +1,20 @@
+Announcing the release of Perl Module Math::Spline Version 0.01
+Uploaded to CPAN archives under my home directory.
+
+Math::Spline  - Cubic Spline Interpolation of data
+
+This package provides cubic spline interpolation of numeric data. The
+data is passed as references to two arrays containing the x and y
+ordinates. It may be used as an exporter of the the numerical
+functions or, more easily as a class module.
+
+Module Entry
+
+6) Data Types and Data Type Utilities (see also Database Interfaces)
+
+Name           DSLI  Description                                  Info
+-----------    ----  -------------------------------------------- -----
+Math::
+::Spline       RdpO  Cubic Spline Interpolation of data           JARW
+
+  JARW John A.R. Williams <J.A.R.Williams@aston.ac.uk>

Added: packages/libmath-spline-perl/branches/upstream/current/Spline.pm
===================================================================
--- packages/libmath-spline-perl/branches/upstream/current/Spline.pm	2005-03-14 05:55:08 UTC (rev 755)
+++ packages/libmath-spline-perl/branches/upstream/current/Spline.pm	2005-03-14 06:00:17 UTC (rev 756)
@@ -0,0 +1,139 @@
+# $Id: Spline.pm,v 1.1 1995/12/26 17:28:17 willijar Exp $
+=head1 NAME
+
+    Math::Spline  - Cubic Spline Interpolation of data
+
+=head1 SYNOPSIS
+    
+    require Math::Spline;
+    $spline=new Math::Spline(\@x,\@y)
+    $y_interp=$spline->evaluate($x);
+
+    use Math::Spline qw(spline linsearch binsearch);
+    use Math::Derivative qw(Derivative2);
+    @y2=Derivative2(\@x,\@y);
+    $index=binsearch(\@x,$x);
+    $index=linsearch(\@x,$x,$index);
+    $y_interp=spline(\@x,\@y,\@y2,$index,$x);
+
+=head1 DESCRIPTION
+
+This package provides cubic spline interpolation of numeric data. The
+data is passed as references to two arrays containing the x and y
+ordinates. It may be used as an exporter of the numerical functions
+or, more easily as a class module.
+
+The B<Math::Spline> class constructor B<new> takes references to the
+arrays of x and y ordinates of the data. An interpolation is performed
+using the B<evaluate> method, which, when given an x ordinate returns
+the interpolate y ordinate at that value.
+
+The B<spline> function takes as arguments references to the x and y
+ordinate array, a reference to the 2nd derivatives (calculated using
+B<Derivative2>, the low index of the interval in which to interpolate
+and the x ordinate in that interval. Returned is the interpolated y
+ordinate. Two functions are provided to look up the appropriate index
+in the array of x data. For random calls B<binsearch> can be used -
+give a reference to the x ordinates and the x loopup value it returns
+the low index of the interval in the data in which the value
+lies. Where the lookups are strictly in ascending sequence (e.g. if
+interpolating to produce a higher resolution data set to draw a curve)
+the B<linsearch> function may more efficiently be used. It performs
+like B<binsearch>, but requires a third argument being the previous
+index value, which is incremented if necessary.
+
+=head1 NOTE
+
+requires Math::Derivative module
+
+=head1 EXAMPLE
+
+    require Math::Spline;
+    my @x=(1,3,8,10);
+    my @y=(1,2,3,4);						    
+    $spline=new Math::Spline(\@x,\@y);
+    print $spline->evaluate(5)."\n";
+
+produces the output
+
+2.44    						   
+
+=head1 HISTORY
+
+$Log: Spline.pm,v $
+Revision 1.1  1995/12/26 17:28:17  willijar
+Initial revision
+
+
+=head1 BUGS
+
+Bug reports or constructive comments are welcome.
+
+=head1 AUTHOR
+
+John A.R. Williams <J.A.R.Williams@aston.ac.uk>
+
+=head1 SEE ALSO
+
+"Numerical Recipies: The Art of Scientific Computing"
+W.H. Press, B.P. Flannery, S.A. Teukolsky, W.T. Vetterling.
+Cambridge University Press. ISBN 0 521 30811 9.
+
+=cut
+
+require Exporter;
+package Math::Spline;
+@ISA=qw(Exporter);
+@EXPORT_OK=qw(linsearch binsearch spline);
+use Carp;
+use Math::Derivative qw(Derivative2);
+use strict;
+
+sub new {
+  my $type=shift;
+  my $self=[];
+  push @{$self},shift; # x
+  push @{$self},shift; # y
+  my $y2=[Derivative2($self->[0],$self->[1])];
+  push @{$self},$y2;
+  bless $self,$type;
+}
+
+sub evaluate {
+  my ($self,$v)=@_;
+  my $idx=binsearch($self->[0],$v);
+  spline($self->[0],$self->[1],$self->[2],$idx,$v);
+}
+
+sub spline { 
+  my ($x,$y,$y2,$i,$v)=@_;
+  my ($klo,$khi)=($i,$i+1);
+  my $h=$x->[$khi]-$x->[$klo];
+  if ($h==0) { croak "Zero interval in spline data.\n"; }
+  my $a=($x->[$khi]-$v)/$h;
+  my $b=($v-$x->[$klo])/$h;
+  return $a*$y->[$klo] + $b*$y->[$khi]
+      +(($a*$a*$a-$a)*$y2->[$klo]
+	+($b*$b*$b-$b)*$y2->[$khi])*($h*$h)/6.0;
+}
+
+sub binsearch { # binary search routine finds index just below value
+  my ($x,$v)=@_;
+  my ($klo,$khi)=(0,$#{$x});
+  my $k;
+  while (($khi-$klo)>1) {
+    $k=int(($khi+$klo)/2);
+    if ($x->[$k]>$v) { $khi=$k; } else { $klo=$k; }
+  }
+  return $klo;
+}
+
+sub linsearch { # more efficient if repetatively doint it
+  my ($x,$v,$khi)=@_; $khi+=1;
+  my $n=$#{$x};
+  while($v>$x->[$khi] and $khi<$n) { $khi++; }
+  $_[2]=$khi-1;
+}
+
+1;
+