# HG changeset patch # User John W. Eaton # Date 1294689033 18000 # Node ID a02d00dd3d5f5a3a5c1ff7f968921bf9657ff23b # Parent ff7e0776ba0fa297ee68aae627b61130c17efc08 expm.m: new tests diff -r ff7e0776ba0f -r a02d00dd3d5f scripts/ChangeLog --- a/scripts/ChangeLog Mon Jan 10 14:48:55 2011 -0500 +++ b/scripts/ChangeLog Mon Jan 10 14:50:33 2011 -0500 @@ -1,3 +1,7 @@ +2011-01-10 John W. Eaton + + * linear-algebra/expm.m: Validate nargin. New tests. + 2011-01-10 John W. Eaton * linear-algebra/logm.m: Handle scalar and diagonal matrix diff -r ff7e0776ba0f -r a02d00dd3d5f scripts/linear-algebra/expm.m --- a/scripts/linear-algebra/expm.m Mon Jan 10 14:48:55 2011 -0500 +++ b/scripts/linear-algebra/expm.m Mon Jan 10 14:50:33 2011 -0500 @@ -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([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)