Gram-Schmidt



> Now that you mention it, an optional argument for gramschmidt, to
> supply the inner production function, would be helpful.

I've attached a patch against the current CVS which:

     * adds an optional `inprod' parameter to gramschmidt in eigen.mac;

     * updates the docs in Matrices.texi;

     * adds a test to test_vector_analysis.mac.

For instance:

    (%i3) load("eigen")$
    (%i4) ip(f, g) := integrate(f * g, 'x, a, b)$
    (%i5) gramschmidt([1, sin(x), cos(x)], ip),
    a = -%pi/2, b = %pi/2;
                                          %pi cos(x) - 2
    (%o5)                     [1, sin(x), --------------]
                                               %pi
-------------- next part --------------
diff -Naur maxima-cvs/ChangeLog maxima/ChangeLog
--- maxima-cvs/ChangeLog	2007-10-28 17:45:12.000000000 -0700
+++ maxima/ChangeLog	2007-10-28 19:07:40.000000000 -0700
@@ -1,3 +1,14 @@
+2007-10-28  Peter Danenberg  <pcd at wikitex.org>
+
+	* share/matrix/eigen.mac: added optional inner-product
+	  to gramschmidt.
+
+	* doc/info/Matrices.texi:
+	  Added documentation for optional inner-product.
+
+	* tests/wester_problems/test_vector_analysis.mac: added
+	  a test for gramschmidt with inner-product.
+
 2005-03-13 12:00  robert_dodier
 
 	* src/nset.lisp, tests/rtestnset.mac:
diff -Naur maxima-cvs/doc/info/Matrices.texi maxima/doc/info/Matrices.texi
--- maxima-cvs/doc/info/Matrices.texi	2007-10-28 17:45:09.000000000 -0700
+++ maxima/doc/info/Matrices.texi	2007-10-28 19:07:33.000000000 -0700
@@ -751,10 +751,13 @@
 
 @end deffn
 
- at deffn {Function} gramschmidt (@var{x})
+ at deffn {Function} gramschmidt (@var{x}, @var{inprod})
+ at deffnx {Function} gramschmidt (@var{x})
+ at deffnx {Function} gschmit (@var{x}, @var{inprod})
 @deffnx {Function} gschmit (@var{x})
 Carries out the Gram-Schmidt orthogonalization algorithm on @var{x},
-which is either a matrix or a list of lists.
+which is either a matrix or a list of lists; using the optional
+inner-product @var{inprod}.
 @var{x} is not modified by @code{gramschmidt}.
 
 If @var{x} is a matrix, the algorithm is applied to the rows of @var{x}.
diff -Naur maxima-cvs/share/matrix/eigen.mac maxima/share/matrix/eigen.mac
--- maxima-cvs/share/matrix/eigen.mac	2007-10-28 17:45:10.000000000 -0700
+++ maxima/share/matrix/eigen.mac	2007-10-28 19:07:33.000000000 -0700
@@ -58,17 +58,20 @@
 columnvector(x):=transpose(matrix(x))$
 
 
-gramschmidt(x):=
+gramschmidt(x,[inprod]):=
 		block([listarith,dimnsn,listall,intern,count,denom,unit,index1,
 		index2],
+                local(inprod),
+                if inprod=[] then inprod:innerproduct
+                else inprod:first(inprod),
                 mode_declare([dimnsn,count,index1,index2],fixnum,
                               [listall],list,[intern,denom,unit],any),
 		listarith:true,dimnsn:mi(length(x)),listall:[part(x,1)],
 		count:1,if dimnsn=1 then return(x)
 		else (for index1:2 thru dimnsn do
 		(unit:part(x,index1),for index2 thru count do
-		(intern:part(listall,index2),denom:innerproduct(intern,intern),
-		unit:factor(ratsimp(unit-innerproduct(intern,unit)*intern/denom
+		(intern:part(listall,index2),denom:inprod(intern,intern),
+		unit:factor(ratsimp(unit-inprod(intern,unit)*intern/denom
 		))),
 		count:count+1,listall:endcons(unit,listall)),
 		return(listall)))$
diff -Naur maxima-cvs/tests/wester_problems/test_vector_analysis.mac maxima/tests/wester_problems/test_vector_analysis.mac
--- maxima-cvs/tests/wester_problems/test_vector_analysis.mac	2007-10-28 17:45:11.000000000 -0700
+++ maxima/tests/wester_problems/test_vector_analysis.mac	2007-10-28 19:07:33.000000000 -0700
@@ -68,5 +68,8 @@
    Company, 1981, p. 104 => [[0 1 2 1], [0 -1 1 -1], [2 1 0 -1]]^T */
 [[0, 1, 2, 1], [0, 1, 3, 1], [1, 1, 1, 0], [1, 3, 6, 2]];
 gramschmidt(%);
+/* Optional inner-product */
+gramschmidt([1,sin(x),cos(x)], lambda([f, g], integrate(f * g, x, a, b))),
+a = -%pi/2, b = %pi/2;
 /* ---------- Quit ---------- */
 quit();