# HG changeset patch # User Jaroslav Hajek # Date 1205749585 -3600 # Node ID bc6b66bb8c5c2afb379ff0e5f6aa6d96fcdfb662 # Parent bf704d1c5e4375253408bbb855f99138cee2bb5c implement subspace function diff -r bf704d1c5e43 -r bc6b66bb8c5c scripts/ChangeLog --- a/scripts/ChangeLog Fri Mar 14 08:00:50 2008 -0400 +++ b/scripts/ChangeLog Mon Mar 17 11:26:25 2008 +0100 @@ -1,3 +1,7 @@ 2008-03-14 Kai Habel + + * linear-algebra/subspace.m: New function. + 2008-03-14 Kai Habel * plot/__go_draw_axes__.m: Expicitly set gnuplot user diff -r bf704d1c5e43 -r bc6b66bb8c5c scripts/linear-algebra/Makefile.in --- a/scripts/linear-algebra/Makefile.in Fri Mar 14 08:00:50 2008 -0400 +++ b/scripts/linear-algebra/Makefile.in Mon Mar 17 11:26:25 2008 +0100 @@ -35,7 +35,8 @@ INSTALL_DATA = @INSTALL_DATA@ SOURCES = __norm__.m commutation_matrix.m cond.m condest.m cross.m \ dmult.m dot.m duplication_matrix.m housh.m krylov.m krylovb.m logm.m \ - null.m onenormest.m orth.m qzhess.m rank.m rref.m trace.m vec.m vech.m + null.m onenormest.m orth.m qzhess.m rank.m rref.m subspace.m trace.m \ + vec.m vech.m DISTFILES = $(addprefix $(srcdir)/, Makefile.in $(SOURCES)) diff -r bf704d1c5e43 -r bc6b66bb8c5c scripts/linear-algebra/subspace.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/linear-algebra/subspace.m Mon Mar 17 11:26:25 2008 +0100 @@ -0,0 +1,54 @@ +## Copyright (C) 2008 VZLU Prague, a.s., Czech Republic +## +## This file is part of Octave. +## +## Octave is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 3 of the License, or (at +## your option) any later version. +## +## Octave is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with Octave; see the file COPYING. If not, see +## . +## +## Author: Jaroslav Hajek +## +## reference: +## [1] Andrew V. Knyazev, Merico E. Argentati: +## Principal Angles between Subspaces in an A-Based Scalar Product: +## Algorithms and Perturbation Estimates. +## SIAM Journal on Scientific Computing, Vol. 23 no. 6, pp. 2008-2040 +## +## other texts are also around... + + +## -*- texinfo -*- +## @deftypefn{Function File} angle = subspace (A, B) +## determines the largest principal angle between two subspaces +## (spanned by columns of matrices @var{A}, @var{B}). +## @end deftypefn + + +function ang = subspace (A, B) + +A = orth (A); +B = orth (B); +C = A'*B; +scos = min (svd (C)); +if (scos^2 > 1/2) + if (size (A, 2) >= size (B, 2)) + C = B - A*C; + else + C = A - B*C'; + endif + ssin = max (svd (C)); + ang = asin (min (ssin, 1)); +else + ang = acos (scos); +endif +