Mercurial > octave
annotate scripts/linear-algebra/planerot.m @ 23084:ef4d915df748
maint: Merge stable to default.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 23 Jan 2017 14:27:48 -0500 |
parents | 3a2b891d0b33 e9a0469dedd9 |
children | 092078913d54 |
rev | line source |
---|---|
22323
bac0d6f07a3e
maint: Update copyright notices for 2016.
John W. Eaton <jwe@octave.org>
parents:
20852
diff
changeset
|
1 ## Copyright (C) 2008-2016 David Bateman |
7653 | 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 | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
7 ## the Free Software Foundation; either version 3 of the License, or |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
8 ## (at your option) any later version. |
7653 | 9 ## |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
13 ## GNU General Public License for more details. |
7653 | 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 -*- | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
20 ## @deftypefn {} {[@var{G}, @var{y}] =} planerot (@var{x}) |
19169
1faae07afbd8
Overhaul givens and planerot functions.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
21 ## Given a two-element column vector, return the |
7653 | 22 ## @tex |
7989
23c248d415b5
Various doc fixes. Readd cellidx
David Bateman <dbateman@free.fr>
parents:
7653
diff
changeset
|
23 ## $2 \times 2$ orthogonal matrix |
7653 | 24 ## @end tex |
25 ## @ifnottex | |
26 ## 2 by 2 orthogonal matrix | |
27 ## @end ifnottex | |
28 ## @var{G} such that | |
29 ## @code{@var{y} = @var{g} * @var{x}} and @code{@var{y}(2) = 0}. | |
30 ## @seealso{givens} | |
31 ## @end deftypefn | |
32 | |
33 function [G, y] = planerot (x) | |
19169
1faae07afbd8
Overhaul givens and planerot functions.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
34 |
1faae07afbd8
Overhaul givens and planerot functions.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
35 if (nargin != 1) |
1faae07afbd8
Overhaul givens and planerot functions.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
36 print_usage (); |
1faae07afbd8
Overhaul givens and planerot functions.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
37 elseif (! (isvector (x) && numel (x) == 2)) |
1faae07afbd8
Overhaul givens and planerot functions.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
38 error ("planerot: X must be a 2-element vector"); |
1faae07afbd8
Overhaul givens and planerot functions.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
39 endif |
1faae07afbd8
Overhaul givens and planerot functions.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
40 |
7653 | 41 G = givens (x(1), x(2)); |
42 y = G * x(:); | |
19169
1faae07afbd8
Overhaul givens and planerot functions.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
43 |
7653 | 44 endfunction |
13048
c5c94b63931f
codesprint: linear algebra tests: cross, housh, planerot, qzhess, rref
Roman Belov <romblv@gmail.com>
parents:
11523
diff
changeset
|
45 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
46 |
13048
c5c94b63931f
codesprint: linear algebra tests: cross, housh, planerot, qzhess, rref
Roman Belov <romblv@gmail.com>
parents:
11523
diff
changeset
|
47 %!test |
c5c94b63931f
codesprint: linear algebra tests: cross, housh, planerot, qzhess, rref
Roman Belov <romblv@gmail.com>
parents:
11523
diff
changeset
|
48 %! x = [3 4]; |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
49 %! [g y] = planerot (x); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
50 %! assert (g, [x(1) x(2); -x(2) x(1)] / sqrt (x(1)^2 + x(2)^2), 2e-8); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
51 %! assert (y(2), 0, 2e-8); |
13048
c5c94b63931f
codesprint: linear algebra tests: cross, housh, planerot, qzhess, rref
Roman Belov <romblv@gmail.com>
parents:
11523
diff
changeset
|
52 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
53 %!error planerot () |
19169
1faae07afbd8
Overhaul givens and planerot functions.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
54 %!error planerot (1,2) |
1faae07afbd8
Overhaul givens and planerot functions.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
55 %!error <X must be a 2-element vector> planerot (ones (2,2)) |
1faae07afbd8
Overhaul givens and planerot functions.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
56 %!error <X must be a 2-element vector> planerot ([0 0 0]) |