Mercurial > hg > octave-nkf
annotate scripts/linear-algebra/subspace.m @ 16048:10142aad4b9f classdef
Implement indirect method call: fun(obj, ...).
* libinterp/octave-value/ov-classdef.h (class cdef_manager): New class.
(cdef_method::cdef_method_rep::meta_subsref,
cdef_method::cdef_method_rep::meta_is_postfix_index_handled): New
methods.
* libinterp/octave-value/ov-classdef.cc (all_packages, all_classes):
Move static variables to class cdef_manager.
(lookup_class (std::string, bool, bool)): Move implementation to
method cdef_manager::do_find_class().
(lookup_package): Move implementation to method
cdef_manager::do_find_package().
(make_class): Use cdef_manager::register_class.
(make_package): Use cdef_manager::register_package and
cdef_manager::find_package.
(cdef_class::cdef_class_rep::meta_release): Use
cdef_manager::unregister_class.
(cdef_method::cdef_method_rep::meta_subsref): New method.
(class cdef_manager): New class.
* libinterp/interpfcn/symtab.cc
(symbol_table::fcn_info::fcn_info_rep::load_class_constructor):
Look for classdef constructor in normal m-files. Call
find_user_function() and check whether the result is a classdef
constructor. If it is, stash it as a constructor and restore the
previous value of function_on_path.
(symbol_table::fcn_info::fcn_info_rep::load_class_method): Look for
method in classdef system, using cdef_manager::find_method_symbol().
author | Michael Goffioul <michael.goffioul@gmail.com> |
---|---|
date | Mon, 11 Feb 2013 15:20:00 -0500 |
parents | 72c96de7a403 |
children | 1c89599167a6 |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
11587
diff
changeset
|
1 ## Copyright (C) 2008-2012 VZLU Prague, a.s., Czech Republic |
7611 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
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. | |
9 ## | |
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. | |
14 ## | |
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/>. | |
18 | |
19 ## -*- texinfo -*- | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
20 ## @deftypefn {Function File} {@var{angle} =} subspace (@var{A}, @var{B}) |
7611 | 21 ## Determine the largest principal angle between two subspaces |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
22 ## spanned by the columns of matrices @var{A} and @var{B}. |
7611 | 23 ## @end deftypefn |
24 | |
25 ## Author: Jaroslav Hajek <highegg@gmail.com> | |
26 | |
27 ## reference: | |
28 ## [1] Andrew V. Knyazev, Merico E. Argentati: | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
29 ## Principal Angles between Subspaces in an A-Based Scalar Product: |
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
30 ## Algorithms and Perturbation Estimates. |
7611 | 31 ## SIAM Journal on Scientific Computing, Vol. 23 no. 6, pp. 2008-2040 |
32 ## | |
33 ## other texts are also around... | |
34 | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
35 function ang = subspace (A, B) |
7611 | 36 |
7612
c1702f963a5e
error check for subspace.m
Jaroslav Hajek <highegg@gmail.com>
parents:
7611
diff
changeset
|
37 if (nargin != 2) |
c1702f963a5e
error check for subspace.m
Jaroslav Hajek <highegg@gmail.com>
parents:
7611
diff
changeset
|
38 print_usage (); |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
39 elseif (ndims (A) != 2 || ndims (B) != 2) |
7612
c1702f963a5e
error check for subspace.m
Jaroslav Hajek <highegg@gmail.com>
parents:
7611
diff
changeset
|
40 error ("subspace: expecting A and B to be 2-dimensional arrays"); |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
41 elseif (rows (A) != rows (B)) |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
42 error ("subspace: column dimensions of A and B must match"); |
7612
c1702f963a5e
error check for subspace.m
Jaroslav Hajek <highegg@gmail.com>
parents:
7611
diff
changeset
|
43 endif |
c1702f963a5e
error check for subspace.m
Jaroslav Hajek <highegg@gmail.com>
parents:
7611
diff
changeset
|
44 |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
45 A = orth (A); |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
46 B = orth (B); |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
47 c = A'*B; |
7611 | 48 scos = min (svd (c)); |
49 if (scos^2 > 1/2) | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
50 if (columns (A) >= columns (B)) |
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
51 c = B - A*c; |
7611 | 52 else |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
53 c = A - B*c'; |
7611 | 54 endif |
55 ssin = max (svd (c)); | |
56 ang = asin (min (ssin, 1)); | |
57 else | |
58 ang = acos (scos); | |
59 endif | |
60 | |
61 endfunction |