]> Creatis software - CreaPhase.git/blob - octave_packages/m/linear-algebra/planerot.m
update packages
[CreaPhase.git] / octave_packages / m / linear-algebra / planerot.m
1 ## Copyright (C) 2008-2012 David Bateman
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 -*-
20 ## @deftypefn {Function File} {[@var{g}, @var{y}] =} planerot (@var{x})
21 ## Given a two-element column vector, returns the
22 ## @tex
23 ## $2 \times 2$ orthogonal matrix
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)
34   G = givens (x(1), x(2));
35   y = G * x(:);
36 endfunction
37
38 %!test
39 %! x = [3 4];
40 %! [g y] = planerot(x);
41 %! assert(g - [x(1) x(2); -x(2) x(1)] / sqrt(x(1)^2 + x(2)^2), zeros(2), 2e-8);
42 %! assert(y(2), 0, 2e-8);
43
44 %!error planerot([0]);
45 %!error planerot([0 0 0]);
46 %!error planerot();
47