1
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html401/loose.dtd">
3
<!-- Created on September, 20 2006 by texi2html 1.76 -->
5
Written by: Lionel Cons <Lionel.Cons@cern.ch> (original author)
6
Karl Berry <karl@freefriends.org>
7
Olaf Bachmann <obachman@mathematik.uni-kl.de>
9
Maintained by: Many creative people <dev@texi2html.cvshome.org>
10
Send bugs and suggestions to <users@texi2html.cvshome.org>
14
<title>Maxima Manual: 26. Matrices and Linear Algebra</title>
16
<meta name="description" content="Maxima Manual: 26. Matrices and Linear Algebra">
17
<meta name="keywords" content="Maxima Manual: 26. Matrices and Linear Algebra">
18
<meta name="resource-type" content="document">
19
<meta name="distribution" content="global">
20
<meta name="Generator" content="texi2html 1.76">
21
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
22
<style type="text/css">
24
a.summary-letter {text-decoration: none}
25
pre.display {font-family: serif}
26
pre.format {font-family: serif}
27
pre.menu-comment {font-family: serif}
28
pre.menu-preformatted {font-family: serif}
29
pre.smalldisplay {font-family: serif; font-size: smaller}
30
pre.smallexample {font-size: smaller}
31
pre.smallformat {font-family: serif; font-size: smaller}
32
pre.smalllisp {font-size: smaller}
33
span.sansserif {font-family:sans-serif; font-weight:normal;}
34
ul.toc {list-style: none}
47
font-family: sans-serif
53
font-family: sans-serif
59
font-family: sans-serif
62
h2,h3,h4,h5,h6 { margin-left: +4%; }
82
background: rgb(200,255,255);
83
font-family: sans-serif
93
background: rgb(255,220,255);
94
/*background: rgb(200,255,255); */
95
/* font-family: fixed */
105
background: rgb(247,242,180); /* kind of sandy */
106
/* background: rgb(200,255,255); */ /* sky blue */
107
font-family: "Lucida Console", monospace
126
<link rel="icon" href="http://maxima.sourceforge.net/favicon.ico"/>
129
<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
131
<a name="Matrices-and-Linear-Algebra"></a>
133
<table cellpadding="1" cellspacing="1" border="0">
134
<tr><td valign="middle" align="left">[<a href="maxima_25.html#SEC84" title="Previous section in reading order"> < </a>]</td>
135
<td valign="middle" align="left">[<a href="#SEC86" title="Next section in reading order"> > </a>]</td>
136
<td valign="middle" align="left"> </td>
137
<td valign="middle" align="left">[<a href="maxima_25.html#SEC83" title="Beginning of this chapter or previous chapter"> << </a>]</td>
138
<td valign="middle" align="left">[<a href="maxima.html#SEC_Top" title="Up section"> Up </a>]</td>
139
<td valign="middle" align="left">[<a href="maxima_27.html#SEC91" title="Next chapter"> >> </a>]</td>
140
<td valign="middle" align="left"> </td>
141
<td valign="middle" align="left"> </td>
142
<td valign="middle" align="left"> </td>
143
<td valign="middle" align="left"> </td>
144
<td valign="middle" align="left">[<a href="maxima.html#SEC_Top" title="Cover (top) of document">Top</a>]</td>
145
<td valign="middle" align="left">[<a href="maxima_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
146
<td valign="middle" align="left">[<a href="maxima_72.html#SEC264" title="Index">Index</a>]</td>
147
<td valign="middle" align="left">[<a href="maxima_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
149
<h1 class="chapter"> 26. Matrices and Linear Algebra </h1>
151
<table class="menu" border="0" cellspacing="0">
152
<tr><td align="left" valign="top"><a href="#SEC86">26.1 Introduction to Matrices and Linear Algebra</a></td><td> </td><td align="left" valign="top">
154
<tr><td align="left" valign="top"><a href="#SEC90">26.2 Definitions for Matrices and Linear Algebra</a></td><td> </td><td align="left" valign="top">
159
<a name="Introduction-to-Matrices-and-Linear-Algebra"></a>
161
<table cellpadding="1" cellspacing="1" border="0">
162
<tr><td valign="middle" align="left">[<a href="#SEC85" title="Previous section in reading order"> < </a>]</td>
163
<td valign="middle" align="left">[<a href="#SEC87" title="Next section in reading order"> > </a>]</td>
164
<td valign="middle" align="left"> </td>
165
<td valign="middle" align="left">[<a href="#SEC85" title="Beginning of this chapter or previous chapter"> << </a>]</td>
166
<td valign="middle" align="left">[<a href="#SEC85" title="Up section"> Up </a>]</td>
167
<td valign="middle" align="left">[<a href="maxima_27.html#SEC91" title="Next chapter"> >> </a>]</td>
168
<td valign="middle" align="left"> </td>
169
<td valign="middle" align="left"> </td>
170
<td valign="middle" align="left"> </td>
171
<td valign="middle" align="left"> </td>
172
<td valign="middle" align="left">[<a href="maxima.html#SEC_Top" title="Cover (top) of document">Top</a>]</td>
173
<td valign="middle" align="left">[<a href="maxima_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
174
<td valign="middle" align="left">[<a href="maxima_72.html#SEC264" title="Index">Index</a>]</td>
175
<td valign="middle" align="left">[<a href="maxima_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
177
<h2 class="section"> 26.1 Introduction to Matrices and Linear Algebra </h2>
179
<table class="menu" border="0" cellspacing="0">
180
<tr><td align="left" valign="top"><a href="#SEC87">26.1.1 Dot</a></td><td> </td><td align="left" valign="top">
182
<tr><td align="left" valign="top"><a href="#SEC88">26.1.2 Vectors</a></td><td> </td><td align="left" valign="top">
184
<tr><td align="left" valign="top"><a href="#SEC89">26.1.3 eigen</a></td><td> </td><td align="left" valign="top">
191
<table cellpadding="1" cellspacing="1" border="0">
192
<tr><td valign="middle" align="left">[<a href="#SEC86" title="Previous section in reading order"> < </a>]</td>
193
<td valign="middle" align="left">[<a href="#SEC88" title="Next section in reading order"> > </a>]</td>
194
<td valign="middle" align="left"> </td>
195
<td valign="middle" align="left">[<a href="#SEC85" title="Beginning of this chapter or previous chapter"> << </a>]</td>
196
<td valign="middle" align="left">[<a href="#SEC86" title="Up section"> Up </a>]</td>
197
<td valign="middle" align="left">[<a href="maxima_27.html#SEC91" title="Next chapter"> >> </a>]</td>
198
<td valign="middle" align="left"> </td>
199
<td valign="middle" align="left"> </td>
200
<td valign="middle" align="left"> </td>
201
<td valign="middle" align="left"> </td>
202
<td valign="middle" align="left">[<a href="maxima.html#SEC_Top" title="Cover (top) of document">Top</a>]</td>
203
<td valign="middle" align="left">[<a href="maxima_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
204
<td valign="middle" align="left">[<a href="maxima_72.html#SEC264" title="Index">Index</a>]</td>
205
<td valign="middle" align="left">[<a href="maxima_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
207
<h3 class="subsection"> 26.1.1 Dot </h3>
208
<p>The operator <code>.</code> represents noncommutative multiplication and scalar product.
209
When the operands are 1-column or 1-row matrices <code>a</code> and <code>b</code>,
210
the expression <code>a.b</code> is equivalent to <code>sum (a[i]*b[i], i, 1, length(a))</code>.
211
If <code>a</code> and <code>b</code> are not complex, this is the scalar product,
212
also called the inner product or dot product, of <code>a</code> and <code>b</code>.
213
The scalar product is defined as <code>conjugate(a).b</code> when <code>a</code> and <code>b</code> are complex;
214
<code>innerproduct</code> in the <code>eigen</code> package provides the complex scalar product.
216
<p>When the operands are more general matrices,
217
the product is the matrix product <code>a</code> and <code>b</code>.
218
The number of rows of <code>b</code> must equal the number of columns of <code>a</code>,
219
and the result has number of rows equal to the number of rows of <code>a</code>
220
and number of columns equal to the number of columns of <code>b</code>.
222
<p>To distinguish <code>.</code> as an arithmetic operator from
223
the decimal point in a floating point number,
224
it may be necessary to leave spaces on either side.
225
For example, <code>5.e3</code> is <code>5000.0</code> but <code>5 . e3</code> is <code>5</code> times <code>e3</code>.
227
<p>There are several flags which govern the simplification of
228
expressions involving <code>.</code>, namely
229
<code>dot</code>, <code>dot0nscsimp</code>, <code>dot0simp</code>, <code>dot1simp</code>, <code>dotassoc</code>,
230
<code>dotconstrules</code>, <code>dotdistrib</code>, <code>dotexptsimp</code>, <code>dotident</code>,
231
and <code>dotscrules</code>.
234
<a name="Vectors"></a>
236
<table cellpadding="1" cellspacing="1" border="0">
237
<tr><td valign="middle" align="left">[<a href="#SEC87" title="Previous section in reading order"> < </a>]</td>
238
<td valign="middle" align="left">[<a href="#SEC89" title="Next section in reading order"> > </a>]</td>
239
<td valign="middle" align="left"> </td>
240
<td valign="middle" align="left">[<a href="#SEC85" title="Beginning of this chapter or previous chapter"> << </a>]</td>
241
<td valign="middle" align="left">[<a href="#SEC86" title="Up section"> Up </a>]</td>
242
<td valign="middle" align="left">[<a href="maxima_27.html#SEC91" title="Next chapter"> >> </a>]</td>
243
<td valign="middle" align="left"> </td>
244
<td valign="middle" align="left"> </td>
245
<td valign="middle" align="left"> </td>
246
<td valign="middle" align="left"> </td>
247
<td valign="middle" align="left">[<a href="maxima.html#SEC_Top" title="Cover (top) of document">Top</a>]</td>
248
<td valign="middle" align="left">[<a href="maxima_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
249
<td valign="middle" align="left">[<a href="maxima_72.html#SEC264" title="Index">Index</a>]</td>
250
<td valign="middle" align="left">[<a href="maxima_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
252
<h3 class="subsection"> 26.1.2 Vectors </h3>
253
<p><code>vect</code> is a package of functions for vector analysis.
254
<code>load ("vect")</code> loads this package, and <code>demo ("vect")</code> displays a demonstration.
256
<p>The vector analysis package can combine and simplify symbolic
257
expressions including dot products and cross products, together with
258
the gradient, divergence, curl, and Laplacian operators. The
259
distribution of these operators over sums or products is governed
260
by several flags, as are various other expansions, including expansion
261
into components in any specific orthogonal coordinate systems.
262
There are also functions for deriving the scalar or vector potential
265
<p>The <code>vect</code> package contains these functions:
266
<code>vectorsimp</code>, <code>scalefactors</code>,
267
<code>express</code>, <code>potential</code>, and <code>vectorpotential</code>.
269
<p>Warning: the <code>vect</code> package declares the dot operator <code>.</code>
270
to be a commutative operator.
275
<table cellpadding="1" cellspacing="1" border="0">
276
<tr><td valign="middle" align="left">[<a href="#SEC88" title="Previous section in reading order"> < </a>]</td>
277
<td valign="middle" align="left">[<a href="#SEC90" title="Next section in reading order"> > </a>]</td>
278
<td valign="middle" align="left"> </td>
279
<td valign="middle" align="left">[<a href="#SEC85" title="Beginning of this chapter or previous chapter"> << </a>]</td>
280
<td valign="middle" align="left">[<a href="#SEC86" title="Up section"> Up </a>]</td>
281
<td valign="middle" align="left">[<a href="maxima_27.html#SEC91" title="Next chapter"> >> </a>]</td>
282
<td valign="middle" align="left"> </td>
283
<td valign="middle" align="left"> </td>
284
<td valign="middle" align="left"> </td>
285
<td valign="middle" align="left"> </td>
286
<td valign="middle" align="left">[<a href="maxima.html#SEC_Top" title="Cover (top) of document">Top</a>]</td>
287
<td valign="middle" align="left">[<a href="maxima_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
288
<td valign="middle" align="left">[<a href="maxima_72.html#SEC264" title="Index">Index</a>]</td>
289
<td valign="middle" align="left">[<a href="maxima_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
291
<h3 class="subsection"> 26.1.3 eigen </h3>
293
<p>The package <code>eigen</code> contains several functions devoted to the
294
symbolic computation of eigenvalues and eigenvectors.
295
Maxima loads the package automatically if one of the functions
296
<code>eigenvalues</code> or <code>eigenvectors</code> is invoked.
297
The package may be loaded explicitly as <code>load ("eigen")</code>.
299
<p><code>demo ("eigen")</code> displays a demonstration of the capabilities
301
<code>batch ("eigen")</code> executes the same demonstration,
302
but without the user prompt between successive computations.
304
<p>The functions in the <code>eigen</code> package are
305
<code>innerproduct</code>, <code>unitvector</code>, <code>columnvector</code>,
306
<code>gramschmidt</code>, <code>eigenvalues</code>, <code>eigenvectors</code>, <code>uniteigenvectors</code>,
307
and <code>similaritytransform</code>.
310
<a name="Definitions-for-Matrices-and-Linear-Algebra"></a>
312
<table cellpadding="1" cellspacing="1" border="0">
313
<tr><td valign="middle" align="left">[<a href="#SEC89" title="Previous section in reading order"> < </a>]</td>
314
<td valign="middle" align="left">[<a href="maxima_27.html#SEC91" title="Next section in reading order"> > </a>]</td>
315
<td valign="middle" align="left"> </td>
316
<td valign="middle" align="left">[<a href="#SEC85" title="Beginning of this chapter or previous chapter"> << </a>]</td>
317
<td valign="middle" align="left">[<a href="#SEC85" title="Up section"> Up </a>]</td>
318
<td valign="middle" align="left">[<a href="maxima_27.html#SEC91" title="Next chapter"> >> </a>]</td>
319
<td valign="middle" align="left"> </td>
320
<td valign="middle" align="left"> </td>
321
<td valign="middle" align="left"> </td>
322
<td valign="middle" align="left"> </td>
323
<td valign="middle" align="left">[<a href="maxima.html#SEC_Top" title="Cover (top) of document">Top</a>]</td>
324
<td valign="middle" align="left">[<a href="maxima_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
325
<td valign="middle" align="left">[<a href="maxima_72.html#SEC264" title="Index">Index</a>]</td>
326
<td valign="middle" align="left">[<a href="maxima_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
328
<h2 class="section"> 26.2 Definitions for Matrices and Linear Algebra </h2>
331
<dt><u>Function:</u> <b>addcol</b><i> (<var>M</var>, <var>list_1</var>, ..., <var>list_n</var>)</i>
332
<a name="IDX751"></a>
334
<dd><p>Appends the column(s) given by the one
335
or more lists (or matrices) onto the matrix <var>M</var>.
340
<dt><u>Function:</u> <b>addrow</b><i> (<var>M</var>, <var>list_1</var>, ..., <var>list_n</var>)</i>
341
<a name="IDX752"></a>
343
<dd><p>Appends the row(s) given by the one or
344
more lists (or matrices) onto the matrix <var>M</var>.
349
<dt><u>Function:</u> <b>adjoint</b><i> (<var>M</var>)</i>
350
<a name="IDX753"></a>
352
<dd><p>Returns the adjoint of the matrix <var>M</var>.
353
The adjoint matrix is the transpose of the matrix of cofactors of <var>M</var>.
358
<dt><u>Function:</u> <b>augcoefmatrix</b><i> ([<var>eqn_1</var>, ..., <var>eqn_m</var>], [<var>x_1</var>, ..., <var>x_n</var>])</i>
359
<a name="IDX754"></a>
361
<dd><p>Returns the augmented coefficient
362
matrix for the variables <var>x_1</var>, ..., <var>x_n</var> of the system of linear equations
363
<var>eqn_1</var>, ..., <var>eqn_m</var>. This is the coefficient matrix with a column adjoined for
364
the constant terms in each equation (i.e., those terms not dependent upon
365
<var>x_1</var>, ..., <var>x_n</var>).
367
<table><tr><td> </td><td><pre class="example">(%i1) m: [2*x - (a - 1)*y = 5*b, c + b*y + a*x = 0]$
368
(%i2) augcoefmatrix (m, [x, y]);
372
</pre></td></tr></table>
376
<dt><u>Function:</u> <b>charpoly</b><i> (<var>M</var>, <var>x</var>)</i>
377
<a name="IDX755"></a>
379
<dd><p>Returns the characteristic polynomial for the matrix <var>M</var>
380
with respect to variable <var>x</var>. That is,
381
<code>determinant (<var>M</var> - diagmatrix (length (<var>M</var>), <var>x</var>))</code>.
383
<table><tr><td> </td><td><pre class="example">(%i1) a: matrix ([3, 1], [2, 4]);
387
(%i2) expand (charpoly (a, lambda));
389
(%o2) lambda - 7 lambda + 10
390
(%i3) (programmode: true, solve (%));
391
(%o3) [lambda = 5, lambda = 2]
392
(%i4) matrix ([x1], [x2]);
396
(%i5) ev (a . % - lambda*%, %th(2)[1]);
402
(%i7) x2^2 + x1^2 = 1;
405
(%i8) solve ([%th(2), %], [x1, x2]);
407
(%o8) [[x1 = - -------, x2 = - -------],
411
[x1 = -------, x2 = -------]]
413
</pre></td></tr></table>
417
<dt><u>Function:</u> <b>coefmatrix</b><i> ([<var>eqn_1</var>, ..., <var>eqn_m</var>], [<var>x_1</var>, ..., <var>x_n</var>])</i>
418
<a name="IDX756"></a>
420
<dd><p>Returns the coefficient matrix for the
421
variables <var>x_1</var>, ..., <var>x_n</var> of the system of linear equations
422
<var>eqn_1</var>, ..., <var>eqn_m</var>.
424
<table><tr><td> </td><td><pre class="example">(%i1) coefmatrix([2*x-(a-1)*y+5*b = 0, b*y+a*x = 3], [x,y]);
428
</pre></td></tr></table>
432
<dt><u>Function:</u> <b>col</b><i> (<var>M</var>, <var>i</var>)</i>
433
<a name="IDX757"></a>
435
<dd><p>Returns the <var>i</var>'th column of the matrix <var>M</var>.
436
The return value is a matrix.
441
<dt><u>Function:</u> <b>columnvector</b><i> (<var>L</var>)</i>
442
<a name="IDX758"></a>
444
<dt><u>Function:</u> <b>covect</b><i> (<var>L</var>)</i>
445
<a name="IDX759"></a>
447
<dd><p>Returns a matrix of one column and <code>length (<var>L</var>)</code> rows,
448
containing the elements of the list <var>L</var>.
450
<p><code>covect</code> is a synonym for <code>columnvector</code>.
452
<p><code>load ("eigen")</code> loads this function.
454
<p>This is useful if you want to use parts of the outputs of
455
the functions in this package in matrix calculations.
459
<table><tr><td> </td><td><pre class="example">(%i1) load ("eigen")$
460
Warning - you are redefining the Macsyma function eigenvalues
461
Warning - you are redefining the Macsyma function eigenvectors
462
(%i2) columnvector ([aa, bb, cc, dd]);
470
</pre></td></tr></table>
474
<dt><u>Function:</u> <b>conjugate</b><i> (<var>x</var>)</i>
475
<a name="IDX760"></a>
477
<dd><p>Returns the complex conjugate of <var>x</var>.
479
<table><tr><td> </td><td><pre class="example">(%i1) declare ([aa, bb], real, cc, complex, ii, imaginary);
482
(%i2) conjugate (aa + bb*%i);
485
(%i3) conjugate (cc);
488
(%i4) conjugate (ii);
491
(%i5) conjugate (xx + yy);
493
(%o5) conjugate(yy) + conjugate(xx)
494
</pre></td></tr></table>
498
<dt><u>Function:</u> <b>copymatrix</b><i> (<var>M</var>)</i>
499
<a name="IDX761"></a>
501
<dd><p>Returns a copy of the matrix <var>M</var>. This is the only way
502
to make a copy aside from copying <var>M</var> element by element.
504
<p>Note that an assignment of one matrix to another, as in <code>m2: m1</code>,
505
does not copy <code>m1</code>.
506
An assignment <code>m2 [i,j]: x</code> or <code>setelmx (x, i, j, m2</code> also modifies <code>m1 [i,j]</code>.
507
Creating a copy with <code>copymatrix</code> and then using assignment creates a separate, modified copy.
512
<dt><u>Function:</u> <b>determinant</b><i> (<var>M</var>)</i>
513
<a name="IDX762"></a>
515
<dd><p>Computes the determinant of <var>M</var> by a method similar to
516
Gaussian elimination.
518
<p>The form of the result depends upon the setting
519
of the switch <code>ratmx</code>.
521
<p>There is a special routine for computing
522
sparse determinants which is called when the switches
523
<code>ratmx</code> and <code>sparse</code> are both <code>true</code>.
528
<dt><u>Option variable:</u> <b>detout</b>
529
<a name="IDX763"></a>
531
<dd><p>Default value: <code>false</code>
533
<p>When <code>detout</code> is <code>true</code>, the determinant of a
534
matrix whose inverse is computed is factored out of the inverse.
536
<p>For this switch to have an effect <code>doallmxops</code> and <code>doscmxops</code> should be
537
<code>false</code> (see their descriptions). Alternatively this switch can be
538
given to <code>ev</code> which causes the other two to be set correctly.
542
<table><tr><td> </td><td><pre class="example">(%i1) m: matrix ([a, b], [c, d]);
547
(%i3) doallmxops: false$
548
(%i4) doscmxops: false$
555
</pre></td></tr></table>
559
<dt><u>Function:</u> <b>diagmatrix</b><i> (<var>n</var>, <var>x</var>)</i>
560
<a name="IDX764"></a>
562
<dd><p>Returns a diagonal matrix of size <var>n</var> by <var>n</var> with the
563
diagonal elements all equal to <var>x</var>.
564
<code>diagmatrix (<var>n</var>, 1)</code> returns an identity matrix (same as <code>ident (<var>n</var>)</code>).
566
<p><var>n</var> must evaluate to an integer, otherwise <code>diagmatrix</code> complains with an error message.
568
<p><var>x</var> can be any kind of expression, including another matrix.
569
If <var>x</var> is a matrix, it is not copied; all diagonal elements refer to the same instance, <var>x</var>.
574
<dt><u>Option variable:</u> <b>doallmxops</b>
575
<a name="IDX765"></a>
577
<dd><p>Default value: <code>true</code>
579
<p>When <code>doallmxops</code> is <code>true</code>,
580
all operations relating to matrices are carried out.
581
When it is <code>false</code> then the setting of the
582
individual <code>dot</code> switches govern which operations are performed.
587
<dt><u>Option variable:</u> <b>domxexpt</b>
588
<a name="IDX766"></a>
590
<dd><p>Default value: <code>true</code>
592
<p>When <code>domxexpt</code> is <code>true</code>,
593
a matrix exponential, <code>exp (<var>M</var>)</code> where <var>M</var> is a matrix,
594
is interpreted as a matrix with element <code>[i,j</code> equal to <code>exp (m[i,j])</code>.
595
Otherwise <code>exp (<var>M</var>)</code> evaluates to <code>exp (<var>ev(M)</var></code>.
597
<p><code>domxexpt</code>
598
affects all expressions of the form <code><var>base</var>^<var>power</var></code> where <var>base</var> is an
599
expression assumed scalar or constant, and <var>power</var> is a list or
604
<table><tr><td> </td><td><pre class="example">(%i1) m: matrix ([1, %i], [a+b, %pi]);
608
(%i2) domxexpt: false$
614
(%i4) domxexpt: true$
621
</pre></td></tr></table>
625
<dt><u>Option variable:</u> <b>domxmxops</b>
626
<a name="IDX767"></a>
628
<dd><p>Default value: <code>true</code>
630
<p>When <code>domxmxops</code> is <code>true</code>, all matrix-matrix or
631
matrix-list operations are carried out (but not scalar-matrix
632
operations); if this switch is <code>false</code> such operations are not carried out.
637
<dt><u>Option variable:</u> <b>domxnctimes</b>
638
<a name="IDX768"></a>
640
<dd><p>Default value: <code>false</code>
642
<p>When <code>domxnctimes</code> is <code>true</code>, non-commutative products of
643
matrices are carried out.
648
<dt><u>Option variable:</u> <b>dontfactor</b>
649
<a name="IDX769"></a>
651
<dd><p>Default value: <code>[]</code>
653
<p><code>dontfactor</code> may be set to a list of variables with respect
654
to which factoring is not to occur. (The list is initially empty.)
655
Factoring also will not take place with respect to any variables which
656
are less important, according the variable ordering assumed for canonical rational expression (CRE) form,
657
than those on the <code>dontfactor</code> list.
662
<dt><u>Option variable:</u> <b>doscmxops</b>
663
<a name="IDX770"></a>
665
<dd><p>Default value: <code>false</code>
667
<p>When <code>doscmxops</code> is <code>true</code>, scalar-matrix operations are
673
<dt><u>Option variable:</u> <b>doscmxplus</b>
674
<a name="IDX771"></a>
676
<dd><p>Default value: <code>false</code>
678
<p>When <code>doscmxplus</code> is <code>true</code>, scalar-matrix operations yield
679
a matrix result. This switch is not subsumed under <code>doallmxops</code>.
684
<dt><u>Option variable:</u> <b>dot0nscsimp</b>
685
<a name="IDX772"></a>
687
<dd><p>Default value: <code>true</code>
689
<p>When <code>dot0nscsimp</code> is <code>true</code>, a non-commutative product of zero
690
and a nonscalar term is simplified to a commutative product.
695
<dt><u>Option variable:</u> <b>dot0simp</b>
696
<a name="IDX773"></a>
698
<dd><p>Default value: <code>true</code>
700
<p>When <code>dot0simp</code> is <code>true</code>,
701
a non-commutative product of zero and
702
a scalar term is simplified to a commutative product.
707
<dt><u>Option variable:</u> <b>dot1simp</b>
708
<a name="IDX774"></a>
710
<dd><p>Default value: <code>true</code>
712
<p>When <code>dot1simp</code> is <code>true</code>,
713
a non-commutative product of one and
714
another term is simplified to a commutative product.
719
<dt><u>Option variable:</u> <b>dotassoc</b>
720
<a name="IDX775"></a>
722
<dd><p>Default value: <code>true</code>
724
<p>When <code>dotassoc</code> is <code>true</code>, an expression <code>(A.B).C</code> simplifies to
725
<code>A.(B.C)</code>.
730
<dt><u>Option variable:</u> <b>dotconstrules</b>
731
<a name="IDX776"></a>
733
<dd><p>Default value: <code>true</code>
735
<p>When <code>dotconstrules</code> is <code>true</code>, a non-commutative product of a
736
constant and another term is simplified to a commutative product.
737
Turning on this flag effectively turns on <code>dot0simp</code>, <code>dot0nscsimp</code>, and
738
<code>dot1simp</code> as well.
743
<dt><u>Option variable:</u> <b>dotdistrib</b>
744
<a name="IDX777"></a>
746
<dd><p>Default value: <code>false</code>
748
<p>When <code>dotdistrib</code> is <code>true</code>, an expression <code>A.(B + C)</code> simplifies to <code>A.B + A.C</code>.
753
<dt><u>Option variable:</u> <b>dotexptsimp</b>
754
<a name="IDX778"></a>
756
<dd><p>Default value: <code>true</code>
758
<p>When <code>dotexptsimp</code> is <code>true</code>, an expression <code>A.A</code> simplifies to <code>A^^2</code>.
763
<dt><u>Option variable:</u> <b>dotident</b>
764
<a name="IDX779"></a>
766
<dd><p>Default value: 1
768
<p><code>dotident</code> is the value returned by <code>X^^0</code>.
773
<dt><u>Option variable:</u> <b>dotscrules</b>
774
<a name="IDX780"></a>
776
<dd><p>Default value: <code>false</code>
778
<p>When <code>dotscrules</code> is <code>true</code>, an expression <code>A.SC</code> or <code>SC.A</code> simplifies
779
to <code>SC*A</code> and <code>A.(SC*B)</code> simplifies to <code>SC*(A.B)</code>.
784
<dt><u>Function:</u> <b>echelon</b><i> (<var>M</var>)</i>
785
<a name="IDX781"></a>
787
<dd><p>Returns the echelon form of the matrix <var>M</var>,
788
as produced by Gaussian elimination.
789
The echelon form is computed from <var>M</var>
790
by elementary row operations such that the first
791
non-zero element in each row in the resulting matrix is one and the
792
column elements under the first one in each row are all zero.
794
<p><code>triangularize</code> also carries out Gaussian elimination,
795
but it does not normalize the leading non-zero element in each row.
797
<p><code>lu_factor</code> and <code>cholesky</code> are other functions which yield triangularized matrices.
799
<table><tr><td> </td><td><pre class="example">(%i1) M: matrix ([3, 7, aa, bb], [-1, 8, 5, 2], [9, 2, 11, 4]);
813
[ 0 0 1 ----------- ]
815
</pre></td></tr></table>
819
<dt><u>Function:</u> <b>eigenvalues</b><i> (<var>M</var>)</i>
820
<a name="IDX782"></a>
822
<dt><u>Function:</u> <b>eivals</b><i> (<var>M</var>)</i>
823
<a name="IDX783"></a>
825
<dd><p>Returns a list of two lists containing the eigenvalues of the matrix <var>M</var>.
826
The first sublist of the return value is the list of eigenvalues of the
827
matrix, and the second sublist is the list of the
828
multiplicities of the eigenvalues in the corresponding order.
830
<p><code>eivals</code> is a synonym for <code>eigenvalues</code>.
832
<p><code>eigenvalues</code> calls the function <code>solve</code> to find the roots of the
833
characteristic polynomial of the matrix.
834
Sometimes <code>solve</code> may not be able to find the roots of the polynomial;
835
in that case some other functions in this
836
package (except <code>innerproduct</code>, <code>unitvector</code>, <code>columnvector</code> and
837
<code>gramschmidt</code>) will not work.
839
<p>In some cases the eigenvalues found by <code>solve</code> may be complicated expressions.
840
(This may happen when <code>solve</code> returns a not-so-obviously real expression
841
for an eigenvalue which is known to be real.)
842
It may be possible to simplify the eigenvalues using some other functions.
844
<p>The package <code>eigen.mac</code> is loaded automatically when
845
<code>eigenvalues</code> or <code>eigenvectors</code> is referenced.
846
If <code>eigen.mac</code> is not already loaded,
847
<code>load ("eigen")</code> loads it.
848
After loading, all functions and variables in the package are available.
853
<dt><u>Function:</u> <b>eigenvectors</b><i> (<var>M</var>)</i>
854
<a name="IDX784"></a>
856
<dt><u>Function:</u> <b>eivects</b><i> (<var>M</var>)</i>
857
<a name="IDX785"></a>
859
<dd><p>takes a matrix <var>M</var> as its argument and returns a list
860
of lists the first sublist of which is the output of <code>eigenvalues</code>
861
and the other sublists of which are the eigenvectors of the
862
matrix corresponding to those eigenvalues respectively.
863
The calculated eigenvectors and the unit eigenvectors of the matrix are the
864
right eigenvectors and the right unit eigenvectors respectively.
866
<p><code>eivects</code> is a synonym for <code>eigenvectors</code>.
868
<p>The package <code>eigen.mac</code> is loaded automatically when
869
<code>eigenvalues</code> or <code>eigenvectors</code> is referenced.
870
If <code>eigen.mac</code> is not already loaded,
871
<code>load ("eigen")</code> loads it.
872
After loading, all functions and variables in the package are available.
874
<p>The flags that affect this function are:
876
<p><code>nondiagonalizable</code> is set to <code>true</code> or <code>false</code> depending on
877
whether the matrix is nondiagonalizable or diagonalizable after
878
<code>eigenvectors</code> returns.
880
<p><code>hermitianmatrix</code> when <code>true</code>, causes the degenerate
881
eigenvectors of the Hermitian matrix to be orthogonalized using the
882
Gram-Schmidt algorithm.
884
<p><code>knowneigvals</code> when <code>true</code> causes the <code>eigen</code> package to assume the
885
eigenvalues of the matrix are known to the user and stored under the
886
global name <code>listeigvals</code>. <code>listeigvals</code> should be set to a list similar
887
to the output <code>eigenvalues</code>.
889
<p>The function <code>algsys</code> is used here to solve for the eigenvectors. Sometimes if the
890
eigenvalues are messy, <code>algsys</code> may not be able to find a solution.
891
In some cases, it may be possible to simplify the eigenvalues by
892
first finding them using <code>eigenvalues</code> command and then using other functions
893
to reduce them to something simpler.
894
Following simplification, <code>eigenvectors</code> can be called again
895
with the <code>knowneigvals</code> flag set to <code>true</code>.
900
<dt><u>Function:</u> <b>ematrix</b><i> (<var>m</var>, <var>n</var>, <var>x</var>, <var>i</var>, <var>j</var>)</i>
901
<a name="IDX786"></a>
903
<dd><p>Returns an <var>m</var> by <var>n</var> matrix, all elements of which
904
are zero except for the <code>[<var>i</var>, <var>j</var>]</code> element which is <var>x</var>.
909
<dt><u>Function:</u> <b>entermatrix</b><i> (<var>m</var>, <var>n</var>)</i>
910
<a name="IDX787"></a>
912
<dd><p>Returns an <var>m</var> by <var>n</var> matrix, reading the elements interactively.
914
<p>If <var>n</var> is equal to <var>m</var>,
915
Maxima prompts for the type of the matrix (diagonal, symmetric, antisymmetric, or general)
916
and for each element.
917
Each response is terminated by a semicolon <code>;</code> or dollar sign <code>$</code>.
919
<p>If <var>n</var> is not equal to <var>m</var>,
920
Maxima prompts for each element.
922
<p>The elements may be any expressions, which are evaluated.
923
<code>entermatrix</code> evaluates its arguments.
925
<table><tr><td> </td><td><pre class="example">(%i1) n: 3$
926
(%i2) m: entermatrix (n, n)$
928
Is the matrix 1. Diagonal 2. Symmetric 3. Antisymmetric 4. General
929
Answer 1, 2, 3 or 4 :
948
</pre></td></tr></table>
952
<dt><u>Function:</u> <b>genmatrix</b><i> (<var>a</var>, <var>i_2</var>, <var>j_2</var>, <var>i_1</var>, <var>j_1</var>)</i>
953
<a name="IDX788"></a>
955
<dt><u>Function:</u> <b>genmatrix</b><i> (<var>a</var>, <var>i_2</var>, <var>j_2</var>, <var>i_1</var>)</i>
956
<a name="IDX789"></a>
958
<dt><u>Function:</u> <b>genmatrix</b><i> (<var>a</var>, <var>i_2</var>, <var>j_2</var>)</i>
959
<a name="IDX790"></a>
961
<dd><p>Returns a matrix generated from <var>a</var>,
962
taking element <code><var>a</var>[<var>i_1</var>,<var>j_1</var>]</code>
963
as the upper-left element and <code><var>a</var>[<var>i_2</var>,<var>j_2</var>]</code>
964
as the lower-right element of the matrix.
965
Here <var>a</var> is a declared array (created by <code>array</code> but not by <code>make_array</code>)
966
or an undeclared array,
967
or an array function,
968
or a lambda expression of two arguments.
969
(An array function is created like other functions with <code>:=</code> or <code>define</code>,
970
but arguments are enclosed in square brackets instead of parentheses.)
972
<p>If <var>j_1</var> is omitted, it is assumed equal to <var>i_1</var>.
973
If both <var>j_1</var> and <var>i_1</var> are omitted, both are assumed equal to 1.
975
<p>If a selected element <code>i,j</code> of the array is undefined,
976
the matrix will contain a symbolic element <code><var>a</var>[i,j]</code>.
980
<table><tr><td> </td><td><pre class="example">(%i1) h [i, j] := 1 / (i + j - 1);
984
(%i2) genmatrix (h, 3, 3);
996
(%i3) array (a, fixnum, 2, 2);
1000
(%i5) a [2, 2] : %pi;
1002
(%i6) genmatrix (a, 2, 2);
1006
(%i7) genmatrix (lambda ([i, j], j - i), 3, 3);
1012
(%i8) genmatrix (B, 2, 2);
1018
</pre></td></tr></table>
1022
<dt><u>Function:</u> <b>gramschmidt</b><i> (<var>x</var>)</i>
1023
<a name="IDX791"></a>
1025
<dt><u>Function:</u> <b>gschmit</b><i> (<var>x</var>)</i>
1026
<a name="IDX792"></a>
1028
<dd><p>Carries out the Gram-Schmidt orthogonalization algorithm on <var>x</var>,
1029
which is either a matrix or a list of lists.
1030
<var>x</var> is not modified by <code>gramschmidt</code>.
1032
<p>If <var>x</var> is a matrix, the algorithm is applied to the rows of <var>x</var>.
1033
If <var>x</var> is a list of lists, the algorithm is applied to the sublists,
1034
which must have equal numbers of elements.
1036
the return value is a list of lists, the sublists of which are orthogonal
1037
and span the same space as <var>x</var>.
1038
If the dimension of the span of <var>x</var> is less than the number of rows or sublists,
1039
some sublists of the return value are zero.
1041
<p><code>factor</code> is called at each stage of the algorithm to simplify intermediate results.
1042
As a consequence, the return value may contain factored integers.
1044
<p><code>gschmit</code> (note spelling) is a synonym for <code>gramschmidt</code>.
1046
<p><code>load ("eigen")</code> loads this function.
1050
<table><tr><td> </td><td><pre class="example">(%i1) load ("eigen")$
1051
Warning - you are redefining the Macsyma function eigenvalues
1052
Warning - you are redefining the Macsyma function eigenvectors
1053
(%i2) x: matrix ([1, 2, 3], [9, 18, 30], [12, 48, 60]);
1059
(%i3) y: gramschmidt (x);
1062
(%o3) [[1, 2, 3], [- ---, - --, ---], [- ----, ----, 0]]
1064
(%i4) i: innerproduct$
1065
(%i5) [i (y[1], y[2]), i (y[2], y[3]), i (y[3], y[1])];
1067
</pre></td></tr></table>
1071
<dt><u>Function:</u> <b>hach</b><i> (<var>a</var>, <var>b</var>, <var>m</var>, <var>n</var>, <var>l</var>)</i>
1072
<a name="IDX793"></a>
1074
<dd><p><code>hach</code> is an implementation of Hacijan's linear programming algorithm.
1076
<p><code>load ("kach")</code> loads this function.
1077
<code>demo ("kach")</code> executes a demonstration of this function.
1082
<dt><u>Function:</u> <b>ident</b><i> (<var>n</var>)</i>
1083
<a name="IDX794"></a>
1085
<dd><p>Returns an <var>n</var> by <var>n</var> identity matrix.
1090
<dt><u>Function:</u> <b>innerproduct</b><i> (<var>x</var>, <var>y</var>)</i>
1091
<a name="IDX795"></a>
1093
<dt><u>Function:</u> <b>inprod</b><i> (<var>x</var>, <var>y</var>)</i>
1094
<a name="IDX796"></a>
1096
<dd><p>Returns the inner product (also called the scalar product or dot product) of <var>x</var> and <var>y</var>,
1097
which are lists of equal length, or both 1-column or 1-row matrices of equal length.
1098
The return value is <code>conjugate (x) . y</code>,
1099
where <code>.</code> is the noncommutative multiplication operator.
1101
<p><code>load ("eigen")</code> loads this function.
1103
<p><code>inprod</code> is a synonym for <code>innerproduct</code>.
1108
<dt><u>Function:</u> <b>invert</b><i> (<var>M</var>)</i>
1109
<a name="IDX797"></a>
1111
<dd><p>Returns the inverse of the matrix <var>M</var>.
1112
The inverse is computed by the adjoint method.
1114
<p>This allows a user to compute the inverse of a matrix with
1115
bfloat entries or polynomials with floating pt. coefficients without
1116
converting to cre-form.
1118
<p>Cofactors are computed by the <code>determinant</code> function,
1119
so if <code>ratmx</code> is <code>false</code> the inverse is computed
1120
without changing the representation of the elements.
1123
implementation is inefficient for matrices of high order.
1125
<p>When <code>detout</code> is <code>true</code>, the determinant is factored out of the
1128
<p>The elements of the inverse are not automatically expanded.
1129
If <var>M</var> has polynomial elements, better appearing output can be
1130
generated by <code>expand (invert (m)), detout</code>.
1131
If it is desirable to then
1132
divide through by the determinant this can be accomplished by <code>xthru (%)</code>
1133
or alternatively from scratch by
1135
<table><tr><td> </td><td><pre class="example">expand (adjoint (m)) / expand (determinant (m))
1136
invert (m) := adjoint (m) / determinant (m)
1137
</pre></td></tr></table>
1138
<p>See <code>^^</code> (noncommutative exponent) for another method of inverting a matrix.
1143
<dt><u>Option variable:</u> <b>lmxchar</b>
1144
<a name="IDX798"></a>
1146
<dd><p>Default value: <code>[</code>
1148
<p><code>lmxchar</code> is the character displayed as the left
1149
delimiter of a matrix.
1150
See also <code>rmxchar</code>.
1154
<table><tr><td> </td><td><pre class="example">(%i1) lmxchar: "|"$
1155
(%i2) matrix ([a, b, c], [d, e, f], [g, h, i]);
1161
</pre></td></tr></table>
1165
<dt><u>Function:</u> <b>matrix</b><i> (<var>row_1</var>, ..., <var>row_n</var>)</i>
1166
<a name="IDX799"></a>
1168
<dd><p>Returns a rectangular matrix which has the rows <var>row_1</var>, ..., <var>row_n</var>.
1169
Each row is a list of expressions.
1170
All rows must be the same length.
1172
<p>The operations <code>+</code> (addition), <code>-</code> (subtraction), <code>*</code> (multiplication),
1173
and <code>/</code> (division), are carried out element by element
1174
when the operands are two matrices, a scalar and a matrix, or a matrix and a scalar.
1175
The operation <code>^</code> (exponentiation, equivalently <code>**</code>)
1176
is carried out element by element
1177
if the operands are a scalar and a matrix or a matrix and a scalar,
1178
but not if the operands are two matrices.
1179
All operations are normally carried out in full,
1180
including <code>.</code> (noncommutative multiplication).
1182
<p>Matrix multiplication is represented by the noncommutative multiplication operator <code>.</code>.
1183
The corresponding noncommutative exponentiation operator is <code>^^</code>.
1184
For a matrix <code><var>A</var></code>, <code><var>A</var>.<var>A</var> = <var>A</var>^^2</code> and
1185
<code><var>A</var>^^-1</code> is the inverse of <var>A</var>, if it exists.
1187
<p>There are switches for controlling simplification of expressions
1188
involving dot and matrix-list operations.
1190
<code>doallmxops</code>, <code>domxexpt</code>
1191
<code>domxmxops</code>, <code>doscmxops</code>, and <code>doscmxplus</code>.
1193
<p>There are additional options which are related to matrices. These are:
1194
<code>lmxchar</code>, <code>rmxchar</code>, <code>ratmx</code>, <code>listarith</code>, <code>detout</code>,
1195
<code>scalarmatrix</code>,
1196
and <code>sparse</code>.
1198
<p>There are a number of
1199
functions which take matrices as arguments or yield matrices as return values.
1200
See <code>eigenvalues</code>, <code>eigenvectors</code>,
1201
<code>determinant</code>,
1202
<code>charpoly</code>, <code>genmatrix</code>, <code>addcol</code>, <code>addrow</code>,
1203
<code>copymatrix</code>, <code>transpose</code>, <code>echelon</code>,
1204
and <code>rank</code>.
1210
Construction of matrices from lists.
1212
<table><tr><td> </td><td><pre class="example">(%i1) x: matrix ([17, 3], [-8, 11]);
1216
(%i2) y: matrix ([%pi, %e], [a, b]);
1220
</pre></td></tr></table><ul>
1222
Addition, element by element.
1224
<table><tr><td> </td><td><pre class="example">(%i3) x + y;
1228
</pre></td></tr></table><ul>
1230
Subtraction, element by element.
1232
<table><tr><td> </td><td><pre class="example">(%i4) x - y;
1236
</pre></td></tr></table><ul>
1238
Multiplication, element by element.
1240
<table><tr><td> </td><td><pre class="example">(%i5) x * y;
1244
</pre></td></tr></table><ul>
1246
Division, element by element.
1248
<table><tr><td> </td><td><pre class="example">(%i6) x / y;
1256
</pre></td></tr></table><ul>
1258
Matrix to a scalar exponent, element by element.
1260
<table><tr><td> </td><td><pre class="example">(%i7) x ^ 3;
1264
</pre></td></tr></table><ul>
1266
Scalar base to a matrix exponent, element by element.
1268
<table><tr><td> </td><td><pre class="example">(%i8) exp(y);
1274
</pre></td></tr></table><ul>
1276
Matrix base to a matrix exponent. This is not carried out element by element.
1278
<table><tr><td> </td><td><pre class="example">(%i9) x ^ y;
1285
</pre></td></tr></table><ul>
1287
Noncommutative matrix multiplication.
1289
<table><tr><td> </td><td><pre class="example">(%i10) x . y;
1290
[ 3 a + 17 %pi 3 b + 17 %e ]
1292
[ 11 a - 8 %pi 11 b - 8 %e ]
1294
[ 17 %pi - 8 %e 3 %pi + 11 %e ]
1296
[ 17 a - 8 b 11 b + 3 a ]
1297
</pre></td></tr></table><ul>
1299
Noncommutative matrix exponentiation.
1300
A scalar base <var>b</var> to a matrix power <var>M</var>
1301
is carried out element by element and so <code>b^^m</code> is the same as <code>b^m</code>.
1303
<table><tr><td> </td><td><pre class="example">(%i12) x ^^ 3;
1313
</pre></td></tr></table><ul>
1315
A matrix raised to a -1 exponent with noncommutative exponentiation is the matrix inverse,
1318
<table><tr><td> </td><td><pre class="example">(%i14) x ^^ -1;
1326
(%i15) x . (x ^^ -1);
1330
</pre></td></tr></table>
1334
<dt><u>Function:</u> <b>matrixmap</b><i> (<var>f</var>, <var>M</var>)</i>
1335
<a name="IDX800"></a>
1337
<dd><p>Returns a matrix with element <code>i,j</code> equal to <code><var>f</var>(<var>M</var>[i,j])</code>.
1339
<p>See also <code>map</code>, <code>fullmap</code>, <code>fullmapl</code>, and <code>apply</code>.
1344
<dt><u>Function:</u> <b>matrixp</b><i> (<var>expr</var>)</i>
1345
<a name="IDX801"></a>
1347
<dd><p>Returns <code>true</code> if <var>expr</var> is a matrix, otherwise <code>false</code>.
1352
<dt><u>Option variable:</u> <b>matrix_element_add</b>
1353
<a name="IDX802"></a>
1355
<dd><p>Default value: <code>+</code>
1357
<p><code>matrix_element_add</code> is the operation
1358
invoked in place of addition in a matrix multiplication.
1359
<code>matrix_element_add</code> can be assigned any n-ary operator
1360
(that is, a function which handles any number of arguments).
1361
The assigned value may be the name of an operator enclosed in quote marks,
1362
the name of a function,
1363
or a lambda expression.
1365
<p>See also <code>matrix_element_mult</code> and <code>matrix_element_transpose</code>.
1369
<table><tr><td> </td><td><pre class="example">(%i1) matrix_element_add: "*"$
1370
(%i2) matrix_element_mult: "^"$
1371
(%i3) aa: matrix ([a, b, c], [d, e, f]);
1375
(%i4) bb: matrix ([u, v, w], [x, y, z]);
1379
(%i5) aa . transpose (bb);
1385
</pre></td></tr></table>
1389
<dt><u>Option variable:</u> <b>matrix_element_mult</b>
1390
<a name="IDX803"></a>
1392
<dd><p>Default value: <code>*</code>
1394
<p><code>matrix_element_mult</code> is the operation
1395
invoked in place of multiplication in a matrix multiplication.
1396
<code>matrix_element_mult</code> can be assigned any binary operator.
1397
The assigned value may be the name of an operator enclosed in quote marks,
1398
the name of a function,
1399
or a lambda expression.
1401
<p>The dot operator <code>.</code> is a useful choice in some contexts.
1403
<p>See also <code>matrix_element_add</code> and <code>matrix_element_transpose</code>.
1407
<table><tr><td> </td><td><pre class="example">(%i1) matrix_element_add: lambda ([[x]], sqrt (apply ("+", x)))$
1408
(%i2) matrix_element_mult: lambda ([x, y], (x - y)^2)$
1409
(%i3) [a, b, c] . [x, y, z];
1411
(%o3) sqrt((c - z) + (b - y) + (a - x) )
1412
(%i4) aa: matrix ([a, b, c], [d, e, f]);
1416
(%i5) bb: matrix ([u, v, w], [x, y, z]);
1420
(%i6) aa . transpose (bb);
1422
[ sqrt((c - w) + (b - v) + (a - u) ) ]
1425
[ sqrt((f - w) + (e - v) + (d - u) ) ]
1428
[ sqrt((c - z) + (b - y) + (a - x) ) ]
1431
[ sqrt((f - z) + (e - y) + (d - x) ) ]
1432
</pre></td></tr></table>
1436
<dt><u>Option variable:</u> <b>matrix_element_transpose</b>
1437
<a name="IDX804"></a>
1439
<dd><p>Default value: <code>false</code>
1441
<p><code>matrix_element_transpose</code> is the operation
1442
applied to each element of a matrix when it is transposed.
1443
<code>matrix_element_mult</code> can be assigned any unary operator.
1444
The assigned value may be the name of an operator enclosed in quote marks,
1445
the name of a function,
1446
or a lambda expression.
1448
<p>When <code>matrix_element_transpose</code> equals <code>transpose</code>,
1449
the <code>transpose</code> function is applied to every element.
1450
When <code>matrix_element_transpose</code> equals <code>nonscalars</code>,
1451
the <code>transpose</code> function is applied to every nonscalar element.
1452
If some element is an atom, the <code>nonscalars</code> option applies
1453
<code>transpose</code> only if the atom is declared nonscalar,
1454
while the <code>transpose</code> option always applies <code>transpose</code>.
1456
<p>The default value, <code>false</code>, means no operation is applied.
1458
<p>See also <code>matrix_element_add</code> and <code>matrix_element_mult</code>.
1462
<table><tr><td> </td><td><pre class="example">(%i1) declare (a, nonscalar)$
1463
(%i2) transpose ([a, b]);
1467
(%i3) matrix_element_transpose: nonscalars$
1468
(%i4) transpose ([a, b]);
1472
(%i5) matrix_element_transpose: transpose$
1473
(%i6) transpose ([a, b]);
1477
(%i7) matrix_element_transpose: lambda ([x], realpart(x) - %i*imagpart(x))$
1478
(%i8) m: matrix ([1 + 5*%i, 3 - 2*%i], [7*%i, 11]);
1479
[ 5 %i + 1 3 - 2 %i ]
1482
(%i9) transpose (m);
1486
</pre></td></tr></table>
1490
<dt><u>Function:</u> <b>mattrace</b><i> (<var>M</var>)</i>
1491
<a name="IDX805"></a>
1493
<dd><p>Returns the trace (that is, the sum of the elements on the main diagonal) of
1494
the square matrix <var>M</var>.
1496
<p><code>mattrace</code> is called by <code>ncharpoly</code>,
1497
an alternative to Maxima's <code>charpoly</code>.
1499
<p><code>load ("nchrpl")</code> loads this function.
1504
<dt><u>Function:</u> <b>minor</b><i> (<var>M</var>, <var>i</var>, <var>j</var>)</i>
1505
<a name="IDX806"></a>
1507
<dd><p>Returns the <var>i</var>, <var>j</var> minor of the matrix <var>M</var>. That is, <var>M</var>
1508
with row <var>i</var> and column <var>j</var> removed.
1513
<dt><u>Function:</u> <b>ncexpt</b><i> (<var>a</var>, <var>b</var>)</i>
1514
<a name="IDX807"></a>
1516
<dd><p>If a non-commutative exponential expression is too
1517
wide to be displayed as <code><var>a</var>^^<var>b</var></code> it appears as <code>ncexpt (<var>a</var>,<var>b</var>)</code>.
1519
<p><code>ncexpt</code> is not the name of a function or operator;
1520
the name only appears in output, and is not recognized in input.
1525
<dt><u>Function:</u> <b>ncharpoly</b><i> (<var>M</var>, <var>x</var>)</i>
1526
<a name="IDX808"></a>
1528
<dd><p>Returns the characteristic polynomial of the matrix <var>M</var>
1529
with respect to <var>x</var>. This is an alternative to Maxima's <code>charpoly</code>.
1531
<p><code>ncharpoly</code> works by computing traces of powers of the given matrix,
1532
which are known to be equal to sums of powers of the roots of the
1533
characteristic polynomial. From these quantities the symmetric
1534
functions of the roots can be calculated, which are nothing more than
1535
the coefficients of the characteristic polynomial. <code>charpoly</code> works by
1536
forming the determinant of <code><var>x</var> * ident [n] - a</code>. Thus <code>ncharpoly</code> wins,
1537
for example, in the case of large dense matrices filled with integers,
1538
since it avoids polynomial arithmetic altogether.
1540
<p><code>load ("nchrpl")</code> loads this file.
1545
<dt><u>Function:</u> <b>newdet</b><i> (<var>M</var>, <var>n</var>)</i>
1546
<a name="IDX809"></a>
1548
<dd><p>Computes the determinant of the matrix or array <var>M</var> by the
1549
Johnson-Gentleman tree minor algorithm.
1550
The argument <var>n</var> is the order; it is optional if <var>M</var> is a matrix.
1555
<dt><u>Declaration:</u> <b>nonscalar</b>
1556
<a name="IDX810"></a>
1558
<dd><p>Makes atoms behave as does a list or matrix with respect to
1564
<dt><u>Function:</u> <b>nonscalarp</b><i> (<var>expr</var>)</i>
1565
<a name="IDX811"></a>
1567
<dd><p>Returns <code>true</code> if <var>expr</var> is a non-scalar, i.e., it contains
1568
atoms declared as non-scalars, lists, or matrices.
1573
<dt><u>Function:</u> <b>permanent</b><i> (<var>M</var>, <var>n</var>)</i>
1574
<a name="IDX812"></a>
1576
<dd><p>Computes the permanent of the matrix <var>M</var>. A permanent
1577
is like a determinant but with no sign changes.
1582
<dt><u>Function:</u> <b>rank</b><i> (<var>M</var>)</i>
1583
<a name="IDX813"></a>
1585
<dd><p>Computes the rank of the matrix <var>M</var>. That is, the order of the
1586
largest non-singular subdeterminant of <var>M</var>.
1588
<p><var>rank</var> may return the
1589
wrong answer if it cannot determine that a matrix element that is
1590
equivalent to zero is indeed so.
1595
<dt><u>Option variable:</u> <b>ratmx</b>
1596
<a name="IDX814"></a>
1598
<dd><p>Default value: <code>false</code>
1600
<p>When <code>ratmx</code> is <code>false</code>, determinant and matrix
1601
addition, subtraction, and multiplication are performed in the
1602
representation of the matrix elements and cause the result of
1603
matrix inversion to be left in general representation.
1605
<p>When <code>ratmx</code> is <code>true</code>,
1606
the 4 operations mentioned above are performed in CRE form and the
1607
result of matrix inverse is in CRE form. Note that this may
1608
cause the elements to be expanded (depending on the setting of <code>ratfac</code>)
1609
which might not always be desired.
1614
<dt><u>Function:</u> <b>row</b><i> (<var>M</var>, <var>i</var>)</i>
1615
<a name="IDX815"></a>
1617
<dd><p>Returns the <var>i</var>'th row of the matrix <var>M</var>.
1618
The return value is a matrix.
1623
<dt><u>Option variable:</u> <b>scalarmatrixp</b>
1624
<a name="IDX816"></a>
1626
<dd><p>Default value: <code>true</code>
1628
<p>When <code>scalarmatrixp</code> is <code>true</code>, then whenever a 1 x 1 matrix
1629
is produced as a result of computing the dot product of matrices it
1630
is simplified to a scalar, namely the sole element of the matrix.
1632
<p>When <code>scalarmatrixp</code> is <code>all</code>,
1633
then all 1 x 1 matrices are simplified to scalars.
1635
<p>When <code>scalarmatrixp</code> is <code>false</code>, 1 x 1 matrices are not simplified to scalars.
1640
<dt><u>Function:</u> <b>scalefactors</b><i> (<var>coordinatetransform</var>)</i>
1641
<a name="IDX817"></a>
1643
<dd><p>Here coordinatetransform
1644
evaluates to the form [[expression1, expression2, ...],
1645
indeterminate1, indeterminat2, ...], where indeterminate1,
1646
indeterminate2, etc. are the curvilinear coordinate variables and
1647
where a set of rectangular Cartesian components is given in terms of
1648
the curvilinear coordinates by [expression1, expression2, ...].
1649
<code>coordinates</code> is set to the vector [indeterminate1, indeterminate2,...],
1650
and <code>dimension</code> is set to the length of this vector. SF[1], SF[2],
1651
..., SF[DIMENSION] are set to the coordinate scale factors, and <code>sfprod</code>
1652
is set to the product of these scale factors. Initially, <code>coordinates</code>
1653
is [X, Y, Z], <code>dimension</code> is 3, and SF[1]=SF[2]=SF[3]=SFPROD=1,
1654
corresponding to 3-dimensional rectangular Cartesian coordinates.
1655
To expand an expression into physical components in the current
1656
coordinate system, there is a function with usage of the form
1661
<dt><u>Function:</u> <b>setelmx</b><i> (<var>x</var>, <var>i</var>, <var>j</var>, <var>M</var>)</i>
1662
<a name="IDX818"></a>
1664
<dd><p>Assigns <var>x</var> to the (<var>i</var>, <var>j</var>)'th element of the matrix <var>M</var>,
1665
and returns the altered matrix.
1667
<p><code><var>M</var> [<var>i</var>, <var>j</var>]: <var>x</var></code> has the same effect,
1668
but returns <var>x</var> instead of <var>M</var>.
1673
<dt><u>Function:</u> <b>similaritytransform</b><i> (<var>M</var>)</i>
1674
<a name="IDX819"></a>
1676
<dt><u>Function:</u> <b>simtran</b><i> (<var>M</var>)</i>
1677
<a name="IDX820"></a>
1679
<dd><p><code>similaritytransform</code> computes a similarity transform of the matrix <code>M</code>.
1680
It returns a list which is the output of the
1681
<code>uniteigenvectors</code> command. In addition if the flag <code>nondiagonalizable</code>
1682
is <code>false</code> two global matrices <code>leftmatrix</code> and <code>rightmatrix</code> are computed.
1683
These matrices have the property that
1684
<code>leftmatrix . <var>M</var> . rightmatrix</code> is a diagonal matrix with the eigenvalues
1685
of <var>M</var> on the diagonal. If <code>nondiagonalizable</code> is <code>true</code> the left and right
1686
matrices are not computed.
1688
<p>If the flag <code>hermitianmatrix</code> is <code>true</code>
1689
then <code>leftmatrix</code> is the complex conjugate of the transpose of
1690
<code>rightmatrix</code>. Otherwise <code>leftmatrix</code> is the inverse of <code>rightmatrix</code>.
1692
<p><code>rightmatrix</code> is the matrix the columns of which are the unit
1693
eigenvectors of <var>M</var>. The other flags (see <code>eigenvalues</code> and
1694
<code>eigenvectors</code>) have the same effects since
1695
<code>similaritytransform</code> calls the other functions in the package in order
1696
to be able to form <code>rightmatrix</code>.
1698
<p><code>load ("eigen")</code> loads this function.
1700
<p><code>simtran</code> is a synonym for <code>similaritytransform</code>.
1705
<dt><u>Option variable:</u> <b>sparse</b>
1706
<a name="IDX821"></a>
1708
<dd><p>Default value: <code>false</code>
1710
<p>When <code>sparse</code> is <code>true</code>, and if <code>ratmx</code> is <code>true</code>, then <code>determinant</code>
1711
will use special routines for computing sparse determinants.
1716
<dt><u>Function:</u> <b>submatrix</b><i> (<var>i_1</var>, ..., <var>i_m</var>, <var>M</var>, <var>j_1</var>, ..., <var>j_n</var>)</i>
1717
<a name="IDX822"></a>
1719
<dt><u>Function:</u> <b>submatrix</b><i> (<var>i_1</var>, ..., <var>i_m</var>, <var>M</var>)</i>
1720
<a name="IDX823"></a>
1722
<dt><u>Function:</u> <b>submatrix</b><i> (<var>M</var>, <var>j_1</var>, ..., <var>j_n</var>)</i>
1723
<a name="IDX824"></a>
1725
<dd><p>Returns a new matrix composed of the
1726
matrix <var>M</var> with rows <var>i_1</var>, ..., <var>i_m</var> deleted, and columns <var>j_1</var>, ..., <var>j_n</var> deleted.
1731
<dt><u>Function:</u> <b>transpose</b><i> (<var>M</var>)</i>
1732
<a name="IDX825"></a>
1734
<dd><p>Returns the transpose of <var>M</var>.
1736
<p>If <var>M</var> is a matrix, the return value is another matrix <var>N</var>
1737
such that <code>N[i,j] = M[j,i]</code>.
1739
<p>Otherwise <var>M</var> is a list, and the return value is a matrix <var>N</var>
1740
of <code>length (m)</code> rows and 1 column, such that <code>N[i,1] = M[i]</code>.
1745
<dt><u>Function:</u> <b>triangularize</b><i> (<var>M</var>)</i>
1746
<a name="IDX826"></a>
1748
<dd><p>Returns the upper triangular form of the matrix <code>M</code>,
1749
as produced by Gaussian elimination.
1750
The return value is the same as <code>echelon</code>,
1751
except that the leading nonzero coefficient in each row is not normalized to 1.
1753
<p><code>lu_factor</code> and <code>cholesky</code> are other functions which yield triangularized matrices.
1755
<table><tr><td> </td><td><pre class="example">(%i1) M: matrix ([3, 7, aa, bb], [-1, 8, 5, 2], [9, 2, 11, 4]);
1761
(%i2) triangularize (M);
1764
(%o2) [ 0 - 74 - 56 - 22 ]
1766
[ 0 0 626 - 74 aa 238 - 74 bb ]
1767
</pre></td></tr></table>
1771
<dt><u>Function:</u> <b>uniteigenvectors</b><i> (<var>M</var>)</i>
1772
<a name="IDX827"></a>
1774
<dt><u>Function:</u> <b>ueivects</b><i> (<var>M</var>)</i>
1775
<a name="IDX828"></a>
1777
<dd><p>Computes unit eigenvectors of the matrix <var>M</var>.
1778
The return value is a list of lists, the first sublist of which is the
1779
output of the <code>eigenvalues</code> command, and the other sublists of which are
1780
the unit eigenvectors of the matrix corresponding to those eigenvalues
1783
<p>The flags mentioned in the description of the
1784
<code>eigenvectors</code> command have the same effects in this one as well.
1786
<p>When <code>knowneigvects</code> is <code>true</code>, the <code>eigen</code> package assumes
1787
that the eigenvectors of the matrix are known to the user and are
1788
stored under the global name <code>listeigvects</code>. <code>listeigvects</code> should be set
1789
to a list similar to the output of the <code>eigenvectors</code> command.
1791
<p>If <code>knowneigvects</code> is set to <code>true</code> and the list of eigenvectors is given the
1792
setting of the flag <code>nondiagonalizable</code> may not be correct. If that is
1793
the case please set it to the correct value. The author assumes that
1794
the user knows what he is doing and will not try to diagonalize a
1795
matrix the eigenvectors of which do not span the vector space of the
1796
appropriate dimension.
1798
<p><code>load ("eigen")</code> loads this function.
1800
<p><code>ueivects</code> is a synonym for <code>uniteigenvectors</code>.
1805
<dt><u>Function:</u> <b>unitvector</b><i> (<var>x</var>)</i>
1806
<a name="IDX829"></a>
1808
<dt><u>Function:</u> <b>uvect</b><i> (<var>x</var>)</i>
1809
<a name="IDX830"></a>
1811
<dd><p>Returns <em><var>x</var>/norm(<var>x</var>)</em>;
1812
this is a unit vector in the same direction as <var>x</var>.
1814
<p><code>load ("eigen")</code> loads this function.
1816
<p><code>uvect</code> is a synonym for <code>unitvector</code>.
1821
<dt><u>Function:</u> <b>vectorsimp</b><i> (<var>expr</var>)</i>
1822
<a name="IDX831"></a>
1824
<dd><p>Applies simplifications and expansions according
1825
to the following global flags:
1827
<p><code>expandall</code>, <code>expanddot</code>, <code>expanddotplus</code>, <code>expandcross</code>, <code>expandcrossplus</code>,
1828
<code>expandcrosscross</code>, <code>expandgrad</code>, <code>expandgradplus</code>, <code>expandgradprod</code>,
1829
<code>expanddiv</code>, <code>expanddivplus</code>, <code>expanddivprod</code>, <code>expandcurl</code>, <code>expandcurlplus</code>,
1830
<code>expandcurlcurl</code>, <code>expandlaplacian</code>, <code>expandlaplacianplus</code>,
1831
and <code>expandlaplacianprod</code>.
1833
<p>All these flags have default value <code>false</code>. The <code>plus</code> suffix refers to
1834
employing additivity or distributivity. The <code>prod</code> suffix refers to the
1835
expansion for an operand that is any kind of product.
1837
<dl compact="compact">
1838
<dt> <code>expandcrosscross</code></dt>
1839
<dd><p>Simplifies <em>p ~ (q ~ r)</em> to <em>(p . r)*q - (p . q)*r</em>.
1841
<dt> <code>expandcurlcurl</code></dt>
1842
<dd><p>Simplifies <em>curl curl p</em> to <em>grad div p + div grad p</em>.
1844
<dt> <code>expandlaplaciantodivgrad</code></dt>
1845
<dd><p>Simplifies <em>laplacian p</em> to <em>div grad p</em>.
1847
<dt> <code>expandcross</code></dt>
1848
<dd><p>Enables <code>expandcrossplus</code> and <code>expandcrosscross</code>.
1850
<dt> <code>expandplus</code></dt>
1851
<dd><p>Enables <code>expanddotplus</code>, <code>expandcrossplus</code>, <code>expandgradplus</code>,
1852
<code>expanddivplus</code>, <code>expandcurlplus</code>, and <code>expandlaplacianplus</code>.
1854
<dt> <code>expandprod</code></dt>
1855
<dd><p>Enables <code>expandgradprod</code>, <code>expanddivprod</code>, and <code>expandlaplacianprod</code>.
1859
<p>These flags have all been declared <code>evflag</code>.
1865
<dt><u>Option variable:</u> <b>vect_cross</b>
1866
<a name="IDX832"></a>
1868
<dd><p>Default value: <code>false</code>
1870
<p>When <code>vect_cross</code> is <code>true</code>, it allows DIFF(X~Y,T) to work where
1871
~ is defined in SHARE;VECT (where VECT_CROSS is set to <code>true</code>, anyway.)
1876
<dt><u>Function:</u> <b>zeromatrix</b><i> (<var>m</var>, <var>n</var>)</i>
1877
<a name="IDX833"></a>
1879
<dd><p>Returns an <var>m</var> by <var>n</var> matrix, all elements of which are zero.
1884
<dt><u>Special symbol:</u> <b>[</b>
1885
<a name="IDX834"></a>
1887
<dt><u>Special symbol:</u> <b>]</b>
1888
<a name="IDX835"></a>
1890
<dd><p><code>[</code> and <code>]</code> mark the beginning and end, respectively, of a list.
1892
<p><code>[</code> and <code>]</code> also enclose the subscripts of
1893
a list, array, hash array, or array function.
1897
<table><tr><td> </td><td><pre class="example">(%i1) x: [a, b, c];
1901
(%i3) array (y, fixnum, 3);
1907
(%i6) z['foo]: 'bar;
1911
(%i8) g[k] := 1/(k^2+1);
1920
</pre></td></tr></table>
1924
<table cellpadding="1" cellspacing="1" border="0">
1925
<tr><td valign="middle" align="left">[<a href="#SEC85" title="Beginning of this chapter or previous chapter"> << </a>]</td>
1926
<td valign="middle" align="left">[<a href="maxima_27.html#SEC91" title="Next chapter"> >> </a>]</td>
1927
<td valign="middle" align="left"> </td>
1928
<td valign="middle" align="left"> </td>
1929
<td valign="middle" align="left"> </td>
1930
<td valign="middle" align="left"> </td>
1931
<td valign="middle" align="left"> </td>
1932
<td valign="middle" align="left">[<a href="maxima.html#SEC_Top" title="Cover (top) of document">Top</a>]</td>
1933
<td valign="middle" align="left">[<a href="maxima_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
1934
<td valign="middle" align="left">[<a href="maxima_72.html#SEC264" title="Index">Index</a>]</td>
1935
<td valign="middle" align="left">[<a href="maxima_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
1939
This document was generated by <em>Robert Dodier</em> on <em>September, 20 2006</em> using <a href="http://texi2html.cvshome.org/"><em>texi2html 1.76</em></a>.