annotate scripts/linear-algebra/expm.m @ 20170:af2b7695f1c4 draft default tip @

gallery.m: clean and vectorize part of qmult. * scripts/special-matrix/gallery.m: make qmult() follow Octave guidelines, vectorize last for loop in qmult().
author Antonio Pino Robles <data.script93@gmail.com>
date Thu, 28 May 2015 18:32:47 +0200
parents 9fc020886ae9
children 03b9d17a2d95
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19697
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19040
diff changeset
1 ## Copyright (C) 2008-2015 Jaroslav Hajek, Marco Caliari
8393
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
2 ##
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
3 ## This file is part of Octave.
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
4 ##
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
8 ## your option) any later version.
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
9 ##
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
13 ## General Public License for more details.
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
14 ##
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
17 ## <http://www.gnu.org/licenses/>.
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
18
9065
8207b833557f Cleanup documentation for arith.texi, linalg.texi, nonlin.texi
Rik <rdrider0-list@yahoo.com>
parents: 9048
diff changeset
19 ## -*- texinfo -*-
11471
994e2a93a8e2 Use uppercase 'A' to refer to matrix inputs in m-files.
Rik <octave@nomad.inbox5.com>
parents: 10831
diff changeset
20 ## @deftypefn {Function File} {} expm (@var{A})
8393
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
21 ## Return the exponential of a matrix, defined as the infinite Taylor
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
22 ## series
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
23 ## @tex
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
24 ## $$
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
25 ## \exp (A) = I + A + {A^2 \over 2!} + {A^3 \over 3!} + \cdots
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
26 ## $$
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
27 ## @end tex
8517
81d6ab3ac93c Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents: 8506
diff changeset
28 ## @ifnottex
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
29 ##
8393
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
30 ## @example
14327
4d917a6a858b doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
31 ## expm (A) = I + A + A^2/2! + A^3/3! + @dots{}
8393
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
32 ## @end example
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
33 ##
8517
81d6ab3ac93c Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents: 8506
diff changeset
34 ## @end ifnottex
8393
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
35 ## The Taylor series is @emph{not} the way to compute the matrix
19040
0850b5212619 doc: Add @nospell macro around proper names in documentation.
Rik <rik@octave.org>
parents: 17744
diff changeset
36 ## exponential; see @nospell{Moler and Van Loan}, @cite{Nineteen Dubious Ways
0850b5212619 doc: Add @nospell macro around proper names in documentation.
Rik <rik@octave.org>
parents: 17744
diff changeset
37 ## to Compute the Exponential of a Matrix}, SIAM Review, 1978. This routine
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
38 ## uses Ward's diagonal Pad@'e approximation method with three step
10791
3140cb7a05a1 Add spellchecker scripts for Octave and run spellcheck of documentation
Rik <octave@nomad.inbox5.com>
parents: 10635
diff changeset
39 ## preconditioning (SIAM Journal on Numerical Analysis, 1977). Diagonal
3140cb7a05a1 Add spellchecker scripts for Octave and run spellcheck of documentation
Rik <octave@nomad.inbox5.com>
parents: 10635
diff changeset
40 ## Pad@'e approximations are rational polynomials of matrices
8393
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
41 ## @tex
11471
994e2a93a8e2 Use uppercase 'A' to refer to matrix inputs in m-files.
Rik <octave@nomad.inbox5.com>
parents: 10831
diff changeset
42 ## $D_q(A)^{-1}N_q(A)$
8393
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
43 ## @end tex
8517
81d6ab3ac93c Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents: 8506
diff changeset
44 ## @ifnottex
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
45 ##
8393
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
46 ## @example
9065
8207b833557f Cleanup documentation for arith.texi, linalg.texi, nonlin.texi
Rik <rdrider0-list@yahoo.com>
parents: 9048
diff changeset
47 ## @group
8393
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
48 ## -1
11471
994e2a93a8e2 Use uppercase 'A' to refer to matrix inputs in m-files.
Rik <octave@nomad.inbox5.com>
parents: 10831
diff changeset
49 ## D (A) N (A)
9065
8207b833557f Cleanup documentation for arith.texi, linalg.texi, nonlin.texi
Rik <rdrider0-list@yahoo.com>
parents: 9048
diff changeset
50 ## @end group
8393
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
51 ## @end example
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
52 ##
8517
81d6ab3ac93c Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents: 8506
diff changeset
53 ## @end ifnottex
10791
3140cb7a05a1 Add spellchecker scripts for Octave and run spellcheck of documentation
Rik <octave@nomad.inbox5.com>
parents: 10635
diff changeset
54 ## whose Taylor series matches the first
8393
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
55 ## @tex
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
56 ## $2 q + 1 $
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
57 ## @end tex
8517
81d6ab3ac93c Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents: 8506
diff changeset
58 ## @ifnottex
8393
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
59 ## @code{2q+1}
8517
81d6ab3ac93c Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents: 8506
diff changeset
60 ## @end ifnottex
8393
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
61 ## terms of the Taylor series above; direct evaluation of the Taylor series
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
62 ## (with the same preconditioning steps) may be desirable in lieu of the
10791
3140cb7a05a1 Add spellchecker scripts for Octave and run spellcheck of documentation
Rik <octave@nomad.inbox5.com>
parents: 10635
diff changeset
63 ## Pad@'e approximation when
8393
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
64 ## @tex
11471
994e2a93a8e2 Use uppercase 'A' to refer to matrix inputs in m-files.
Rik <octave@nomad.inbox5.com>
parents: 10831
diff changeset
65 ## $D_q(A)$
8393
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
66 ## @end tex
8517
81d6ab3ac93c Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents: 8506
diff changeset
67 ## @ifnottex
11471
994e2a93a8e2 Use uppercase 'A' to refer to matrix inputs in m-files.
Rik <octave@nomad.inbox5.com>
parents: 10831
diff changeset
68 ## @code{Dq(A)}
8517
81d6ab3ac93c Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents: 8506
diff changeset
69 ## @end ifnottex
8393
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
70 ## is ill-conditioned.
12584
7ef7e20057fa Improve documentation strings in Linear Algebra chapter.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
71 ## @seealso{logm, sqrtm}
8393
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
72 ## @end deftypefn
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
73
11471
994e2a93a8e2 Use uppercase 'A' to refer to matrix inputs in m-files.
Rik <octave@nomad.inbox5.com>
parents: 10831
diff changeset
74 function r = expm (A)
8393
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
75
11477
a02d00dd3d5f expm.m: new tests
John W. Eaton <jwe@octave.org>
parents: 11472
diff changeset
76 if (nargin != 1)
a02d00dd3d5f expm.m: new tests
John W. Eaton <jwe@octave.org>
parents: 11472
diff changeset
77 print_usage ();
a02d00dd3d5f expm.m: new tests
John W. Eaton <jwe@octave.org>
parents: 11472
diff changeset
78 endif
a02d00dd3d5f expm.m: new tests
John W. Eaton <jwe@octave.org>
parents: 11472
diff changeset
79
19700
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
80 if (! isnumeric (A) || ! issquare (A))
11472
1740012184f9 Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents: 11471
diff changeset
81 error ("expm: A must be a square matrix");
8393
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
82 endif
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
83
11471
994e2a93a8e2 Use uppercase 'A' to refer to matrix inputs in m-files.
Rik <octave@nomad.inbox5.com>
parents: 10831
diff changeset
84 if (isscalar (A))
994e2a93a8e2 Use uppercase 'A' to refer to matrix inputs in m-files.
Rik <octave@nomad.inbox5.com>
parents: 10831
diff changeset
85 r = exp (A);
17312
088d014a7fe2 Use semicolon after "return" statement in core m-files.
Rik <rik@octave.org>
parents: 14363
diff changeset
86 return;
11471
994e2a93a8e2 Use uppercase 'A' to refer to matrix inputs in m-files.
Rik <octave@nomad.inbox5.com>
parents: 10831
diff changeset
87 elseif (strfind (typeinfo (A), "diagonal matrix"))
994e2a93a8e2 Use uppercase 'A' to refer to matrix inputs in m-files.
Rik <octave@nomad.inbox5.com>
parents: 10831
diff changeset
88 r = diag (exp (diag (A)));
17312
088d014a7fe2 Use semicolon after "return" statement in core m-files.
Rik <rik@octave.org>
parents: 14363
diff changeset
89 return;
10831
1646bd8e3735 special case diagonal matrices and scalars in expm
Jaroslav Hajek <highegg@gmail.com>
parents: 10791
diff changeset
90 endif
1646bd8e3735 special case diagonal matrices and scalars in expm
Jaroslav Hajek <highegg@gmail.com>
parents: 10791
diff changeset
91
11471
994e2a93a8e2 Use uppercase 'A' to refer to matrix inputs in m-files.
Rik <octave@nomad.inbox5.com>
parents: 10831
diff changeset
92 n = rows (A);
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8393
diff changeset
93 ## Trace reduction.
11471
994e2a93a8e2 Use uppercase 'A' to refer to matrix inputs in m-files.
Rik <octave@nomad.inbox5.com>
parents: 10831
diff changeset
94 A(A == -Inf) = -realmax;
994e2a93a8e2 Use uppercase 'A' to refer to matrix inputs in m-files.
Rik <octave@nomad.inbox5.com>
parents: 10831
diff changeset
95 trshift = trace (A) / length (A);
8393
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
96 if (trshift > 0)
11471
994e2a93a8e2 Use uppercase 'A' to refer to matrix inputs in m-files.
Rik <octave@nomad.inbox5.com>
parents: 10831
diff changeset
97 A -= trshift*eye (n);
8393
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
98 endif
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8393
diff changeset
99 ## Balancing.
11471
994e2a93a8e2 Use uppercase 'A' to refer to matrix inputs in m-files.
Rik <octave@nomad.inbox5.com>
parents: 10831
diff changeset
100 [d, p, aa] = balance (A);
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8393
diff changeset
101 ## FIXME: can we both permute and scale at once? Or should we rather do
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8393
diff changeset
102 ## this:
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8393
diff changeset
103 ##
11471
994e2a93a8e2 Use uppercase 'A' to refer to matrix inputs in m-files.
Rik <octave@nomad.inbox5.com>
parents: 10831
diff changeset
104 ## [d, xx, aa] = balance (A, "noperm");
9048
867d5d1aed06 swap out args in balance for M*b compat
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
105 ## [xx, p, aa] = balance (aa, "noscal");
8393
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
106 [f, e] = log2 (norm (aa, "inf"));
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
107 s = max (0, e);
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
108 s = min (s, 1023);
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
109 aa *= 2^(-s);
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
110
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8393
diff changeset
111 ## Pade approximation for exp(A).
8393
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
112 c = [5.0000000000000000e-1,...
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
113 1.1666666666666667e-1,...
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
114 1.6666666666666667e-2,...
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
115 1.6025641025641026e-3,...
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
116 1.0683760683760684e-4,...
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
117 4.8562548562548563e-6,...
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
118 1.3875013875013875e-7,...
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
119 1.9270852604185938e-9];
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
120
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
121 a2 = aa^2;
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
122 id = eye (n);
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
123 x = (((c(8) * a2 + c(6) * id) * a2 + c(4) * id) * a2 + c(2) * id) * a2 + id;
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
124 y = (((c(7) * a2 + c(5) * id) * a2 + c(3) * id) * a2 + c(1) * id) * aa;
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
125
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
126 r = (x - y) \ (x + y);
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
127
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8393
diff changeset
128 ## Undo scaling by repeated squaring.
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8393
diff changeset
129 for k = 1:s
8393
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
130 r ^= 2;
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
131 endfor
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
132
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8393
diff changeset
133 ## inverse balancing.
8757
79576d40acb6 fix unscaling in expm
Jaroslav Hajek <highegg@gmail.com>
parents: 8664
diff changeset
134 d = diag (d);
79576d40acb6 fix unscaling in expm
Jaroslav Hajek <highegg@gmail.com>
parents: 8664
diff changeset
135 r = d * r / d;
9819
84398271118c fix typo in expm
Jaroslav Hajek <highegg@gmail.com>
parents: 9211
diff changeset
136 r(p, p) = r;
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8393
diff changeset
137 ## Inverse trace reduction.
8393
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
138 if (trshift >0)
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
139 r *= exp (trshift);
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
140 endif
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
141
c8a785d0e867 add omitted m-file
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
142 endfunction
11477
a02d00dd3d5f expm.m: new tests
John W. Eaton <jwe@octave.org>
parents: 11472
diff changeset
143
a02d00dd3d5f expm.m: new tests
John W. Eaton <jwe@octave.org>
parents: 11472
diff changeset
144
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14327
diff changeset
145 %!assert (norm (expm ([1 -1;0 1]) - [e -e; 0 e]) < 1e-5);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14327
diff changeset
146 %!assert (expm ([1 -1 -1;0 1 -1; 0 0 1]), [e -e -e/2; 0 e -e; 0 0 e], 1e-5);
11477
a02d00dd3d5f expm.m: new tests
John W. Eaton <jwe@octave.org>
parents: 11472
diff changeset
147
a02d00dd3d5f expm.m: new tests
John W. Eaton <jwe@octave.org>
parents: 11472
diff changeset
148 %!assert (expm (10), expm (10))
a02d00dd3d5f expm.m: new tests
John W. Eaton <jwe@octave.org>
parents: 11472
diff changeset
149 %!assert (full (expm (eye (3))), expm (full (eye (3))))
a02d00dd3d5f expm.m: new tests
John W. Eaton <jwe@octave.org>
parents: 11472
diff changeset
150 %!assert (full (expm (10*eye (3))), expm (full (10*eye (3))), 8*eps)
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14327
diff changeset
151
19833
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19700
diff changeset
152 ## Test input validation
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14327
diff changeset
153 %!error expm ()
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14327
diff changeset
154 %!error expm (1, 2)
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14327
diff changeset
155 %!error <expm: A must be a square matrix> expm ([1 0;0 1; 2 2])
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14327
diff changeset
156