changeset 6850:9398f6a81bdf

[project @ 2007-08-31 17:29:22 by jwe]
author jwe
date Fri, 31 Aug 2007 17:29:55 +0000
parents c118ea1823f1
children 05f6f120a65f
files doc/ChangeLog doc/interpreter/interp.txi doc/interpreter/nonlin.txi doc/interpreter/octave.texi doc/interpreter/poly.txi scripts/ChangeLog scripts/polynomial/compan.m scripts/polynomial/poly.m scripts/polynomial/polyderiv.m scripts/polynomial/polygcd.m scripts/polynomial/roots.m src/ChangeLog src/load-path.cc
diffstat 13 files changed, 256 insertions(+), 50 deletions(-) [+]
line wrap: on
line diff
--- a/doc/ChangeLog	Fri Aug 31 10:47:27 2007 +0000
+++ b/doc/ChangeLog	Fri Aug 31 17:29:55 2007 +0000
@@ -1,3 +1,10 @@
+2007-08-31  Søren Hauberg  <hauberg@gmail.com>
+
+        * interpreter/nonlin.txi: Extended the example.
+
+        * interpreter/poly.txi: Sectioning and documentation.
+        * interpreter/octave.texi: Adapt to changes in poly.txi.
+
 2007-08-30  David Bateman  <dbateman@free.fr>
 
 	* interpreter/geometryimages.m: Add inpolygon example
--- a/doc/interpreter/interp.txi	Fri Aug 31 10:47:27 2007 +0000
+++ b/doc/interpreter/interp.txi	Fri Aug 31 17:29:55 2007 +0000
@@ -13,6 +13,10 @@
 @node One-dimensional Interpolation
 @section One-dimensional Interpolation
 
+Octave supports several methods for one-dimensional interpolation, most
+of which are described in this section.  @ref{Polynomial Interpolation}
+and @ref{Interpolation on Scattered Data} describes further methods.
+
 @DOCSTRING(interp1)
 
 There are some important differences between the various interpolation
@@ -119,7 +123,8 @@
 @section Multi-dimensional Interpolation
 
 There are three multi-dimensional interpolation function in Octave, with
-similar capabilities.
+similar capabilities.  Methods using Delaunay tessellation are described
+in @ref{Interpolation on Scattered Data}.
 
 @DOCSTRING(interp2)
 
--- a/doc/interpreter/nonlin.txi	Fri Aug 31 10:47:27 2007 +0000
+++ b/doc/interpreter/nonlin.txi	Fri Aug 31 17:29:55 2007 +0000
@@ -15,16 +15,18 @@
 $$
 @end tex
 @end iftex
-@ifinfo
+@ifnottex
 
 @example
 F (x) = 0
 @end example
-@end ifinfo
+@end ifnottex
 
 @noindent
 using the function @code{fsolve}, which is based on the @sc{Minpack}
-subroutine @code{hybrd}.
+subroutine @code{hybrd}.  This is an iterative technique so a starting
+point will have to be provided.  This also has the consequence that
+convergence is not guarantied even if a solution exists.
 
 @DOCSTRING(fsolve)
 
@@ -63,7 +65,7 @@
 @code{f} defined above,
 
 @example
-[x, info] = fsolve ("f", [1; 2])
+[x, info] = fsolve (@@f, [1; 2])
 @end example
 
 @noindent
@@ -78,6 +80,7 @@
 info = 1
 @end example
 
+@noindent
 A value of @code{info = 1} indicates that the solution has converged.
 
 The function @code{perror} may be used to print English messages
@@ -90,4 +93,43 @@
 @end group
 @end example
 
+When no Jacobian is supplied (as in the example above) it is approximated
+numerically.  This requires more function evaluations, and hence is
+less efficient.  In the example above we could compute the Jacobian 
+analytically as
 
+@iftex
+@tex
+$$
+\left[\matrix{ {\partial f_1 \over \partial x_1} &
+               {\partial f_1 \over \partial x_2} \cr
+               {\partial f_2 \over \partial x_1} &
+               {\partial f_2 \over \partial x_2} \cr}\right] =
+\left[\matrix{ 3 x_2 - 4 x_1                  &
+               4 \cos(x_2) + 3 x_1            \cr
+               -2 x_2^2 - 3 \sin(x_1) + 6 x_1 &
+               -4 x_1 x_2                     \cr }\right]
+$$
+@end tex
+which is computed with the following Octave function
+@end iftex
+
+@example
+function J = jacobian(x)
+  J(1,1) =  3*x(2) - 4*x(1);
+  J(1,2) =  4*cos(x(2)) + 3*x(1);
+  J(2,1) = -2*x(2)^2 - 3*sin(x(1)) + 6*x(1);
+  J(2,2) = -4*x(1)*x(2);
+endfunction
+@end example
+
+@noindent
+Using this Jacobian is done with the following code
+
+@example
+[x, info] = fsolve (@{@@f, @@jacobian@}, [1; 2]);
+@end example
+
+@noindent
+which gives the same solution as before.
+
--- a/doc/interpreter/octave.texi	Fri Aug 31 10:47:27 2007 +0000
+++ b/doc/interpreter/octave.texi	Fri Aug 31 17:29:55 2007 +0000
@@ -443,6 +443,15 @@
 
 * Set Operations::
 
+Polynomial Manipulations
+
+* Evaluating Polynomials::
+* Finding Roots::
+* Products of Polynomials::
+* Derivatives and Integrals::
+* Polynomial Interpolation::
+* Miscellaneous Functions::
+
 Interpolation
 
 * One-dimensional Interpolation::
--- a/doc/interpreter/poly.txi	Fri Aug 31 10:47:27 2007 +0000
+++ b/doc/interpreter/poly.txi	Fri Aug 31 17:29:55 2007 +0000
@@ -6,26 +6,13 @@
 @chapter Polynomial Manipulations
 
 In Octave, a polynomial is represented by its coefficients (arranged
-in descending order).  For example, a vector
-@iftex
-@end iftex
-@ifinfo
- $c$
-@end ifinfo
-of length
-@iftex
-@tex
- $N+1$
-@end tex
-@ifinfo
- @var{N+1}
-@end ifinfo
- corresponds to the following polynomial of order
+in descending order).  For example, a vector @var{c} of length
+@math{N+1} corresponds to the following polynomial of order
 @iftex
 @tex
  $N$
 $$
- p (x) = c_1 x^N + ... + c_N x + c_{N+1}.
+ p (x) = c_1 x^N + \ldots + c_N x + c_{N+1}.
 $$
 @end tex
 @end iftex
@@ -37,40 +24,134 @@
 @end example
 @end ifinfo
 
+@menu
+* Evaluating Polynomials::
+* Finding Roots::
+* Products of Polynomials::
+* Derivatives and Integrals::
+* Polynomial Interpolation::
+* Miscellaneous Functions::
+@end menu
+
+@node Evaluating Polynomials
+@section Evaluating Polynomials
+
+The value of a polynomial represented by the vector @var{c} can be evaluated
+at the point @var{x} very easily, as the following example shows.
+
+@example
+N = length(c)-1;
+val = dot( x.^(N:-1:0), c );
+@end example
+
+@noindent
+While the above example shows how easy it is to compute the value of a
+polynomial, it isn't the most stable algorithm.  With larger polynomials
+you should use more elegant algorithms, such as Horner's Method, which
+is exactly what the Octave function @code{polyval} does.
+
+In the case where @var{x} is a square matrix, the polynomial given by
+@var{c} is still well-defined.  As when @var{x} is a scalar the obvious
+implementation is easily expressed in Octave, but also in this case
+more elegant algorithms perform better.  The @code{polyvalm} function
+provides such an algorithm.
+
+@DOCSTRING(polyval)
+
+@DOCSTRING(polyvalm)
+
+@node Finding Roots
+@section Finding Roots
+
+Octave can find the roots of a given polynomial.  This is done by computing
+the companion matrix of the polynomial (see the @code{compan} function
+for a definition), and then finding its eigenvalues.
+
+@DOCSTRING(roots)
+
 @DOCSTRING(compan)
 
+@node Products of Polynomials
+@section Products of Polynomials
+
 @DOCSTRING(conv)
 
 @DOCSTRING(deconv)
 
 @DOCSTRING(conv2)
 
-@DOCSTRING(poly)
+@DOCSTRING(polygcd)
+
+@DOCSTRING(residue)
+
+@node Derivatives and Integrals
+@section Derivatives and Integrals
+
+Octave comes with functions for computing the derivative and the integral
+of a polynomial.  The functions @code{polyderiv} and @code{polyinteg}
+both return new polynomials describing the result.  As an example we'll
+compute the definite integral of @math{p(x) = x^2 + 1} from 0 to 3.
+
+@example
+c = [1, 0, 1];
+integral = polyinteg(c);
+area = polyval(integral, 3) - polyval(integral, 0)
+@result{} 12
+@end example
 
 @DOCSTRING(polyderiv)
 
 @DOCSTRING(polyder)
 
-@DOCSTRING(polyfit)
-
-@DOCSTRING(polygcd)
-
 @DOCSTRING(polyinteg)
 
-@DOCSTRING(polyreduce)
+@node Polynomial Interpolation
+@section Polynomial Interpolation
 
-@DOCSTRING(polyval)
+Octave comes with good support for various kinds of interpolation,
+most of which are described in @ref{Interpolation}.  One simple alternative
+to the functions described in the aforementioned chapter, is to fit
+a single polynomial to some given data points.  To avoid a highly
+fluctuating polynomial, one most often wants to fit a low-order polynomial
+to data.  This usually means that it is necessary to fit the polynomial
+in a least-squares sense, which is what the @code{polyfit} function does.
 
-@DOCSTRING(polyvalm)
+@DOCSTRING(polyfit)
 
-@DOCSTRING(residue)
+In situations where a single polynomial isn't good enough, a solution
+is to use several polynomials pieced together.  The function @code{mkpp}
+creates a piece-wise polynomial, @code{ppval} evaluates the function 
+created by @code{mkpp}, and @code{unmkpp} returns detailed information
+about the function.
+
+The following example shows how to combine two linear functions and a
+quadratic into one function.  Each of these functions are expressed
+on adjoined intervals.
 
-@DOCSTRING(roots)
-
-@DOCSTRING(polyout)
+@example
+x = [-2, -1, 1, 2];
+p = [ 0,  1, 0;
+      1, -2, 1;
+      0, -1, 1 ];
+pp = mkpp(x, p);
+xi = linspace(-2, 2, 50);
+yi = ppval(pp, xi);
+plot(xi, yi);
+@end example
 
 @DOCSTRING(ppval)
 
 @DOCSTRING(mkpp)
 
 @DOCSTRING(unmkpp)
+
+@node Miscellaneous Functions
+@section Miscellaneous Functions
+
+@DOCSTRING(poly)
+
+@DOCSTRING(polyout)
+
+@DOCSTRING(polyreduce)
+
+
--- a/scripts/ChangeLog	Fri Aug 31 10:47:27 2007 +0000
+++ b/scripts/ChangeLog	Fri Aug 31 17:29:55 2007 +0000
@@ -1,3 +1,11 @@
+2007-08-31  Søren Hauberg  <hauberg@gmail.com>
+
+        * polynomial/polygcd.m: Better layout of example.
+        * polynomial/compan.m: Remove unnecessary check.
+        * polynomial/roots.m: Added example to help text.
+        * polynomial/polyderiv.m: Change 'polyder' to 'polyderiv' in help text.
+        * polynomial/poly.m: Added example to help text.
+
 2007-08-30  John W. Eaton  <jwe@octave.org>
 
 	* optimization/qp.m: Increase maxit to 200.
--- a/scripts/polynomial/compan.m	Fri Aug 31 10:47:27 2007 +0000
+++ b/scripts/polynomial/compan.m	Fri Aug 31 17:29:55 2007 +0000
@@ -35,7 +35,7 @@
 ## $$
 ## @end tex
 ## @end iftex
-## @ifinfo
+## @ifnottex
 ##
 ## @smallexample
 ##      _                                                        _
@@ -47,7 +47,7 @@
 ##     |       .            .           .    .             .      |
 ##     |_      0            0      ...       1             0     _|
 ## @end smallexample
-## @end ifinfo
+## @end ifnottex
 ##
 ## The eigenvalues of the companion matrix are equal to the roots of the
 ## polynomial.
@@ -69,12 +69,6 @@
     error ("compan: expecting a vector argument");
   endif
 
-  ## Ensure that c is a row vector.
-
-  if (rows (c) > 1)
-    c = c.';
-  endif
-
   n = length (c);
 
   if (n == 1)
--- a/scripts/polynomial/poly.m	Fri Aug 31 10:47:27 2007 +0000
+++ b/scripts/polynomial/poly.m	Fri Aug 31 17:29:55 2007 +0000
@@ -21,9 +21,24 @@
 ## @deftypefn {Function File} {} poly (@var{a})
 ## If @var{a} is a square @math{N}-by-@math{N} matrix, @code{poly (@var{a})}
 ## is the row vector of the coefficients of @code{det (z * eye (N) - a)},
-## the characteristic polynomial of @var{a}.  If @var{x} is a vector,
-## @code{poly (@var{x})} is a vector of coefficients of the polynomial
-## whose roots are the elements of @var{x}.
+## the characteristic polynomial of @var{a}.  As an example we can use
+## this to find the eigenvalues of @var{a} as the roots of @code{poly (@var{a})}.
+## @example
+## roots(poly(eye(3)))
+## @result{} 1.00000 + 0.00000i
+## @result{} 1.00000 - 0.00000i
+## @result{} 1.00000 + 0.00000i
+## @end example
+## In real-life examples you should, however, use the @code{eig} function
+## for computing eigenvalues.
+##
+## If @var{x} is a vector, @code{poly (@var{x})} is a vector of coefficients
+## of the polynomial whose roots are the elements of @var{x}.  That is,
+## of @var{c} is a polynomial, then the elements of 
+## @code{@var{d} = roots (poly (@var{c}))} are contained in @var{c}.
+## The vectors @var{c} and @var{d} are, however, not equal due to sorting
+## and numerical errors.
+## @seealso{eig, roots}
 ## @end deftypefn
 
 ## Author: KH <Kurt.Hornik@wu-wien.ac.at>
--- a/scripts/polynomial/polyderiv.m	Fri Aug 31 10:47:27 2007 +0000
+++ b/scripts/polynomial/polyderiv.m	Fri Aug 31 17:29:55 2007 +0000
@@ -19,8 +19,8 @@
 
 ## -*- texinfo -*-
 ## @deftypefn {Function File} {} polyderiv (@var{c})
-## @deftypefnx {Function File} {[@var{q}] =} polyder (@var{b}, @var{a})
-## @deftypefnx {Function File} {[@var{q}, @var{r}] =} polyder (@var{b}, @var{a})
+## @deftypefnx {Function File} {[@var{q}] =} polyderiv (@var{b}, @var{a})
+## @deftypefnx {Function File} {[@var{q}, @var{r}] =} polyderiv (@var{b}, @var{a})
 ## Return the coefficients of the derivative of the polynomial whose
 ## coefficients are given by vector @var{c}.  If a pair of polynomials
 ## is given @var{b} and @var{a}, the derivative of the product is
--- a/scripts/polynomial/polygcd.m	Fri Aug 31 10:47:27 2007 +0000
+++ b/scripts/polynomial/polygcd.m	Fri Aug 31 17:29:55 2007 +0000
@@ -31,7 +31,9 @@
 ## Example
 ## @example
 ## polygcd (poly(1:8), poly(3:12)) - poly(3:8)
-##          deconv (poly(1:8), polygcd (poly(1:8), poly(3:12))) - poly(1:2)
+## @result{} [ 0, 0, 0, 0, 0, 0, 0 ]
+## deconv (poly(1:8), polygcd (poly(1:8), poly(3:12))) - poly(1:2)
+## @result{} [ 0, 0, 0 ]
 ## @end example
 ## @seealso{poly, polyinteg, polyderiv, polyreduce, roots, conv, deconv,
 ## residue, filter, polyval, and polyvalm}
--- a/scripts/polynomial/roots.m	Fri Aug 31 10:47:27 2007 +0000
+++ b/scripts/polynomial/roots.m	Fri Aug 31 17:29:55 2007 +0000
@@ -29,12 +29,50 @@
 ## $$
 ## @end tex
 ## @end iftex
-## @ifinfo
+## @ifnottex
 ##
 ## @example
 ## v(1) * z^(N-1) + ... + v(N-1) * z + v(N)
 ## @end example
-## @end ifinfo
+## @end ifnottex
+##
+## As an example, the following code finds the roots of the quadratic
+## polynomial
+## @iftex
+## @tex
+## $$ p(x) = x^2 - 5. $$
+## @end tex
+## @end iftex
+## @ifnottex
+## @example
+## p(x) = x^2 - 5.
+## @end example
+## @end ifnottex
+## @example
+## c = [1, 0, -5];
+## roots(c)
+## @result{}  2.2361
+## @result{} -2.2361
+## @end example
+## Note that the true result is
+## @iftex
+## @tex
+## $\pm \sqrt{5}$
+## @end tex
+## @end iftex
+## @ifnottex
+## @math{+/- sqrt(5)}
+## @end ifnottex
+## which is roughly
+## @iftex
+## @tex
+## $\pm 2.2361$.
+## @end tex
+## @end iftex
+## @ifnottex
+## @math{+/- 2.2361}.
+## @end ifnottex
+## @seealso{compan}
 ## @end deftypefn
 
 ## Author: KH <Kurt.Hornik@wu-wien.ac.at>
--- a/src/ChangeLog	Fri Aug 31 10:47:27 2007 +0000
+++ b/src/ChangeLog	Fri Aug 31 17:29:55 2007 +0000
@@ -1,3 +1,8 @@
+2007-08-31  Michael Goffioul <michael.goffioul@gmail.com>
+
+	* load-path.cc (load_path::do_find_file): Do not assume paths
+	use forward slashes.
+
 2007-08-30  John W. Eaton  <jwe@octave.org>
 
 	* sysdep.cc (Fpause): Doc fix.
--- a/src/load-path.cc	Fri Aug 31 10:47:27 2007 +0000
+++ b/src/load-path.cc	Fri Aug 31 17:29:55 2007 +0000
@@ -743,7 +743,7 @@
 {
   std::string retval;
 
-  if (file.find ('/') != NPOS)
+  if (file.find_first_of (file_ops::dir_sep_chars) != NPOS)
     {
       if (octave_env::absolute_pathname (file)
 	  || octave_env::rooted_relative_pathname (file))