1math::linearalgebra(n)         Tcl Math Library         math::linearalgebra(n)
2
3
4
5______________________________________________________________________________
6

NAME

8       math::linearalgebra - Linear Algebra
9

SYNOPSIS

11       package require Tcl  ?8.4?
12
13       package require math::linearalgebra  ?1.1?
14
15       ::math::linearalgebra::mkVector ndim value
16
17       ::math::linearalgebra::mkUnitVector ndim ndir
18
19       ::math::linearalgebra::mkMatrix nrows ncols value
20
21       ::math::linearalgebra::getrow matrix row ?imin? ?imax?
22
23       ::math::linearalgebra::setrow matrix row newvalues ?imin? ?imax?
24
25       ::math::linearalgebra::getcol matrix col ?imin? ?imax?
26
27       ::math::linearalgebra::setcol matrix col newvalues ?imin? ?imax?
28
29       ::math::linearalgebra::getelem matrix row col
30
31       ::math::linearalgebra::setelem matrix row ?col? newvalue
32
33       ::math::linearalgebra::swaprows matrix irow1 irow2 ?imin? ?imax?
34
35       ::math::linearalgebra::swapcols matrix icol1 icol2 ?imin? ?imax?
36
37       ::math::linearalgebra::show obj ?format? ?rowsep? ?colsep?
38
39       ::math::linearalgebra::dim obj
40
41       ::math::linearalgebra::shape obj
42
43       ::math::linearalgebra::conforming type obj1 obj2
44
45       ::math::linearalgebra::symmetric matrix ?eps?
46
47       ::math::linearalgebra::norm vector type
48
49       ::math::linearalgebra::norm_one vector
50
51       ::math::linearalgebra::norm_two vector
52
53       ::math::linearalgebra::norm_max vector ?index?
54
55       ::math::linearalgebra::normMatrix matrix type
56
57       ::math::linearalgebra::dotproduct vect1 vect2
58
59       ::math::linearalgebra::unitLengthVector vector
60
61       ::math::linearalgebra::normalizeStat mv
62
63       ::math::linearalgebra::axpy scale mv1 mv2
64
65       ::math::linearalgebra::add mv1 mv2
66
67       ::math::linearalgebra::sub mv1 mv2
68
69       ::math::linearalgebra::scale scale mv
70
71       ::math::linearalgebra::rotate c s vect1 vect2
72
73       ::math::linearalgebra::transpose matrix
74
75       ::math::linearalgebra::matmul mv1 mv2
76
77       ::math::linearalgebra::angle vect1 vect2
78
79       ::math::linearalgebra::crossproduct vect1 vect2
80
81       ::math::linearalgebra::matmul mv1 mv2
82
83       ::math::linearalgebra::mkIdentity size
84
85       ::math::linearalgebra::mkDiagonal diag
86
87       ::math::linearalgebra::mkRandom size
88
89       ::math::linearalgebra::mkTriangular size ?uplo? ?value?
90
91       ::math::linearalgebra::mkHilbert size
92
93       ::math::linearalgebra::mkDingdong size
94
95       ::math::linearalgebra::mkOnes size
96
97       ::math::linearalgebra::mkMoler size
98
99       ::math::linearalgebra::mkFrank size
100
101       ::math::linearalgebra::mkBorder size
102
103       ::math::linearalgebra::mkWilkinsonW+ size
104
105       ::math::linearalgebra::mkWilkinsonW- size
106
107       ::math::linearalgebra::solveGauss matrix bvect
108
109       ::math::linearalgebra::solvePGauss matrix bvect
110
111       ::math::linearalgebra::solveTriangular matrix bvect ?uplo?
112
113       ::math::linearalgebra::solveGaussBand matrix bvect
114
115       ::math::linearalgebra::solveTriangularBand matrix bvect
116
117       ::math::linearalgebra::determineSVD A eps
118
119       ::math::linearalgebra::eigenvectorsSVD A eps
120
121       ::math::linearalgebra::leastSquaresSVD A y qmin eps
122
123       ::math::linearalgebra::choleski matrix
124
125       ::math::linearalgebra::orthonormalizeColumns matrix
126
127       ::math::linearalgebra::orthonormalizeRows matrix
128
129       ::math::linearalgebra::dger matrix alpha x y ?scope?
130
131       ::math::linearalgebra::dgetrf matrix
132
133       ::math::linearalgebra::to_LA mv
134
135       ::math::linearalgebra::from_LA mv
136
137_________________________________________________________________
138

DESCRIPTION

140       This package offers both low-level procedures and high-level algorithms
141       to deal with linear algebra problems:
142
143       ·      robust solution of linear equations or least squares problems
144
145       ·      determining eigenvectors and eigenvalues of symmetric matrices
146
147       ·      various decompositions of general matrices or matrices of a spe‐
148              cific form
149
150       ·      (limited) support for matrices in band storage, a common type of
151              sparse matrices
152
153       It arose as a re-implementation of Hume's LA package and the desire  to
154       offer  low-level  procedures  as  found in the well-known BLAS library.
155       Matrices are implemented as lists of lists  rather  linear  lists  with
156       reserved  elements, as in the original LA package, as it was found that
157       such an implementation is actually faster.
158
159       It is advisable, however, to use the procedures that are offered,  such
160       as  setrow  and getrow, rather than rely on this representation explic‐
161       itly: that way it is to switch  to  a  possibly  even  faster  compiled
162       implementation that supports the same API.
163
164       Note:  When  using  this package in combination with Tk, there may be a
165       naming conflict, as both this package and Tk define  a  command  scale.
166       See the NAMING CONFLICT section below.
167

PROCEDURES

169       The  package  defines the following public procedures (several exist as
170       specialised procedures, see below):
171
172       Constructing matrices and vectors
173
174       ::math::linearalgebra::mkVector ndim value
175              Create a vector with ndim elements, each with the value value.
176
177              integer ndim
178                     Dimension of the vector (number of components)
179
180              double value
181                     Uniform value to be used (default: 0.0)
182
183
184       ::math::linearalgebra::mkUnitVector ndim ndir
185              Create a unit vector in ndim-dimensional space, along the  ndir-
186              th direction.
187
188              integer ndim
189                     Dimension of the vector (number of components)
190
191              integer ndir
192                     Direction (0, ..., ndim-1)
193
194
195       ::math::linearalgebra::mkMatrix nrows ncols value
196              Create  a matrix with nrows rows and ncols columns. All elements
197              have the value value.
198
199              integer nrows
200                     Number of rows
201
202              integer ncols
203                     Number of columns
204
205              double value
206                     Uniform value to be used (default: 0.0)
207
208
209       ::math::linearalgebra::getrow matrix row ?imin? ?imax?
210              Returns a single row of a matrix as a list
211
212              list matrix
213                     Matrix in question
214
215              integer row
216                     Index of the row to return
217
218              integer imin
219                     Minimum index of the column (default: 0)
220
221              integer imax
222                     Maximum index of the column (default: ncols-1)
223
224
225       ::math::linearalgebra::setrow matrix row newvalues ?imin? ?imax?
226              Set a single row of a matrix to new values (this list must  have
227              the  same  number  of  elements  as the number of columns in the
228              matrix)
229
230              list matrix
231                     name of the matrix in question
232
233              integer row
234                     Index of the row to update
235
236              list newvalues
237                     List of new values for the row
238
239              integer imin
240                     Minimum index of the column (default: 0)
241
242              integer imax
243                     Maximum index of the column (default: ncols-1)
244
245
246       ::math::linearalgebra::getcol matrix col ?imin? ?imax?
247              Returns a single column of a matrix as a list
248
249              list matrix
250                     Matrix in question
251
252              integer col
253                     Index of the column to return
254
255              integer imin
256                     Minimum index of the row (default: 0)
257
258              integer imax
259                     Maximum index of the row (default: nrows-1)
260
261
262       ::math::linearalgebra::setcol matrix col newvalues ?imin? ?imax?
263              Set a single column of a matrix to new values  (this  list  must
264              have  the  same  number of elements as the number of rows in the
265              matrix)
266
267              list matrix
268                     name of the matrix in question
269
270              integer col
271                     Index of the column to update
272
273              list newvalues
274                     List of new values for the column
275
276              integer imin
277                     Minimum index of the row (default: 0)
278
279              integer imax
280                     Maximum index of the row (default: nrows-1)
281
282
283       ::math::linearalgebra::getelem matrix row col
284              Returns a single element of a matrix/vector
285
286              list matrix
287                     Matrix or vector in question
288
289              integer row
290                     Row of the element
291
292              integer col
293                     Column of the element (not present for vectors)
294
295
296       ::math::linearalgebra::setelem matrix row ?col? newvalue
297              Set a single element of a matrix (or vector) to a new value
298
299              list matrix
300                     name of the matrix in question
301
302              integer row
303                     Row of the element
304
305              integer col
306                     Column of the element (not present for vectors)
307
308
309       ::math::linearalgebra::swaprows matrix irow1 irow2 ?imin? ?imax?
310              Swap two rows in a matrix completely or only a selected part
311
312              list matrix
313                     name of the matrix in question
314
315              integer irow1
316                     Index of first row
317
318              integer irow2
319                     Index of second row
320
321              integer imin
322                     Minimum column index (default: 0)
323
324              integer imin
325                     Maximum column index (default: ncols-1)
326
327
328       ::math::linearalgebra::swapcols matrix icol1 icol2 ?imin? ?imax?
329              Swap two columns in a matrix completely or only a selected part
330
331              list matrix
332                     name of the matrix in question
333
334              integer irow1
335                     Index of first column
336
337              integer irow2
338                     Index of second column
339
340              integer imin
341                     Minimum row index (default: 0)
342
343              integer imin
344                     Maximum row index (default: nrows-1)
345
346       Querying matrices and vectors
347
348       ::math::linearalgebra::show obj ?format? ?rowsep? ?colsep?
349              Return a string representing the  vector  or  matrix,  for  easy
350              printing.   (There  is  currently  no way to print fixed sets of
351              columns)
352
353              list obj
354                     Matrix or vector in question
355
356              string format
357                     Format for printing the numbers (default: %6.4f)
358
359              string rowsep
360                     String to use for separating rows (default: newline)
361
362              string colsep
363                     String to use for separating columns (default: space)
364
365
366       ::math::linearalgebra::dim obj
367              Returns the number of dimensions for the object (either 0 for  a
368              scalar, 1 for a vector and 2 for a matrix)
369
370              any obj
371                     Scalar, vector, or matrix
372
373
374       ::math::linearalgebra::shape obj
375              Returns  the number of elements in each dimension for the object
376              (either an empty list for a scalar, a single number for a vector
377              and a list of the number of rows and columns for a matrix)
378
379              any obj
380                     Scalar, vector, or matrix
381
382
383       ::math::linearalgebra::conforming type obj1 obj2
384              Checks if two objects (vector or matrix) have conforming shapes,
385              that is if they can be applied in an operation like addition  or
386              matrix multiplication.
387
388              string type
389                     Type of check:
390
391                     ·      "shape" - the two objects have the same shape (for
392                            all element-wise operations)
393
394                     ·      "rows" - the two objects have the same  number  of
395                            rows  (for  use  as  A and b in a system of linear
396                            equations Ax = b
397
398                     ·      "matmul" - the first object has the same number of
399                            columns  as  the  number  of  rows  of  the second
400                            object. Useful for matrix-matrix or  matrix-vector
401                            multiplication.
402
403              list obj1
404                     First vector or matrix (left operand)
405
406              list obj2
407                     Second vector or matrix (right operand)
408
409
410       ::math::linearalgebra::symmetric matrix ?eps?
411              Checks  if  the given (square) matrix is symmetric. The argument
412              eps is the tolerance.
413
414              list matrix
415                     Matrix to be inspected
416
417              float eps
418                     Tolerance for determining approximate equality  (defaults
419                     to 1.0e-8)
420
421       Basic operations
422
423       ::math::linearalgebra::norm vector type
424              Returns  the norm of the given vector. The type argument can be:
425              1, 2, inf or max, respectively the sum of absolute  values,  the
426              ordinary Euclidean norm or the max norm.
427
428              list vector
429                     Vector, list of coefficients
430
431              string type
432                     Type of norm (default: 2, the Euclidean norm)
433
434       ::math::linearalgebra::norm_one vector
435              Returns  the  L1  norm  of the given vector, the sum of absolute
436              values
437
438              list vector
439                     Vector, list of coefficients
440
441       ::math::linearalgebra::norm_two vector
442              Returns the L2 norm of the given vector, the ordinary  Euclidean
443              norm
444
445              list vector
446                     Vector, list of coefficients
447
448       ::math::linearalgebra::norm_max vector ?index?
449              Returns  the Linf norm of the given vector, the maximum absolute
450              coefficient
451
452              list vector
453                     Vector, list of coefficients
454
455              integer index
456                     (optional) if non zero, returns a list made of the  maxi‐
457                     mum value and the index where that maximum was found.  if
458                     zero, returns the maximum value.
459
460
461       ::math::linearalgebra::normMatrix matrix type
462              Returns the norm of the given matrix. The type argument can  be:
463              1,  2,  inf or max, respectively the sum of absolute values, the
464              ordinary Euclidean norm or the max norm.
465
466              list matrix
467                     Matrix, list of row vectors
468
469              string type
470                     Type of norm (default: 2, the Euclidean norm)
471
472
473       ::math::linearalgebra::dotproduct vect1 vect2
474              Determine the inproduct or dot product  of  two  vectors.  These
475              must have the same shape (number of dimensions)
476
477              list vect1
478                     First vector, list of coefficients
479
480              list vect2
481                     Second vector, list of coefficients
482
483
484       ::math::linearalgebra::unitLengthVector vector
485              Return a vector in the same direction with length 1.
486
487              list vector
488                     Vector to be normalized
489
490
491       ::math::linearalgebra::normalizeStat mv
492              Normalize  the matrix or vector in a statistical sense: the mean
493              of the elements of the columns of the result  is  zero  and  the
494              standard deviation is 1.
495
496              list mv
497                     Vector or matrix to be normalized in the above sense
498
499
500       ::math::linearalgebra::axpy scale mv1 mv2
501              Return a vector or matrix that results from a "daxpy" operation,
502              that is: compute a*x+y (a a scalar and x and y both  vectors  or
503              matrices of the same shape) and return the result.
504
505              Specialised  variants  are:  axpy_vect  and  axpy_mat  (slightly
506              faster, but no check on the arguments)
507
508              double scale
509                     The scale factor for the first vector/matrix (a)
510
511              list mv1
512                     First vector or matrix (x)
513
514              list mv2
515                     Second vector or matrix (y)
516
517
518       ::math::linearalgebra::add mv1 mv2
519              Return a vector or matrix that is the sum of the  two  arguments
520              (x+y)
521
522              Specialised variants are: add_vect and add_mat (slightly faster,
523              but no check on the arguments)
524
525              list mv1
526                     First vector or matrix (x)
527
528              list mv2
529                     Second vector or matrix (y)
530
531
532       ::math::linearalgebra::sub mv1 mv2
533              Return a vector or matrix that is  the  difference  of  the  two
534              arguments (x-y)
535
536              Specialised variants are: sub_vect and sub_mat (slightly faster,
537              but no check on the arguments)
538
539              list mv1
540                     First vector or matrix (x)
541
542              list mv2
543                     Second vector or matrix (y)
544
545
546       ::math::linearalgebra::scale scale mv
547              Scale a vector or matrix and return the result, that is: compute
548              a*x.
549
550              Specialised  variants  are:  scale_vect  and scale_mat (slightly
551              faster, but no check on the arguments)
552
553              double scale
554                     The scale factor for the vector/matrix (a)
555
556              list mv
557                     Vector or matrix (x)
558
559
560       ::math::linearalgebra::rotate c s vect1 vect2
561              Apply a planar rotation to two vectors and return the result  as
562              a  list  of  two vectors: c*x-s*y and s*x+c*y. In algorithms you
563              can often easily determine the cosine and sine of the angle,  so
564              it is more efficient to pass that information directly.
565
566              double c
567                     The cosine of the angle
568
569              double s
570                     The sine of the angle
571
572              list vect1
573                     First vector (x)
574
575              list vect2
576                     Seocnd vector (x)
577
578
579       ::math::linearalgebra::transpose matrix
580              Transpose a matrix
581
582              list matrix
583                     Matrix to be transposed
584
585
586       ::math::linearalgebra::matmul mv1 mv2
587              Multiply  a vector/matrix with another vector/matrix. The result
588              is a matrix, if both x and y are matrices or both  are  vectors,
589              in  which case the "outer product" is computed. If one is a vec‐
590              tor and the other is a matrix, then the result is a vector.
591
592              list mv1
593                     First vector/matrix (x)
594
595              list mv2
596                     Second vector/matrix (y)
597
598
599       ::math::linearalgebra::angle vect1 vect2
600              Compute the angle between two vectors (in radians)
601
602              list vect1
603                     First vector
604
605              list vect2
606                     Second vector
607
608
609       ::math::linearalgebra::crossproduct vect1 vect2
610              Compute the cross product of two (three-dimensional) vectors
611
612              list vect1
613                     First vector
614
615              list vect2
616                     Second vector
617
618
619       ::math::linearalgebra::matmul mv1 mv2
620              Multiply a vector/matrix with another vector/matrix. The  result
621              is  a  matrix, if both x and y are matrices or both are vectors,
622              in which case the "outer product" is computed. If one is a  vec‐
623              tor and the other is a matrix, then the result is a vector.
624
625              list mv1
626                     First vector/matrix (x)
627
628              list mv2
629                     Second vector/matrix (y)
630
631       Common matrices and test matrices
632
633       ::math::linearalgebra::mkIdentity size
634              Create an identity matrix of dimension size.
635
636              integer size
637                     Dimension of the matrix
638
639
640       ::math::linearalgebra::mkDiagonal diag
641              Create  a  diagonal  matrix whose diagonal elements are the ele‐
642              ments of the vector diag.
643
644              list diag
645                     Vector whose elements are used for the diagonal
646
647
648       ::math::linearalgebra::mkRandom size
649              Create a square matrix whose elements are uniformly  distributed
650              random numbers between 0 and 1 of dimension size.
651
652              integer size
653                     Dimension of the matrix
654
655
656       ::math::linearalgebra::mkTriangular size ?uplo? ?value?
657              Create  a  triangular matrix with non-zero elements in the upper
658              or lower part, depending on argument uplo.
659
660              integer size
661                     Dimension of the matrix
662
663              string uplo
664                     Fill the upper (U) or lower part (L)
665
666              double value
667                     Value to fill the matrix with
668
669
670       ::math::linearalgebra::mkHilbert size
671              Create a Hilbert matrix of dimension size.  Hilbert matrices are
672              very  ill-conditioned  with  respect  to  eigenvalue/eigenvector
673              problems. Therefore they are good  candidates  for  testing  the
674              accuracy of algorithms and implementations.
675
676              integer size
677                     Dimension of the matrix
678
679
680       ::math::linearalgebra::mkDingdong size
681              Create a "dingdong" matrix of dimension size.  Dingdong matrices
682              are imprecisely represented, but have the property of being very
683              stable in such algorithms as Gauss elimination.
684
685              integer size
686                     Dimension of the matrix
687
688
689       ::math::linearalgebra::mkOnes size
690              Create  a  square matrix of dimension size whose entries are all
691              1.
692
693              integer size
694                     Dimension of the matrix
695
696
697       ::math::linearalgebra::mkMoler size
698              Create a Moler matrix of size size. (Moler matrices have a  very
699              simple  Choleski  decomposition. It has one small eigenvalue and
700              it can easily upset elimination methods for  systems  of  linear
701              equations.)
702
703              integer size
704                     Dimension of the matrix
705
706
707       ::math::linearalgebra::mkFrank size
708              Create  a  Frank matrix of size size. (Frank matrices are fairly
709              well-behaved matrices)
710
711              integer size
712                     Dimension of the matrix
713
714
715       ::math::linearalgebra::mkBorder size
716              Create a bordered matrix of size size. (Bordered matrices have a
717              very low rank and can upset certain specialised algorithms.)
718
719              integer size
720                     Dimension of the matrix
721
722
723       ::math::linearalgebra::mkWilkinsonW+ size
724              Create  a  Wilkinson  W+  of  size size. This kind of matrix has
725              pairs of eigenvalues that are very close together.  Usually  the
726              order (size) is odd.
727
728              integer size
729                     Dimension of the matrix
730
731
732       ::math::linearalgebra::mkWilkinsonW- size
733              Create  a  Wilkinson  W-  of  size size. This kind of matrix has
734              pairs of eigenvalues with opposite signs, when the order  (size)
735              is odd.
736
737              integer size
738                     Dimension of the matrix
739
740       Common algorithms
741
742       ::math::linearalgebra::solveGauss matrix bvect
743              Solve  a  system of linear equations (Ax=b) using Gauss elimina‐
744              tion.  Returns the solution (x) as a vector  or  matrix  of  the
745              same shape as bvect.
746
747              list matrix
748                     Square matrix (matrix A)
749
750              list bvect
751                     Vector  or matrix whose columns are the individual b-vec‐
752                     tors
753
754       ::math::linearalgebra::solvePGauss matrix bvect
755              Solve a system of linear equations (Ax=b) using  Gauss  elimina‐
756              tion with partial pivoting. Returns the solution (x) as a vector
757              or matrix of the same shape as bvect.
758
759              list matrix
760                     Square matrix (matrix A)
761
762              list bvect
763                     Vector or matrix whose columns are the individual  b-vec‐
764                     tors
765
766
767       ::math::linearalgebra::solveTriangular matrix bvect ?uplo?
768              Solve  a system of linear equations (Ax=b) by backward substitu‐
769              tion. The matrix is supposed to be upper-triangular.
770
771              list matrix
772                     Lower or upper-triangular matrix (matrix A)
773
774              list bvect
775                     Vector or matrix whose columns are the individual  b-vec‐
776                     tors
777
778              string uplo
779                     Indicates  whether  the matrix is lower-triangular (L) or
780                     upper-triangular (U). Defaults to "U".
781
782       ::math::linearalgebra::solveGaussBand matrix bvect
783              Solve a system of linear equations (Ax=b) using  Gauss  elimina‐
784              tion, where the matrix is stored as a band matrix (cf. STORAGE).
785              Returns the solution (x) as a vector or matrix of the same shape
786              as bvect.
787
788              list matrix
789                     Square matrix (matrix A; in band form)
790
791              list bvect
792                     Vector  or matrix whose columns are the individual b-vec‐
793                     tors
794
795
796       ::math::linearalgebra::solveTriangularBand matrix bvect
797              Solve a system of linear equations (Ax=b) by backward  substitu‐
798              tion.  The  matrix is supposed to be upper-triangular and stored
799              in band form.
800
801              list matrix
802                     Upper-triangular matrix (matrix A)
803
804              list bvect
805                     Vector or matrix whose columns are the individual  b-vec‐
806                     tors
807
808
809       ::math::linearalgebra::determineSVD A eps
810              Determines the Singular Value Decomposition of a matrix: A = U S
811              Vtrans.  Returns a list with the matrix U, the vector of  singu‐
812              lar values S and the matrix V.
813
814              list A Matrix to be decomposed
815
816              float eps
817                     Tolerance (defaults to 2.3e-16)
818
819
820       ::math::linearalgebra::eigenvectorsSVD A eps
821              Determines  the eigenvectors and eigenvalues of a real symmetric
822              matrix, using SVD. Returns a list with the matrix of  normalized
823              eigenvectors and their eigenvalues.
824
825              list A Matrix whose eigenvalues must be determined
826
827              float eps
828                     Tolerance (defaults to 2.3e-16)
829
830
831       ::math::linearalgebra::leastSquaresSVD A y qmin eps
832              Determines  the  solution  to a least-sqaures problem Ax ~ y via
833              singular value decomposition. The result is the vector x.
834
835              Note that if you add a column of 1s to  the  matrix,  then  this
836              column  will  represent a constant like in: y = a*x1 + b*x2 + c.
837              To force the intercept to be zero, simply leave it out.
838
839              list A Matrix of independent variables
840
841              list y List of observed values
842
843              float qmin
844                     Minimum singular value to be considered (defaults to 0.0)
845
846              float eps
847                     Tolerance (defaults to 2.3e-16)
848
849
850       ::math::linearalgebra::choleski matrix
851              Determine the Choleski decomposition  of  a  symmetric  positive
852              semidefinite matrix (this condition is not checked!). The result
853              is the lower-triangular matrix L such that L Lt = matrix.
854
855              list matrix
856                     Matrix to be decomposed
857
858
859       ::math::linearalgebra::orthonormalizeColumns matrix
860              Use the modified Gram-Schmidt method to orthogonalize  and  nor‐
861              malize the columns of the given matrix and return the result.
862
863              list matrix
864                     Matrix whose columns must be orthonormalized
865
866
867       ::math::linearalgebra::orthonormalizeRows matrix
868              Use  the  modified Gram-Schmidt method to orthogonalize and nor‐
869              malize the rows of the given matrix and return the result.
870
871              list matrix
872                     Matrix whose rows must be orthonormalized
873
874
875       ::math::linearalgebra::dger matrix alpha x y ?scope?
876              Perform the rank 1 operation A + alpha*x*y' inline (that is: the
877              matrix  A  is adjusted).  For convenience the new matrix is also
878              returned as the result.
879
880              list matrix
881                     Matrix whose rows must be adjusted
882
883              double alpha
884                     Scale factor
885
886              list x A column vector
887
888              list y A column vector
889
890              list scope
891                     If not  provided,  the  operation  is  performed  on  all
892                     rows/columns  of  A if provided, it is expected to be the
893                     list {imin imax jmin jmax} where:
894
895                     ·      imin Minimum row index
896
897                     ·      imax Maximum row index
898
899                     ·      jmin Minimum column index
900
901                     ·      jmax Maximum column index
902
903
904       ::math::linearalgebra::dgetrf matrix
905              Computes an LU factorization of a general matrix, using partial,
906              pivoting with row interchanges. Returns the permutation vector.
907
908              The factorization has the form
909
910                 P * A = L * U
911
912              where P is a permutation matrix, L is lower triangular with unit
913              diagonal elements, and U is upper triangular.
914
915              list matrix
916                     On entry, the matrix to be factored.  On exit,  the  fac‐
917                     tors  L  and U from the factorization P*A = L*U; the unit
918                     diagonal elements of L are not stored.
919
920       Compability with the LA package
921
922       ::math::linearalgebra::to_LA mv
923              Transforms a vector or matrix into the format used by the origi‐
924              nal LA package.
925
926              list mv
927                     Matrix or vector
928
929       ::math::linearalgebra::from_LA mv
930              Transforms a vector or matrix from the format used by the origi‐
931              nal LA package into the format used by the  present  implementa‐
932              tion.
933
934              list mv
935                     Matrix or vector as used by the LA package
936

STORAGE

938       While  most procedures assume that the matrices are given in full form,
939       the procedures solveGaussBand and solveTriangularBand assume  that  the
940       matrices  are  stored  as  band  matrices. This common type of "sparse"
941       matrices is related to ordinary matrices as follows:
942
943       ·      "A" is a full-size matrix with N rows and M columns.
944
945       ·      "B" is a band matrix, with m upper and  lower  diagonals  and  n
946              rows.
947
948       ·      "B"  can  be stored in an ordinary matrix of (2m+1) columns (one
949              for each off-diagonal and the main diagonal) and n rows.
950
951       ·      Element i,j (i = -m,...,m; j =1,...,n)  of  "B"  corresponds  to
952              element  k,j of "A" where k = M+i-1 and M is at least (!) n, the
953              number of rows in "B".
954
955       ·      To set element (i,j) of matrix "B" use:
956
957                  setelem B $j [expr {$N+$i-1}] $value
958
959
960       (There is no convenience procedure for this yet)
961

REMARKS ON THE IMPLEMENTATION

963       There is a difference between the original LA package by Hume  and  the
964       current  implementation. Whereas the LA package uses a linear list, the
965       current package uses lists of lists to represent matrices. It turns out
966       that  with this representation, the algorithms are faster and easier to
967       implement.
968
969       The LA package was used as a model and in fact the  implementation  of,
970       for instance, the SVD algorithm was taken from that package. The set of
971       procedures was expanded using ideas from the  well-known  BLAS  library
972       and some algorithms were updated from the second edition of J.C. Nash's
973       book, Compact Numerical Methods for Computers, (Adam Hilger, 1990) that
974       inspired the LA package.
975
976       Two  procedures  are  provided  to  make the transition between the two
977       implementations easier: to_LA and from_LA. They are described above.
978

TODO

980       Odds and ends: the following algorithms have not been implemented yet:
981
982       ·      determineQR
983
984       ·      certainlyPositive, diagonallyDominant
985

NAMING CONFLICT

987       If you load this package in a Tk-enabled shell like wish, then the com‐
988       mand
989       namespace import ::math::linearalgebra
990       results in an error message about "scale". This is due to the fact that
991       Tk defines all its commands in the global namespace. The solution is to
992       import  the  linear  algebra  commands  in  a namespace that is not the
993       global one:
994
995       package require math::linearalgebra
996       namespace eval compute {
997           namespace import ::math::linearalgebra::*
998           ... use the linear algebra version of scale ...
999       }
1000
1001       To use Tk's scale command in that same namespace you can rename it:
1002
1003       namespace eval compute {
1004           rename ::scale scaleTk
1005           scaleTk .scale ...
1006       }
1007
1008

BUGS, IDEAS, FEEDBACK

1010       This document, and the package it describes, will  undoubtedly  contain
1011       bugs  and  other  problems.  Please report such in the category math ::
1012       linearalgebra   of   the    Tcllib    SF    Trackers    [http://source
1013       forge.net/tracker/?group_id=12883].   Please  also report any ideas for
1014       enhancements you may have for either package and/or documentation.
1015

KEYWORDS

1017       least squares, linear algebra, linear equations, math,  matrices,  vec‐
1018       tors
1019
1021       Copyright (c) 2004-2008 Arjen Markus <arjenmarkus@users.sourceforge.net>
1022       Copyright (c) 2004 Ed Hume <http://www.hume.com/contact.us.htm>
1023       Copyright (c) 2008 Michael Buadin <relaxkmike@users.sourceforge.net>
1024
1025
1026
1027
1028math                                  1.1               math::linearalgebra(n)
Impressum