Mercurial > hg > octave-nkf
changeset 11477:a02d00dd3d5f
expm.m: new tests
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 10 Jan 2011 14:50:33 -0500 |
parents | ff7e0776ba0f |
children | 655d5c2d8462 |
files | scripts/ChangeLog scripts/linear-algebra/expm.m |
diffstat | 2 files changed, 20 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,7 @@ +2011-01-10 John W. Eaton <jwe@octave.org> + + * linear-algebra/expm.m: Validate nargin. New tests. + 2011-01-10 John W. Eaton <jwe@octave.org> * linear-algebra/logm.m: Handle scalar and diagonal matrix
--- a/scripts/linear-algebra/expm.m +++ b/scripts/linear-algebra/expm.m @@ -72,6 +72,10 @@ function r = expm (A) + if (nargin != 1) + print_usage (); + endif + if (! ismatrix (A) || ! issquare (A)) error ("expm: A must be a square matrix"); endif @@ -135,3 +139,15 @@ endif endfunction + +%!assert(norm(expm([1 -1;0 1]) - [e -e; 0 e]) < 1e-5); +%!assert(expm([1 -1 -1;0 1 -1; 0 0 1]), [e -e -e/2; 0 e -e; 0 0 e], 1e-5); + +%% Test input validation +%!error expm (); +%!error expm (1, 2); +%!error <expm: A must be a square matrix> expm([1 0;0 1; 2 2]); + +%!assert (expm (10), expm (10)) +%!assert (full (expm (eye (3))), expm (full (eye (3)))) +%!assert (full (expm (10*eye (3))), expm (full (10*eye (3))), 8*eps)