Add missing ===end=== line in zheev example
[maxima.git] / doc / info / lapack.texi.m4
blob02c7ab6022e7ef3dc8ea5aebe2866e8a57be193d
1 @menu
2 * Introduction to lapack::
3 * Functions and Variables for lapack::
4 @end menu
6 @node Introduction to lapack, Functions and Variables for lapack, Package lapack, Package lapack
7 @section Introduction to lapack
9 @code{lapack} is a Common Lisp translation (via the program @code{f2cl}) of the Fortran library LAPACK,
10 as obtained from the SLATEC project.
12 @opencatbox{Categories:}
13 @category{Numerical methods}
14 @category{Share packages}
15 @category{Package lapack}
16 @closecatbox
19 @node Functions and Variables for lapack, , Introduction to lapack, Package lapack
20 @section Functions and Variables for lapack
22 @anchor{dgeev}
23 @deffn {Function} dgeev (@var{A})
24 @deffnx {Function} dgeev (@var{A}, @var{right_p}, @var{left_p})
26 Computes the eigenvalues and, optionally, the eigenvectors of a matrix @var{A}.
27 All elements of @var{A} must be integer or floating point numbers.
28 @var{A} must be square (same number of rows and columns).
29 @var{A} might or might not be symmetric.
31 To make use of this function, you must load the LaPack package via
32 @code{load("lapack")}.
34 @code{dgeev(@var{A})} computes only the eigenvalues of @var{A}.
35 @code{dgeev(@var{A}, @var{right_p}, @var{left_p})} computes the eigenvalues of @var{A}
36 and the right eigenvectors when @math{@var{right_p} = @code{true}}
37 and the left eigenvectors when @math{@var{left_p} = @code{true}}.
39 A list of three items is returned.
40 The first item is a list of the eigenvalues.
41 The second item is @code{false} or the matrix of right eigenvectors.
42 The third item is @code{false} or the matrix of left eigenvectors.
44 The right eigenvector
45 m4_math(<<<v_j>>>,<<<v_j>>>)
46 (the @math{j}-th column of the right eigenvector matrix) satisfies
48 m4_displaymath(
49 <<<\mathbf{A} v_j = \lambda_j v_j>>>,
50 <<<@math{A . v_j = lambda_j . v_j}>>>,
51 <<<{\bf A} v_j = \lambda_j v_j>>>
54 where
55 m4_math(<<<\lambda_j>>>,<<<@math{lambda_j}>>>)
56 is the corresponding eigenvalue.
57 The left eigenvector
58 m4_math(<<<u_j>>>,<<<u_j>>>)
59 (the @math{j}-th column of the left eigenvector matrix) satisfies
61 m4_displaymath(
62 <<<u_j^\mathbf{H} \mathbf{A} = \lambda_j u_j^\mathbf{H}>>>,
63 <<<@math{u_j^H . A = lambda_j . u_j^H}>>>,
64 <<<u_j^{\bf H} {\bf A} = \lambda_j u_j^{\bf H}>>>
67 where
68 m4_math(<<<u_j^\mathbf{H}>>>,<<<u_j^H>>>, <<<u_j^{\bf H}>>>)
69 denotes the conjugate transpose of
70 m4_mathdot(<<<u_j>>>,<<<u_j>>>)
71 For a Maxima function to compute the conjugate transpose, @pxref{ctranspose}.
74 The computed eigenvectors are normalized to have Euclidean norm
75 equal to 1, and largest component has imaginary part equal to zero.
77 Example:
79 @c ===beg===
80 @c load ("lapack")$
81 @c fpprintprec : 6;
82 @c M : matrix ([9.5, 1.75], [3.25, 10.45]);
83 @c dgeev (M);
84 @c [L, v, u] : dgeev (M, true, true);
85 @c D : apply (diag_matrix, L);
86 @c M . v - v . D;
87 @c transpose (u) . M - D . transpose (u);
88 @c ===end===
89 @example
90 (%i1) load ("lapack")$
91 (%i2) fpprintprec : 6;
92 (%o2)                           6
93 (%i3) M : matrix ([9.5, 1.75], [3.25, 10.45]);
94                          [ 9.5   1.75  ]
95 (%o3)                    [             ]
96                          [ 3.25  10.45 ]
97 (%i4) dgeev (M);
98 (%o4)          [[7.54331, 12.4067], false, false]
99 (%i5) [L, v, u] : dgeev (M, true, true);
100                            [ - .666642  - .515792 ]
101 (%o5) [[7.54331, 12.4067], [                      ], 
102                            [  .745378   - .856714 ]
103                                         [ - .856714  - .745378 ]
104                                         [                      ]]
105                                         [  .515792   - .666642 ]
106 (%i6) D : apply (diag_matrix, L);
107                       [ 7.54331     0    ]
108 (%o6)                 [                  ]
109                       [    0     12.4067 ]
110 (%i7) M . v - v . D;
111                 [      0.0       - 8.88178E-16 ]
112 (%o7)           [                              ]
113                 [ - 8.88178E-16       0.0      ]
114 (%i8) transpose (u) . M - D . transpose (u);
115                      [ 0.0  - 4.44089E-16 ]
116 (%o8)                [                    ]
117                      [ 0.0       0.0      ]
118 @end example
120 @opencatbox{Categories:}
121 @category{Package lapack}
122 @closecatbox
124 @end deffn
126 @anchor{dgeqrf}
127 @deffn {Function} dgeqrf (@var{A})
129 Computes the QR decomposition of the matrix @var{A}.
130 All elements of @var{A} must be integer or floating point numbers.
131 @var{A} may or may not have the same number of rows and columns.
133 To make use of this function, you must load the LaPack package via
134 @code{load("lapack")}.
136 The real square matrix
137 m4_math(<<<\mathbf{A}>>>, <<<A>>>, <<<{\bf A}>>>)
138 can be decomposed as
140 m4_displaymath(
141 <<<\mathbf{A} = \mathbf{Q}\mathbf{R}>>>,
142 <<<A = QR>>>,
143 <<<{\bf A} = {\bf Q} {\bf R}>>>)
145 where
146 m4_math(<<<{\bf Q}>>>, <<<Q>>>)
147 is a square orthogonal matrix with the same number of rows as
148 m4_math(<<<\mathbf{A}>>>, <<<A>>>, <<<{\bf A}>>>)
150 m4_math(<<<{\bf R}>>>, <<<R>>>)
151 is an upper triangular matrix and is the same size as
152 m4_mathdot(<<<{\bf A}>>>, A)
154 A list of two items is returned.
155 The first item is the matrix
156 m4_mathdot(<<<{\bf Q}>>>, Q)
157 The second item is the matrix
158 m4_mathcomma(<<<{\bf R}>>>, R)
159 The product @math{Q . R}, where "." is the noncommutative multiplication operator,
160 is equal to @var{A} (ignoring floating point round-off errors).
162 @c ===beg===
163 @c load ("lapack")$
164 @c fpprintprec : 6;
165 @c M : matrix ([1, -3.2, 8], [-11, 2.7, 5.9]);
166 @c [q, r] : dgeqrf (M);
167 @c q . r - M;
168 @c mat_norm (%);
169 @c ===end===
170 @example
171 (%i1) load ("lapack") $
172 (%i2) fpprintprec : 6 $
173 (%i3) M : matrix ([1, -3.2, 8], [-11, 2.7, 5.9]) $
174 (%i4) [q, r] : dgeqrf (M);
175        [ - .0905357  .995893  ]
176 (%o4) [[                      ], 
177        [  .995893    .0905357 ]
178                                [ - 11.0454   2.97863   5.15148 ]
179                                [                               ]]
180                                [     0      - 2.94241  8.50131 ]
181 (%i5) q . r - M;
182          [ - 7.77156E-16   1.77636E-15   - 8.88178E-16 ]
183 (%o5)    [                                             ]
184          [      0.0       - 1.33227E-15   8.88178E-16  ]
185 (%i6) mat_norm (%, 1);
186 (%o6)                      3.10862E-15
187 @end example
189 @opencatbox{Categories:}
190 @category{Package lapack}
191 @closecatbox
193 @end deffn
195 @anchor{dgesv}
196 @deffn {Function} dgesv (@var{A}, @var{b})
198 Computes the solution @var{x} of the linear equation
199 m4_mathcomma(<<<{\bf A} x = b>>>, <<<@var{A} @var{x} = @var{b}>>>)
200 where
201 m4_math(<<<{\bf A}>>>, <<<@var{A}>>>)
202 is a square matrix, and @math{b} is a matrix of the same number of rows
204 m4_math(<<<{\bf A}>>>, <<<@var{A}>>>)
205 and any number of columns.
206 The return value @math{x} is the same size as @math{b}.
208 To make use of this function, you must load the LaPack package via
209 @code{load("lapack")}.
211 The elements of @var{A} and @var{b} must evaluate to real floating point numbers via @code{float};
212 thus elements may be any numeric type, symbolic numerical constants, or expressions which evaluate to floats.
213 The elements of @var{x} are always floating point numbers.
214 All arithmetic is carried out as floating point operations.
216 @code{dgesv} computes the solution via the LU decomposition of @var{A}.
218 Examples:
220 @code{dgesv} computes the solution of the linear equation @math{@var{A} @var{x} = @var{b}}.
222 @c ===beg===
223 @c A : matrix ([1, -2.5], [0.375, 5]);
224 @c b : matrix ([1.75], [-0.625]);
225 @c x : dgesv (A, b);
226 @c dlange (inf_norm, b - A . x);
227 @c ===end===
228 @example
229 (%i1) A : matrix ([1, -2.5], [0.375, 5]);
230                                [   1    - 2.5 ]
231 (%o1)                          [              ]
232                                [ 0.375    5   ]
233 (%i2) b : matrix ([1.75], [-0.625]);
234                                   [  1.75   ]
235 (%o2)                             [         ]
236                                   [ - 0.625 ]
237 (%i3) x : dgesv (A, b);
238                             [  1.210526315789474  ]
239 (%o3)                       [                     ]
240                             [ - 0.215789473684211 ]
241 (%i4) dlange (inf_norm, b - A.x);
242 (%o4)                                 0.0
243 @end example
245 @var{b} is a matrix with the same number of rows as @var{A} and any number of columns.
246 @var{x} is the same size as @var{b}.
248 @c ===beg===
249 @c A : matrix ([1, -0.15], [1.82, 2]);
250 @c b : matrix ([3.7, 1, 8], [-2.3, 5, -3.9]);
251 @c x : dgesv (A, b);
252 @c dlange (inf_norm, b - A . x);
253 @c ===end===
254 @example
255 (%i1) A : matrix ([1, -0.15], [1.82, 2]);
256                                [  1    - 0.15 ]
257 (%o1)                          [              ]
258                                [ 1.82    2    ]
259 (%i2) b : matrix ([3.7, 1, 8], [-2.3, 5, -3.9]);
260                               [  3.7   1    8   ]
261 (%o2)                         [                 ]
262                               [ - 2.3  5  - 3.9 ]
263 (%i3) x : dgesv (A, b);
264       [  3.103827540695117  1.20985481742191    6.781786185657722 ]
265 (%o3) [                                                           ]
266       [ -3.974483062032557  1.399032116146062  -8.121425428948527 ]
267 (%i4) dlange (inf_norm, b - A . x);
268 (%o4)                       1.1102230246251565E-15
269 @end example
271 The elements of @var{A} and @var{b} must evaluate to real floating point numbers.
273 @c ===beg===
274 @c A : matrix ([5, -%pi], [1b0, 11/17]);
275 @c b : matrix ([%e], [sin(1)]);
276 @c x : dgesv (A, b);
277 @c dlange (inf_norm, b - A . x);
278 @c ===end===
279 @example
280 (%i1) A : matrix ([5, -%pi], [1b0, 11/17]);
281                                [   5    - %pi ]
282                                [              ]
283 (%o1)                          [         11   ]
284                                [ 1.0b0   --   ]
285                                [         17   ]
286 (%i2) b : matrix ([%e], [sin(1)]);
287                                   [   %e   ]
288 (%o2)                             [        ]
289                                   [ sin(1) ]
290 (%i3) x : dgesv (A, b);
291                              [ 0.690375643155986 ]
292 (%o3)                        [                   ]
293                              [ 0.233510982552952 ]
294 (%i4) dlange (inf_norm, b - A . x);
295 (%o4)                        2.220446049250313E-16
296 @end example
298 @opencatbox{Categories:}
299 @category{Package lapack}
300 @category{Linear equations}
301 @closecatbox
303 @end deffn
305 @anchor{dgesvd}
306 @deffn {Function} dgesvd (@var{A})
307 @deffnx {Function} dgesvd (@var{A}, @var{left_p}, @var{right_p})
309 Computes the singular value decomposition (SVD) of a matrix @var{A},
310 comprising the singular values and, optionally, the left and right singular vectors.
311 All elements of @var{A} must be integer or floating point numbers.
312 @var{A} might or might not be square (same number of rows and columns).
314 To make use of this function, you must load the LaPack package via
315 @code{load("lapack")}.
317 Let @math{m} be the number of rows, and @math{n} the number of columns of @var{A}.
318 The singular value decomposition of
319 m4_math(<<<\mathbf{A}>>>,<<<@math{A}>>>, <<<{\bf A}>>>)
320 comprises three matrices,
321 m4_mathcomma(<<<\mathbf{U}>>>,<<<U>>>,<<<{\bf U}>>>)
322 m4_mathcomma(<<<\mathbf{\Sigma}>>>,<<<@math{Sigma}>>>, <<<{\bf \Sigma}>>>)
324 m4_mathcomma(<<<\mathbf{V}>>>, <<<@math{V}>>>, <<<{\bf V}>>>)
325 such that
327 @c this code breaks texi2pdf: @math{@var{A} = @var{U} . @var{Sigma} . @var{V^T}}
328 @c @math{@var{A} = @var{U} . @var{Sigma} . @var{V}^T}
330 m4_displaymath(
331 <<<\mathbf{A} = \mathbf{U} \mathbf{\Sigma} \mathbf{V}^T>>>,
332 <<<@math{{A} = {U} . {Sigma} . {V}^T}>>>,
333 <<<{\bf A} = {\bf U} {\bf \Sigma} {\bf V}^T>>>)
336 where
337 m4_math(<<<\mathbf{U}>>>, <<<@math{U}>>>, <<<{\bf U}>>>)
338 is an @math{m}-by-@math{m} unitary matrix,
339 m4_math(<<<\mathbf{\Sigma}>>>, <<<@math{Sigma}>>>, <<<{\bf\Sigma}>>>)
340 is an @math{m}-by-@math{n} diagonal matrix,
342 m4_math(<<<\mathbf{V}>>>, <<<@math{V}>>>, <<<{\bf V}>>>)
343 is an @math{n}-by-@math{n} unitary matrix.
346 m4_math(<<<\mathbf{\sigma}_i>>>, <<<@math{sigma[i]}>>>, <<<{\bf \sigma}_i>>>)
347 be a diagonal element of
348 m4_mathcomma(<<<\mathbf{\Sigma}>>>, <<<@math{Sigma}>>>, <<<{\bf \Sigma}>>>)
349 that is,
350 m4_mathdot(<<<\mathbf{\Sigma}_{ii} = \sigma_i>>>,
351 <<<@math{@var{Sigma}[i, i]  = @var{sigma}[i]}>>>,
352 <<<{\bf \Sigma}_{ii}  = \sigma_i>>>)
353 The elements
354 m4_math(<<<\sigma_i>>>, <<<@math{sigma[i]}>>>)
355 are the so-called singular values of
356 m4_mathpunc(<<<;>>>, <<<\mathbf{A}>>>, <<<A>>>, <<<{\bf A}>>>)
357 these are real and nonnegative, and returned in descending order.
358 The first
359 m4_math(<<<\min(m, n)>>>, <<<min(m, n)>>>)
360 columns of
361 m4_math(<<<\mathbf{U}>>>, <<<@math{U}>>>, <<<{\bf U}>>>)
363 m4_math(<<<\mathbf{V}>>>, <<<@math{V}>>>, <<<{\bf V}>>>)
364 are the left and right singular vectors of
365 m4_mathdot(<<<\mathbf{A}>>>, <<<@math{A}>>>, <<<{\bf A}>>>)
366 Note that @code{dgesvd} returns the transpose of
367 m4_mathcomma(<<<\mathbf{V}>>>, <<<@math{V}>>>, <<<{\bf V}>>>)
369 m4_math(<<<\mathbf{V}>>>, <<<@math{V}>>>, <<<{\bf V}>>>)
370 itself.
372 @code{dgesvd(@var{A})} computes only the singular values of @var{A}.
373 @code{dgesvd(@var{A}, @var{left_p}, @var{right_p})} computes the singular values of @var{A}
374 and the left singular vectors when @math{@var{left_p} = @code{true}}
375 and the right singular vectors when @math{@var{right_p} = @code{true}}.
377 A list of three items is returned.
378 The first item is a list of the singular values.
379 The second item is @code{false} or the matrix of left singular vectors.
380 The third item is @code{false} or the matrix of right singular vectors.
382 Example:
384 @c ===beg===
385 @c load ("lapack")$
386 @c fpprintprec : 6;
387 @c M: matrix([1, 2, 3], [3.5, 0.5, 8], [-1, 2, -3], [4, 9, 7]);
388 @c dgesvd (M);
389 @c [sigma, U, VT] : dgesvd (M, true, true);
390 @c m : length (U);
391 @c n : length (VT);
392 @c Sigma:
393 @c   genmatrix(lambda ([i, j], if i=j then sigma[i] else 0),
394 @c             m, n);
395 @c U . Sigma . VT - M;
396 @c transpose (U) . U;
397 @c VT . transpose (VT);
398 @c ===end===
399 @example
400 (%i1) load ("lapack")$
401 (%i2) fpprintprec : 6;
402 (%o2)                           6
403 (%i3) M: matrix([1, 2, 3], [3.5, 0.5, 8], [-1, 2, -3], [4, 9, 7]);
404                         [  1    2    3  ]
405                         [               ]
406                         [ 3.5  0.5   8  ]
407 (%o3)                   [               ]
408                         [ - 1   2   - 3 ]
409                         [               ]
410                         [  4    9    7  ]
411 (%i4) dgesvd (M);
412 (%o4)      [[14.4744, 6.38637, .452547], false, false]
413 (%i5) [sigma, U, VT] : dgesvd (M, true, true);
414 (%o5) [[14.4744, 6.38637, .452547], 
415 [ - .256731  .00816168   .959029    - .119523 ]
416 [                                             ]
417 [ - .526456   .672116   - .206236   - .478091 ]
418 [                                             ], 
419 [  .107997   - .532278  - .0708315  - 0.83666 ]
420 [                                             ]
421 [ - .803287  - .514659  - .180867    .239046  ]
422 [ - .374486  - .538209  - .755044 ]
423 [                                 ]
424 [  .130623   - .836799   0.5317   ]]
425 [                                 ]
426 [ - .917986   .100488    .383672  ]
427 (%i6) m : length (U);
428 (%o6)                           4
429 (%i7) n : length (VT);
430 (%o7)                           3
431 (%i8) Sigma:
432         genmatrix(lambda ([i, j], if i=j then sigma[i] else 0),
433                   m, n);
434                   [ 14.4744     0        0    ]
435                   [                           ]
436                   [    0     6.38637     0    ]
437 (%o8)             [                           ]
438                   [    0        0     .452547 ]
439                   [                           ]
440                   [    0        0        0    ]
441 (%i9) U . Sigma . VT - M;
442           [  1.11022E-15        0.0       1.77636E-15 ]
443           [                                           ]
444           [  1.33227E-15    1.66533E-15       0.0     ]
445 (%o9)     [                                           ]
446           [ - 4.44089E-16  - 8.88178E-16  4.44089E-16 ]
447           [                                           ]
448           [  8.88178E-16    1.77636E-15   8.88178E-16 ]
449 (%i10) transpose (U) . U;
450        [     1.0      5.55112E-17    2.498E-16     2.77556E-17  ]
451        [                                                        ]
452        [ 5.55112E-17      1.0       5.55112E-17    4.16334E-17  ]
453 (%o10) [                                                        ]
454        [  2.498E-16   5.55112E-17       1.0       - 2.08167E-16 ]
455        [                                                        ]
456        [ 2.77556E-17  4.16334E-17  - 2.08167E-16       1.0      ]
457 (%i11) VT . transpose (VT);
458           [      1.0           0.0      - 5.55112E-17 ]
459           [                                           ]
460 (%o11)    [      0.0           1.0       5.55112E-17  ]
461           [                                           ]
462           [ - 5.55112E-17  5.55112E-17       1.0      ]
463 @end example
465 @opencatbox{Categories:}
466 @category{Package lapack}
467 @closecatbox
469 @end deffn
471 @anchor{dlange}
472 @anchor{zlange}
473 @deffn {Function} dlange (@var{norm}, @var{A})
474 @deffnx {Function} zlange (@var{norm}, @var{A})
476 Computes a norm or norm-like function of the matrix @var{A}.  If
477 @var{A} is a real matrix, use @code{dlange}.  For a matrix with
478 complex elements, use @code{zlange}.
480 To make use of this function, you must load the LaPack package via
481 @code{load("lapack")}.
483 @code{norm} specifies the kind of norm to be computed:
484 @table @code
485 @item max
486 Compute
487 m4_math(<<<\max(|{\bf A}_{ij}|)>>>, <<<max(abs(A(i, j)))>>>)
488 where @math{i} and @math{j} range over
489 the rows and columns, respectively, of
490 m4_mathdot(<<<{\bf A}>>>, <<<A>>>)
491 Note that this function is not a proper matrix norm.
492 @item one_norm
493 Compute the
494 m4_math(<<<L_1>>>, <<<L[1]>>>)
495 norm of
496 m4_mathcomma(<<<{\bf A}>>>, <<<A>>>)
497 that is, the maximum of the sum of the absolute value of elements in each column.
498 @item inf_norm
499 Compute the
500 m4_math(<<<L_\infty>>>, <<<L[inf]>>>)
501 norm of
502 m4_mathcomma(<<<{\bf A}>>>, <<<A>>>)
503 that is, the maximum of the sum of the absolute value of elements in each row.
504 @item frobenius
505 Compute the Frobenius norm of
506 m4_mathcomma(<<<{\bf A}>>>, <<<A>>>)
507 that is, the square root of the sum of squares of the matrix elements.
508 @end table
510 @opencatbox{Categories:}
511 @category{Package lapack}
512 @closecatbox
514 @end deffn
516 @anchor{dgemm}
517 @deffn {Function} dgemm (@var{A}, @var{B})
518 @deffnx {Function} dgemm (@var{A}, @var{B}, @var{options})
519 Compute the product of two matrices and optionally add the product to
520 a third matrix.
522 In the simplest form, @code{dgemm(@var{A}, @var{B})} computes the
523 product of the two real matrices, @var{A} and @var{B}.
525 To make use of this function, you must load the LaPack package via
526 @code{load("lapack")}.
528 In the second form, @code{dgemm} computes
529 m4_math(<<<\alpha {\bf A} {\bf B} + \beta {\bf C}>>>,
530 <<<@var{alpha} * @var{A} * @var{B} + @var{beta} * @var{C}>>>)
531 where
532 m4_mathcomma(<<<{\bf A}>>>, <<<@var{A}>>>)
533 m4_mathcomma(<<<{\bf B}>>>, <<<@var{B}>>>)
535 m4_math(<<<{\bf C}>>>, <<<@var{C}>>>)
536 are real matrices of the appropriate sizes and
537 m4_math(<<<\alpha>>>, <<<alpha>>>)
539 m4_math(<<<\beta>>>, <<<beta>>>)
540 are real numbers.  Optionally,
541 m4_math(<<<{\bf A}>>>, <<<@var{A}>>>)
542 and/or
543 m4_math(<<<{\bf B}>>>, <<<@var{B}>>>)
545 be transposed before computing the product.  The extra parameters are
546 specified by optional keyword arguments: The keyword arguments are
547 optional and may be specified in any order.  They all take the form
548 @code{key=val}.  The keyword arguments are:
550 @table @code
551 @item C
552 The matrix
553 m4_math(<<<{\bf C}>>>, <<<@var{C}>>>)
554 that should be added.  The default is @code{false},
555 which means no matrix is added.
556 @item alpha
557 The product of
558 m4_math(<<<{\bf A}>>>, <<<@var{A}>>>)
560 m4_math(<<<{\bf B}>>>, <<<@var{B}>>>)
561 is multiplied by this value.  The
562 default is 1.
563 @item beta
564 If a matrix
565 m4_math(<<<{\bf C}>>>, <<<@var{C}>>>)
566 is given, this value multiplies
567 m4_math(<<<{\bf C}>>>, <<<@var{C}>>>)
568 before it
569 is added.  The default value is 0, which implies that
570 m4_math(<<<{\bf C}>>>, <<<@var{C}>>>)
571 is not
572 added, even if
573 m4_math(<<<{\bf C}>>>, <<<@var{C}>>>)
574 is given.  Hence, be sure to specify a non-zero
575 value for
576 m4_mathdot(<<<\beta>>>, <<<@math{beta}>>>)
577 @item transpose_a
578 If @code{true}, the transpose of
579 m4_math(<<<{\bf A}>>>, <<<@var{A}>>>)
580 is used instead of
581 m4_math(<<<{\bf A}>>>, <<<@var{A}>>>)
582 for the product.  The default is @code{false}.
583 @item transpose_b
584 If @code{true}, the transpose of
585 m4_math(<<<{\bf B}>>>, <<<@var{B}>>>)
586 is used instead of
587 m4_math(<<<{\bf B}>>>, <<<@var{B}>>>)
588 for the product.  The default is @code{false}.
589 @end table
591 @c ===beg===
592 @c load ("lapack")$
593 @c A : matrix([1,2,3],[4,5,6],[7,8,9]);
594 @c B : matrix([-1,-2,-3],[-4,-5,-6],[-7,-8,-9]);
595 @c C : matrix([3,2,1],[6,5,4],[9,8,7]);
596 @c dgemm(A,B);
597 @c A . B;
598 @c dgemm(A,B,transpose_a=true);
599 @c transpose(A) . B;
600 @c dgemm(A,B,c=C,beta=1);
601 @c A . B + C;
602 @c dgemm(A,B,c=C,beta=1, alpha=-1);
603 @c -A . B + C;
604 @c ===end===
605 @example
606 (%i1) load ("lapack")$
607 (%i2) A : matrix([1,2,3],[4,5,6],[7,8,9]);
608                                   [ 1  2  3 ]
609                                   [         ]
610 (%o2)                             [ 4  5  6 ]
611                                   [         ]
612                                   [ 7  8  9 ]
613 (%i3) B : matrix([-1,-2,-3],[-4,-5,-6],[-7,-8,-9]);
614                                [ - 1  - 2  - 3 ]
615                                [               ]
616 (%o3)                          [ - 4  - 5  - 6 ]
617                                [               ]
618                                [ - 7  - 8  - 9 ]
619 (%i4) C : matrix([3,2,1],[6,5,4],[9,8,7]);
620                                   [ 3  2  1 ]
621                                   [         ]
622 (%o4)                             [ 6  5  4 ]
623                                   [         ]
624                                   [ 9  8  7 ]
625 (%i5) dgemm(A,B);
626                          [ - 30.0   - 36.0   - 42.0  ]
627                          [                           ]
628 (%o5)                    [ - 66.0   - 81.0   - 96.0  ]
629                          [                           ]
630                          [ - 102.0  - 126.0  - 150.0 ]
631 (%i6) A . B;
632                             [ - 30   - 36   - 42  ]
633                             [                     ]
634 (%o6)                       [ - 66   - 81   - 96  ]
635                             [                     ]
636                             [ - 102  - 126  - 150 ]
637 (%i7) dgemm(A,B,transpose_a=true);
638                          [ - 66.0  - 78.0   - 90.0  ]
639                          [                          ]
640 (%o7)                    [ - 78.0  - 93.0   - 108.0 ]
641                          [                          ]
642                          [ - 90.0  - 108.0  - 126.0 ]
643 (%i8) transpose(A) . B;
644                            [ - 66  - 78   - 90  ]
645                            [                    ]
646 (%o8)                      [ - 78  - 93   - 108 ]
647                            [                    ]
648                            [ - 90  - 108  - 126 ]
649 (%i9) dgemm(A,B,c=C,beta=1);
650                          [ - 27.0  - 34.0   - 41.0  ]
651                          [                          ]
652 (%o9)                    [ - 60.0  - 76.0   - 92.0  ]
653                          [                          ]
654                          [ - 93.0  - 118.0  - 143.0 ]
655 (%i10) A . B + C;
656                             [ - 27  - 34   - 41  ]
657                             [                    ]
658 (%o10)                      [ - 60  - 76   - 92  ]
659                             [                    ]
660                             [ - 93  - 118  - 143 ]
661 (%i11) dgemm(A,B,c=C,beta=1, alpha=-1);
662                             [ 33.0   38.0   43.0  ]
663                             [                     ]
664 (%o11)                      [ 72.0   86.0   100.0 ]
665                             [                     ]
666                             [ 111.0  134.0  157.0 ]
667 (%i12) -A . B + C;
668                                [ 33   38   43  ]
669                                [               ]
670 (%o12)                         [ 72   86   100 ]
671                                [               ]
672                                [ 111  134  157 ]
674 @end example
675 @opencatbox{Categories:}
676 @category{Package lapack}
677 @closecatbox
679 @end deffn
681 @anchor{zgeev}
682 @deffn {Function} zgeev (@var{A})
683 @deffnx {Function} zgeev (@var{A}, @var{right_p}, @var{left_p})
685 Like @mrefcomma{dgeev} but the matrix
686 m4_math(<<<{\bf A}>>>, <<<@var{A}>>>)
687 is complex.
689 To make use of this function, you must load the LaPack package via
690 @code{load("lapack")}.
692 @opencatbox{Categories:}
693 @category{Package lapack}
694 @closecatbox
696 @end deffn
698 @anchor{zheev}
699 @deffn {Function} zheev (@var{A})
700 @deffnx {Function} zheev (@var{A}, @var{eigvec_p})
702 Like @mrefcomma{dgeev} but the matrix
703 m4_math(<<<{\bf A}>>>, <<<@var{A}>>>)
704 is assumed to be a square
705 complex Hermitian matrix. If @var{eigvec_p} is @code{true}, then the
706 eigenvectors of the matrix are also computed.
708 To make use of this function, you must load the LaPack package via
709 @code{load("lapack")}.
711 No check is made that the matrix
712 m4_math(<<<{\bf A}>>>, <<<@var{A}>>>)
713 is, in fact, Hermitian.
715 A list of two items is returned, as in @code{dgeev}: a list of
716 eigenvalues, and @code{false} or the matrix of the eigenvectors.
718 @c ===beg===
719 @c load("lapack")
720 @c A: matrix(
721 @c      [9.14 +%i*0.00 ,   -4.37 -%i*9.22 ,  -1.98 -%i*1.72 ,  -8.96 -%i*9.50],
722 @c      [-4.37 +%i*9.22 ,  -3.35 +%i*0.00 ,   2.25 -%i*9.51 ,   2.57 +%i*2.40],
723 @c      [-1.98 +%i*1.72 ,   2.25 +%i*9.51 ,  -4.82 +%i*0.00 ,  -3.24 +%i*2.04],
724 @c      [-8.96 +%i*9.50 ,   2.57 -%i*2.40 ,  -3.24 -%i*2.04 ,   8.44 +%i*0.00]);
725 @c zheev(M);
726 @c E: zheev(M,true)$
727 @c E[1];
728 @c E[2];
729 @c ===end===
730 An example of computing the eigenvalues and then eigenvalues and
731 eigenvectors of an Hermitian matrix.
732 @example
733 (%i1) load("lapack")$
734 (%i2) A: matrix(
735      [9.14 +%i*0.00 ,   -4.37 -%i*9.22 ,  -1.98 -%i*1.72 ,  -8.96 -%i*9.50],
736      [-4.37 +%i*9.22 ,  -3.35 +%i*0.00 ,   2.25 -%i*9.51 ,   2.57 +%i*2.40],
737      [-1.98 +%i*1.72 ,   2.25 +%i*9.51 ,  -4.82 +%i*0.00 ,  -3.24 +%i*2.04],
738      [-8.96 +%i*9.50 ,   2.57 -%i*2.40 ,  -3.24 -%i*2.04 ,   8.44 +%i*0.00]);
739 (%o2) 
740   [      9.14       (- 9.22 %i) - 4.37  (- 1.72 %i) - 1.98  (- 9.5 %i) - 8.96 ]
741   [                                                                           ]
742   [ 9.22 %i - 4.37        - 3.35          2.25 - 9.51 %i      2.4 %i + 2.57   ]
743   [                                                                           ]
744   [ 1.72 %i - 1.98    9.51 %i + 2.25          - 4.82         2.04 %i - 3.24   ]
745   [                                                                           ]
746   [ 9.5 %i - 8.96     2.57 - 2.4 %i     (- 2.04 %i) - 3.24        8.44        ]
747 (%i3) zheev(A);
748 (%o3) [[- 16.00474647209473, - 6.764970154793324, 6.665711453507098, 
749                                                      25.51400517338097], false]
750 (%i4) E:zheev(A,true)$
751 (%i5) E[1];
752 (%o5) [- 16.00474647209474, - 6.764970154793325, 6.665711453507101, 
753                                                              25.51400517338096]
754 (%i6) E[2];
755                [   0.2674650533172745 %i + 0.2175453586665017    ]
756                [                                                 ]
757                [  0.002696730886619885 %i + 0.6968836773391712   ]
758 (%o6)  Col 1 = [                                                 ]
759                [ (- 0.6082406376714117 %i) - 0.01210614292697931 ]
760                [                                                 ]
761                [               0.1593081858095037                ]
762          [   0.2644937470667444 %i + 0.4773693349937472   ]
763          [                                                ]
764          [ (- 0.2852389036031621 %i) - 0.1414362742011673 ]
765  Col 2 = [                                                ]
766          [   0.2654607680986639 %i + 0.4467818117184174   ]
767          [                                                ]
768          [               0.5750762708542709               ]
769          [   0.2810649767305922 %i - 0.1335263928245182   ]
770          [                                                ]
771          [   0.2866310132869556 %i - 0.4536971347853274   ]
772  Col 3 = [                                                ]
773          [ (- 0.2933684323754295 %i) - 0.4954972425541057 ]
774          [                                                ]
775          [               0.5325337537576771               ]
776          [ (- 0.5737316575503476 %i) - 0.3966146799427706 ]
777          [                                                ]
778          [  0.01826502619021457 %i + 0.3530557704387017   ]
779  Col 4 = [                                                ]
780          [  0.1673700900085425 %i + 0.01476684746229564   ]
781          [                                                ]
782          [               0.6002632636961784               ]
783 @end example
785 @opencatbox{Categories:}
786 @category{Package lapack}
787 @closecatbox
789 @end deffn