Mercurial > hg > octave-nkf
annotate scripts/linear-algebra/planerot.m @ 20815:a260a6acb70f
fix test failures introduced by a22d8a2eb0e5
* scripts/ode/private/integrate_adaptive.m: fix stepping backwards, fix
invocation of OutputFcn, fix text of some error messages
* scripts/ode/private/integrate_const.m: remove use of option OutputSave
* scripts/ode/private/integrate_n_steps.m: remove use of option OutputSave
author | Carlo de Falco <carlo.defalco@polimi.it> |
---|---|
date | Sun, 11 Oct 2015 23:09:01 +0200 |
parents | 4197fc428c7d |
children |
rev | line source |
---|---|
19898
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19361
diff
changeset
|
1 ## Copyright (C) 2008-2015 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 | |
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 -*- | |
19361
1faae07afbd8
Overhaul givens and planerot functions.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
20 ## @deftypefn {Function File} {[@var{G}, @var{y}] =} planerot (@var{x}) |
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) | |
19361
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(:); | |
19361
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 () |
19361
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]) |
13048
c5c94b63931f
codesprint: linear algebra tests: cross, housh, planerot, qzhess, rref
Roman Belov <romblv@gmail.com>
parents:
11523
diff
changeset
|
57 |