2 * Functions and Variables for diag::
5 @node Functions and Variables for diag, , Package diag, Package diag
6 @section Functions and Variables for diag
10 @deffn {Function} diag (@var{lm})
11 Constructs a matrix that is the block sum of the elements of
12 @var{lm}. The elements of @var{lm} are assumed to be matrices; if an
13 element is scalar, it treated as a 1 by 1 matrix.
15 The resulting matrix will be square if each of the elements of
22 (%i2) a1:matrix([1,2,3],[0,4,5],[0,0,6])$
24 (%i3) a2:matrix([1,1],[1,0])$
26 (%i4) diag([a1,x,a2]);
38 (%i5) diag ([matrix([1,2]), 3]);
44 To use this function write first @code{load("diag")}.
46 @opencatbox{Categories:}
48 @category{Share packages}
49 @category{Package diag}
56 @deffn {Function} JF (@var{lambda},@var{n})
57 Returns the Jordan cell of order @var{n} with eigenvalue @var{lambda}.
79 To use this function write first @code{load("diag")}.
81 @opencatbox{Categories:}
82 @category{Package diag}
89 @deffn {Function} jordan (@var{mat})
90 Returns the Jordan form of matrix @var{mat}, encoded as a list in a
91 particular format. To get the corresponding matrix, call the function
92 @code{dispJordan} using the output of @code{jordan} as the argument.
94 The elements of the returned list are themselves lists. The first
95 element of each is an eigenvalue of @var{mat}. The remaining elements
96 are positive integers which are the lengths of the Jordan blocks for
97 this eigenvalue. These integers are listed in decreasing
98 order. Eigenvalues are not repeated.
100 The functions @code{dispJordan}, @code{minimalPoly} and
101 @code{ModeMatrix} expect the output of a call to @code{jordan} as an
102 argument. If you construct this argument by hand, rather than by
103 calling @code{jordan}, you must ensure that each eigenvalue only
104 appears once and that the block sizes are listed in decreasing order,
105 otherwise the functions might give incorrect answers.
110 @c A: matrix([2,0,0,0,0,0,0,0],
111 @c [1,2,0,0,0,0,0,0],
112 @c [-4,1,2,0,0,0,0,0],
113 @c [2,0,0,2,0,0,0,0],
114 @c [-7,2,0,0,2,0,0,0],
115 @c [9,0,-2,0,1,2,0,0],
116 @c [-34,7,1,-2,-1,1,2,0],
117 @c [145,-17,-16,3,9,-2,0,3])$
124 (%i2) A: matrix([2,0,0,0,0,0,0,0],
130 [-34,7,1,-2,-1,1,2,0],
131 [145,-17,-16,3,9,-2,0,3])$
135 (%o3) [[2, 3, 3, 1], [3, 1]]
137 (%i4) dispJordan (%);
155 To use this function write first @code{load("diag")}. See also @mref{dispJordan} and @mrefdot{minimalPoly}
157 @opencatbox{Categories:}
158 @category{Package diag}
165 @deffn {Function} dispJordan (@var{l})
166 Returns a matrix in Jordan canonical form (JCF) corresponding to the
167 list of eigenvalues and multiplicities given by @var{l}. This list
168 should be in the format given by the @mref{jordan} function. See
169 @mref{jordan} for details of this format.
175 (%i2) b1:matrix([0,0,1,1,1],
195 To use this function write first @code{load("diag")}. See also @mref{jordan} and @mrefdot{minimalPoly}
197 @opencatbox{Categories:}
198 @category{Package diag}
205 @deffn {Function} minimalPoly (@var{l})
206 Returns the minimal polynomial of the matrix whose Jordan form is
207 described by the list @var{l}. This list should be in the format given
208 by the @mref{jordan} function. See @mref{jordan} for details of this
215 (%i2) a:matrix([2,1,2,0],
221 (%o3) [[- 1, 1], [1, 3]]
222 (%i4) minimalPoly(%);
224 (%o4) (x - 1) (x + 1)
227 To use this function write first @code{load("diag")}. See also @mref{jordan} and @mrefdot{dispJordan}
229 @opencatbox{Categories:}
230 @category{Package diag}
236 @deffn {Function} ModeMatrix (@var{A}, [@var{jordan_info}])
237 Returns an invertible matrix @var{M} such that @math{(M^^-1).A.M} is
238 the Jordan form of @var{A}.
240 To calculate this, Maxima must find the Jordan form of @var{A}, which
241 might be quite computationally expensive. If that has already been
242 calculated by a previous call to @mref{jordan}, pass it as a second
243 argument, @var{jordan_info}. See @mref{jordan} for details of the
249 @c A: matrix([2,1,2,0], [-2,2,1,2], [-2,-1,-1,1], [3,1,2,-1])$
250 @c M: ModeMatrix (A);
251 @c is ((M^^-1) . A . M = dispJordan (jordan (A)));
255 (%i2) A: matrix([2,1,2,0], [-2,2,1,2], [-2,-1,-1,1], [3,1,2,-1])$
256 (%i3) M: ModeMatrix (A);
271 (%i4) is ((M^^-1) . A . M = dispJordan (jordan (A)));
276 Note that, in this example, the Jordan form of @code{A} is computed
277 twice. To avoid this, we could have stored the output of
278 @code{jordan(A)} in a variable and passed that to both
279 @code{ModeMatrix} and @code{dispJordan}.
281 To use this function write first @code{load("diag")}. See also
282 @mref{jordan} and @mrefdot{dispJordan}
284 @opencatbox{Categories:}
285 @category{Package diag}
291 @anchor{mat_function}
292 @deffn {Function} mat_function (@var{f},@var{A})
293 Returns @math{f(A)}, where @var{f} is an analytic function and @var{A}
294 a matrix. This computation is based on the Taylor expansion of
295 @var{f}. It is not efficient for numerical evaluation, but can give
296 symbolic answers for small matrices.
298 @c What other methods do we have in Maxima at the moment? We should
299 @c probably give links here...
303 The exponential of a matrix. We only give the first row of the answer,
304 since the output is rather large.
307 @c A: matrix ([0,1,0], [0,0,1], [-1,-3,-3])$
308 @c ratsimp (mat_function (exp, t*A)[1]);
312 (%i2) A: matrix ([0,1,0], [0,0,1], [-1,-3,-3])$
314 (%i3) ratsimp (mat_function (exp, t*A)[1]);
316 (t + 2 t + 2) %e 2 - t t %e
317 (%o3) [--------------------, (t + t) %e , --------]
324 Comparison with the Taylor series for the exponential and also
325 comparing @code{exp(%i*A)} with sine and cosine.
328 @c A: matrix ([0,1,1,1],
332 @c ratsimp (mat_function (exp, t*A));
333 @c minimalPoly (jordan (A));
334 @c ratsimp (ident(4) + t*A + 1/2*(t^2)*A^^2);
335 @c ratsimp (mat_function (exp, %i*t*A));
336 @c ratsimp (mat_function (cos, t*A) + %i*mat_function (sin, t*A));
341 (%i2) A: matrix ([0,1,1,1],
347 (%i3) ratsimp (mat_function (exp, t*A));
358 (%i4) minimalPoly (jordan (A));
363 (%i5) ratsimp (ident(4) + t*A + 1/2*(t^2)*A^^2);
374 (%i6) ratsimp (mat_function (exp, %i*t*A));
376 [ 1 %i t %i t %i t - t ]
385 (%i7) ratsimp (mat_function (cos, t*A) + %i*mat_function (sin, t*A));
387 [ 1 %i t %i t %i t - t ]
402 @c A: matrix([1,2,0], [0,1,0], [1,0,1])$
403 @c integer_pow(x) := block ([k], declare (k, integer), x^k)$
404 @c mat_function (integer_pow, A);
409 (%i2) A: matrix([1,2,0], [0,1,0], [1,0,1])$
410 (%i3) integer_pow(x) := block ([k], declare (k, integer), x^k)$
412 (%i4) mat_function (integer_pow, A);
429 To use this function write first @code{load("diag")}.
431 @opencatbox{Categories:}
432 @category{Package diag}