changeset 24839:55021b03884d

subspace.m: Change BIST tests to more accurately test function (bug #53242). * subspace.m: Replace the tests using random vectors with one small-angle test that starts with a known angle. One subspace spans the xy-plane and the other is a vector along the x-axis rotated about the y-axis. Add some basic tests for 1-D, 2-D, 3-D, 4-D spaces.
author Daniel J Sebald <daniel.sebald@ieee.org>
date Thu, 01 Mar 2018 17:06:49 -0600
parents 08a591a59a95
children 2ee45d3f6ec1
files scripts/linear-algebra/subspace.m
diffstat 1 files changed, 11 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/linear-algebra/subspace.m	Mon Mar 05 15:18:20 2018 -0800
+++ b/scripts/linear-algebra/subspace.m	Thu Mar 01 17:06:49 2018 -0600
@@ -61,16 +61,16 @@
 endfunction
 
 
-%!test
-%! ## For random vectors
-%! a = rand (2,1);
-%! b = rand (2,1);
-%! a1 = norm (a,2);
-%! b1 = norm (b,2);
-%! theta = acos (dot (a,b)/(a1*b1));
-%! assert (theta, subspace (a, b), 100*eps);
+%!assert (subspace (1, 1), 0)
+%!assert (subspace ([1, 0]', [1, 1; 0, 1]'), 0, 3*eps)
+%!assert (subspace ([1, 0, 1]', [1, 1, 0; 1, -1, 0]'), pi/4, 3*eps)
+%!assert (subspace ([1 5 0 0; -3 2 0 0]', [0 0 4 2; 0 0 4 3]'), pi/2)
+%!assert (subspace ([1 1 1 1; 1 2 3 4]', [1 -1 -1 1]'), pi/2)
 
 %!test
-%! ## For random matrices
-%! M = rand (3, 3);
-%! assert (0, subspace (M, M'), 100*eps);
+%! ## For small angle between subspaces
+%! theta = pi/200;
+%! Ry = [cos(theta), 0, sin(theta);0, 1, 0;-sin(theta), 0, cos(theta)];
+%! a = Ry*[3*e, 0, 0]';
+%! b = [1, 1, 0; 1, -1, 0]';
+%! assert (theta, subspace (a, b), eps);