1 ## Copyright (C) 2008-2012 VZLU Prague, a.s., Czech Republic
3 ## This file is part of Octave.
5 ## Octave is free software; you can redistribute it and/or modify it
6 ## under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
10 ## Octave is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ## General Public License for more details.
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>.
20 ## @deftypefn {Function File} {@var{angle} =} subspace (@var{A}, @var{B})
21 ## Determine the largest principal angle between two subspaces
22 ## spanned by the columns of matrices @var{A} and @var{B}.
25 ## Author: Jaroslav Hajek <highegg@gmail.com>
28 ## [1] Andrew V. Knyazev, Merico E. Argentati:
29 ## Principal Angles between Subspaces in an A-Based Scalar Product:
30 ## Algorithms and Perturbation Estimates.
31 ## SIAM Journal on Scientific Computing, Vol. 23 no. 6, pp. 2008-2040
33 ## other texts are also around...
35 function ang = subspace (A, B)
39 elseif (ndims (A) != 2 || ndims (B) != 2)
40 error ("subspace: expecting A and B to be 2-dimensional arrays");
41 elseif (rows (A) != rows (B))
42 error ("subspace: column dimensions of A and B must match");
50 if (columns (A) >= columns (B))
56 ang = asin (min (ssin, 1));