changeset 6743:f11fec9c06b0

[project @ 2007-06-18 19:12:48 by dbateman]
author dbateman
date Mon, 18 Jun 2007 19:12:48 +0000
parents ebf96cc00ee9
children b6c6587c1fb0
files doc/ChangeLog doc/interpreter/Makefile.in doc/interpreter/interp.txi doc/interpreter/interpimages.m
diffstat 4 files changed, 61 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/doc/ChangeLog	Mon Jun 18 16:28:48 2007 +0000
+++ b/doc/ChangeLog	Mon Jun 18 19:12:48 2007 +0000
@@ -1,3 +1,10 @@
+2007-06-18  David Bateman  <dbateman@free.fr>
+
+	* interpreter/interpimages.m: Simpler images to demonstrate
+	the continuity of the second derivative of splines.
+	* interpreter/interp.txi: Also change figures here.
+	* interpreter/Makefile.in: and here.
+	
 2007-06-18  Søren Hauberg  <hauberg@gmail.com>
 
         * interpreter/optim.txi: Added some introductory text to each
--- a/doc/interpreter/Makefile.in	Mon Jun 18 16:28:48 2007 +0000
+++ b/doc/interpreter/Makefile.in	Mon Jun 18 19:12:48 2007 +0000
@@ -43,7 +43,7 @@
 
 EXAMPLE_FILES = $(addprefix $(top_srcdir)/examples/, $(EXAMPLE_FILES_NODIR))
 
-INTERPIMAGES = interpft interpn interpderiv
+INTERPIMAGES = interpft interpn interpderiv1 interpderiv2
 INTERPIMAGES_EPS = $(addsuffix .eps, $(INTERPIMAGES))
 INTERPIMAGES_PDF = $(addsuffix .pdf, $(INTERPIMAGES))
 INTERPIMAGES_PNG = $(addsuffix .png, $(INTERPIMAGES))
--- a/doc/interpreter/interp.txi	Mon Jun 18 16:28:48 2007 +0000
+++ b/doc/interpreter/interp.txi	Mon Jun 18 19:12:48 2007 +0000
@@ -18,31 +18,49 @@
 There are some important differences between the various interpolation
 methods. The 'spline' method enforces that both the first and second
 derivatives of the interpolated values have a continuous derivative,
-whereas the other methods do not. This can be demonstrated by the code
+whereas the other methods do not. This means that the results of the
+'spline' method are generally smoother. If the function to be
+interpolated is in fact smooth, then 'spline' will give excellent
+results. However, if the function to be evaluated is in some manner
+discontinuous, then 'pchip' interpolation might give better results.
+
+This can be demonstrated by the code
 
 @example
 @group
-t = 0 : 0.3 : pi; dt = t(2)-t(1);
-n = length (t); k = 100; dti = dt*n/k;
-ti = t(1) + [0 : k-1]*dti;
-y = sin (4*t + 0.3) .* cos (3*t - 0.1);
-ddyc = diff(diff(interp1(t,y,ti,'cubic'))./dti)./dti;
-ddys = diff(diff(interp1(t,y,ti,'spline'))./dti)./dti;
-ddyp = diff(diff(interp1(t,y,ti,'pchip'))./dti)./dti;
-plot (ti(2:end-1), ddyc,'g+',ti(2:end-1),ddys,'b*', ...
-      ti(2:end-1),ddyp,'c^');
-legend('cubic','spline','pchip');
+t = -2:2;
+dt = 1;
+ti =-2:0.025:2;
+dti = 0.025;
+y = sign(t);
+ys = interp1(t,y,ti,'spline');
+yp = interp1(t,y,ti,'pchip');
+ddys = diff(diff(ys)./dti)./dti;
+ddyp = diff(diff(yp)./dti)./dti;
+figure(1);
+plot (ti, ys,'r-', ti, yp,'g-');
+legend('spline','pchip',4);
+figure(2);
+plot (ti, ddys,'r+', ti, ddyp,'g*');
+legend('spline','pchip');
 @end group
 @end example
 
 @ifnotinfo
 @noindent
-The result of which can be seen in @ref{fig:interpderiv}.
+The result of which can be seen in @ref{fig:interpderiv1} and
+@ref{fig:interpderiv2}.
 
-@float Figure,fig:interpderiv
-@image{interpderiv,8cm}
-@caption{Comparison of second derivative of interpolated values for
-various interpolation methods}
+@float Figure,fig:interpderiv1
+@image{interpderiv1,8cm}
+@caption{Comparison of 'phcip' and 'spline' interpolation methods for a 
+step function}
+@end float
+
+@float Figure,fig:interpderiv2
+@image{interpderiv2,8cm}
+@caption{Comparison of the second derivate of the 'phcip' and 'spline' 
+interpolation methods for a step function}
 @end float
 @end ifnotinfo
 
--- a/doc/interpreter/interpimages.m	Mon Jun 18 16:28:48 2007 +0000
+++ b/doc/interpreter/interpimages.m	Mon Jun 18 19:12:48 2007 +0000
@@ -20,17 +20,27 @@
     vi = interpn(x, y, z, v, xxi, yyi, zzi, 'spline');
     mesh (zi, yi, squeeze (vi(1,:,:)));
     print (strcat (nm, ".", typ), strcat ("-d", typ))
-  elseif (strcmp (nm, "interpderiv"))
-    t = 0 : 0.3 : pi; dt = t(2)-t(1);
-    n = length (t); k = 100; dti = dt*n/k;
-    ti = t(1) + [0 : k-1]*dti;
-    y = sin (4*t + 0.3) .* cos (3*t - 0.1);
-    ddyc = diff(diff(interp1(t,y,ti,'cubic'))./dti)./dti;
+  elseif (strcmp (nm, "interpderiv1"))
+    t = -2:2;
+    dt = 1;
+    ti =-2:0.025:2;
+    dti = 0.025;
+    y = sign(t);
+    ys = interp1(t,y,ti,'spline');
+    yp = interp1(t,y,ti,'pchip');
+    plot (ti, ys,'r-', ti, yp,'g-');
+    legend('spline','pchip', 4);
+    print (strcat (nm, ".", typ), strcat ("-d", typ))
+  elseif (strcmp (nm, "interpderiv2"))
+    t = -2:2;
+    dt = 1;
+    ti =-2:0.025:2;
+    dti = 0.025;
+    y = sign(t);
     ddys = diff(diff(interp1(t,y,ti,'spline'))./dti)./dti;
     ddyp = diff(diff(interp1(t,y,ti,'pchip'))./dti)./dti;
-    plot (ti(2:end-1), ddyc,'g+',ti(2:end-1),ddys,'b*', ...
-          ti(2:end-1),ddyp,'c^');
-    legend('cubic','spline','pchip');
+    plot (ti(2:end-1),ddys,'r*', ti(2:end-1),ddyp,'g+');
+    legend('spline','pchip');
     print (strcat (nm, ".", typ), strcat ("-d", typ))
   endif
   bury_output ();