Mercurial > octave
annotate scripts/linear-algebra/subspace.m @ 27978:a4268efb7334
maint: Eliminate single "Author:" lines from code base.
* color-picker.cc, color-picker.h, octave-qscintilla.cc, octave-qscintilla.h,
octave-txt-lexer.cc, octave-txt-lexer.h, balance.cc, kron.cc, lookup.cc,
ls-hdf5.cc, ls-mat5.cc, ls-oct-text.cc, sylvester.cc, tsearch.cc, jit-ir.cc,
jit-ir.h, jit-typeinfo.cc, jit-typeinfo.h, jit-util.cc, jit-util.h, pt-jit.cc,
pt-jit.h, Array-jit.cc, bsxfun.h, url-transfer.cc, url-transfer.h, acosd.m,
acotd.m, acscd.m, asecd.m, asind.m, atand.m, cosd.m, cotd.m, cscd.m, secd.m,
sind.m, tand.m, cart2pol.m, cart2sph.m, curl.m, del2.m, divergence.m, flip.m,
pol2cart.m, randi.m, sortrows.m, sph2cart.m, griddata3.m, griddatan.m,
rectint.m, voronoi.m, dialog.m, guidata.m, guihandles.m, __file_filter__.m,
__fltk_file_filter__.m, __get_funcname__.m, __is_function__.m,
__uigetdir_fltk__.m, __uigetfile_fltk__.m, __uiobject_split_args__.m,
__uiputfile_fltk__.m, uibuttongroup.m, uicontextmenu.m, uicontrol.m,
uigetdir.m, uigetfile.m, uimenu.m, uipanel.m, uipushtool.m, uiputfile.m,
uiresume.m, uitoggletool.m, uitoolbar.m, uiwait.m, doc.m, autumn.m, bone.m,
cmpermute.m, cmunique.m, cool.m, copper.m, cubehelix.m, flag.m, frame2im.m,
hot.m, hsv.m, hsv2rgb.m, im2frame.m, imfinfo.m, imformats.m, iscolormap.m,
jet.m, pink.m, prism.m, __imfinfo__.m, rainbow.m, rgb2hsv.m, spinmap.m,
spring.m, viridis.m, white.m, winter.m, importdata.m, strmatch.m, bandwidth.m,
isbanded.m, isdiag.m, istril.m, istriu.m, krylov.m, linsolve.m, logm.m,
lscov.m, subspace.m, bunzip2.m, compare_versions.m, edit.m, fullfile.m,
getfield.m, gunzip.m, inputParser.m, license.m, nargchk.m, narginchk.m,
nthargout.m, python.m, setfield.m, tar.m, unpack.m, ver.m, zip.m, odeplot.m,
fminbnd.m, fminunc.m, fsolve.m, fzero.m, glpk.m, humps.m, pathdef.m,
savepath.m, diffuse.m, lighting.m, material.m, shading.m, specular.m,
contour.m, ellipsoid.m, isocaps.m, isocolors.m, isonormals.m, isosurface.m,
light.m, pcolor.m, __interp_cube__.m, __marching_cube__.m, __patch__.m,
__stem__.m, reducepatch.m, reducevolume.m, ribbon.m, shrinkfaces.m, slice.m,
stem.m, surf.m, surfl.m, tetramesh.m, waterfall.m, __actual_axis_position__.m,
__next_line_color__.m, allchild.m, figure.m, findall.m, findobj.m, gcf.m,
hggroup.m, isprop.m, ndgrid.m, __add_default_menu__.m, saveas.m,
__splinefit__.m, prefdir.m, preferences.m, profexplore.m, profexport.m,
profile.m, profshow.m, setdiff.m, freqz.m, freqz_plot.m, sinc.m, unwrap.m,
pcr.m, qmr.m, sprandn.m, betaincinv.m, cosint.m, ellipke.m, factor.m,
gammaincinv.m, legendre.m, nchoosek.m, primes.m, invhilb.m, toeplitz.m,
erase.m, mat2str.m, strtrim.m, validatestring.m, fail.m, compare_plot_demos.m,
dump_demos.m, html_compare_plot_demos.m, addtodate.m, datenum.m, jit.tst:
Eliminate single "Author:" lines from code base.
author | Rik <rik@octave.org> |
---|---|
date | Tue, 21 Jan 2020 12:53:13 -0800 |
parents | bd51beb6205e |
children | b09432b20a84 |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 ######################################################################## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 ## |
27919
1891570abac8
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
27918
diff
changeset
|
3 ## Copyright (C) 2008-2020 The Octave Project Developers |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
4 ## |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 ## See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 ## distribution or <https://octave.org/copyright/>. |
7611 | 7 ## |
8 ## This file is part of Octave. | |
9 ## | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
10 ## Octave is free software: you can redistribute it and/or modify it |
7611 | 11 ## under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
12 ## the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
13 ## (at your option) any later version. |
7611 | 14 ## |
15 ## Octave is distributed in the hope that it will be useful, but | |
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
18 ## GNU General Public License for more details. |
7611 | 19 ## |
20 ## You should have received a copy of the GNU General Public License | |
21 ## along with Octave; see the file COPYING. If not, see | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
22 ## <https://www.gnu.org/licenses/>. |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 ## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 ######################################################################## |
7611 | 25 |
26 ## -*- texinfo -*- | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20711
diff
changeset
|
27 ## @deftypefn {} {@var{angle} =} subspace (@var{A}, @var{B}) |
7611 | 28 ## 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
|
29 ## spanned by the columns of matrices @var{A} and @var{B}. |
7611 | 30 ## @end deftypefn |
31 | |
32 ## reference: | |
33 ## [1] Andrew V. Knyazev, Merico E. Argentati: | |
20194
b0f7ee81d974
doc: Remove extra spaces at start of docstring which show up in Info format.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
34 ## Principal Angles between Subspaces in an A-Based Scalar Product: |
b0f7ee81d974
doc: Remove extra spaces at start of docstring which show up in Info format.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
35 ## Algorithms and Perturbation Estimates. |
b0f7ee81d974
doc: Remove extra spaces at start of docstring which show up in Info format.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
36 ## SIAM Journal on Scientific Computing, Vol. 23 no. 6, pp. 2008-2040 |
7611 | 37 ## |
38 ## other texts are also around... | |
39 | |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
40 function ang = subspace (A, B) |
7611 | 41 |
7612
c1702f963a5e
error check for subspace.m
Jaroslav Hajek <highegg@gmail.com>
parents:
7611
diff
changeset
|
42 if (nargin != 2) |
c1702f963a5e
error check for subspace.m
Jaroslav Hajek <highegg@gmail.com>
parents:
7611
diff
changeset
|
43 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
|
44 elseif (ndims (A) != 2 || ndims (B) != 2) |
20711
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20194
diff
changeset
|
45 error ("subspace: A and B must 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
|
46 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
|
47 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
|
48 endif |
c1702f963a5e
error check for subspace.m
Jaroslav Hajek <highegg@gmail.com>
parents:
7611
diff
changeset
|
49 |
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 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
|
51 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
|
52 c = A'*B; |
7611 | 53 scos = min (svd (c)); |
54 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
|
55 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
|
56 c = B - A*c; |
7611 | 57 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
|
58 c = A - B*c'; |
7611 | 59 endif |
60 ssin = max (svd (c)); | |
61 ang = asin (min (ssin, 1)); | |
62 else | |
63 ang = acos (scos); | |
64 endif | |
65 | |
66 endfunction | |
17338
1c89599167a6
maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
67 |
19306
314b4de4bb6d
Add BIST tests for subspace, t_test, z_test.
Pooja Rao <poojarao12@gmail.com>
parents:
17744
diff
changeset
|
68 |
24839
55021b03884d
subspace.m: Change BIST tests to more accurately test function (bug #53242).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24534
diff
changeset
|
69 %!assert (subspace (1, 1), 0) |
55021b03884d
subspace.m: Change BIST tests to more accurately test function (bug #53242).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24534
diff
changeset
|
70 %!assert (subspace ([1, 0]', [1, 1; 0, 1]'), 0, 3*eps) |
55021b03884d
subspace.m: Change BIST tests to more accurately test function (bug #53242).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24534
diff
changeset
|
71 %!assert (subspace ([1, 0, 1]', [1, 1, 0; 1, -1, 0]'), pi/4, 3*eps) |
55021b03884d
subspace.m: Change BIST tests to more accurately test function (bug #53242).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24534
diff
changeset
|
72 %!assert (subspace ([1 5 0 0; -3 2 0 0]', [0 0 4 2; 0 0 4 3]'), pi/2) |
55021b03884d
subspace.m: Change BIST tests to more accurately test function (bug #53242).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24534
diff
changeset
|
73 %!assert (subspace ([1 1 1 1; 1 2 3 4]', [1 -1 -1 1]'), pi/2) |
19306
314b4de4bb6d
Add BIST tests for subspace, t_test, z_test.
Pooja Rao <poojarao12@gmail.com>
parents:
17744
diff
changeset
|
74 |
314b4de4bb6d
Add BIST tests for subspace, t_test, z_test.
Pooja Rao <poojarao12@gmail.com>
parents:
17744
diff
changeset
|
75 %!test |
24839
55021b03884d
subspace.m: Change BIST tests to more accurately test function (bug #53242).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24534
diff
changeset
|
76 %! ## For small angle between subspaces |
55021b03884d
subspace.m: Change BIST tests to more accurately test function (bug #53242).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24534
diff
changeset
|
77 %! theta = pi/200; |
55021b03884d
subspace.m: Change BIST tests to more accurately test function (bug #53242).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24534
diff
changeset
|
78 %! Ry = [cos(theta), 0, sin(theta);0, 1, 0;-sin(theta), 0, cos(theta)]; |
55021b03884d
subspace.m: Change BIST tests to more accurately test function (bug #53242).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24534
diff
changeset
|
79 %! a = Ry*[3*e, 0, 0]'; |
55021b03884d
subspace.m: Change BIST tests to more accurately test function (bug #53242).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24534
diff
changeset
|
80 %! b = [1, 1, 0; 1, -1, 0]'; |
55021b03884d
subspace.m: Change BIST tests to more accurately test function (bug #53242).
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
24534
diff
changeset
|
81 %! assert (theta, subspace (a, b), eps); |