2928
|
1 /* |
|
2 |
7017
|
3 Copyright (C) 1996, 1997, 1999, 2000, 2005, 2006, 2007 John W. Eaton |
2928
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
7016
|
9 Free Software Foundation; either version 3 of the License, or (at your |
|
10 option) any later version. |
2928
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
7016
|
18 along with Octave; see the file COPYING. If not, see |
|
19 <http://www.gnu.org/licenses/>. |
2928
|
20 |
|
21 */ |
|
22 |
|
23 // Originally written by A. S. Hodel <scotte@eng.auburn.edu> |
|
24 |
|
25 #ifdef HAVE_CONFIG_H |
|
26 #include <config.h> |
|
27 #endif |
|
28 |
|
29 #include "defun-dld.h" |
|
30 #include "error.h" |
|
31 #include "oct-obj.h" |
|
32 |
|
33 DEFUN_DLD (givens, args, nargout, |
3548
|
34 "-*- texinfo -*-\n\ |
3499
|
35 @deftypefn {Loadable Function} {@var{g} =} givens (@var{x}, @var{y})\n\ |
3372
|
36 @deftypefnx {Loadable Function} {[@var{c}, @var{s}] =} givens (@var{x}, @var{y})\n\ |
|
37 @iftex\n\ |
|
38 @tex\n\ |
|
39 Return a $2\\times 2$ orthogonal matrix\n\ |
|
40 $$\n\ |
|
41 G = \\left[\\matrix{c & s\\cr -s'& c\\cr}\\right]\n\ |
|
42 $$\n\ |
|
43 such that\n\ |
|
44 $$\n\ |
|
45 G \\left[\\matrix{x\\cr y}\\right] = \\left[\\matrix{\\ast\\cr 0}\\right]\n\ |
|
46 $$\n\ |
|
47 with $x$ and $y$ scalars.\n\ |
|
48 @end tex\n\ |
|
49 @end iftex\n\ |
|
50 @ifinfo\n\ |
|
51 Return a 2 by 2 orthogonal matrix\n\ |
3499
|
52 @code{@var{g} = [@var{c} @var{s}; -@var{s}' @var{c}]} such that\n\ |
|
53 @code{@var{g} [@var{x}; @var{y}] = [*; 0]} with @var{x} and @var{y} scalars.\n\ |
3372
|
54 @end ifinfo\n\ |
2928
|
55 \n\ |
3372
|
56 For example,\n\ |
2928
|
57 \n\ |
3372
|
58 @example\n\ |
|
59 @group\n\ |
|
60 givens (1, 1)\n\ |
|
61 @result{} 0.70711 0.70711\n\ |
|
62 -0.70711 0.70711\n\ |
|
63 @end group\n\ |
|
64 @end example\n\ |
|
65 @end deftypefn") |
2928
|
66 { |
|
67 octave_value_list retval; |
|
68 |
|
69 int nargin = args.length (); |
|
70 |
|
71 if (nargin != 2 || nargout > 2) |
|
72 { |
5823
|
73 print_usage (); |
2928
|
74 return retval; |
|
75 } |
|
76 else |
|
77 { |
|
78 if (args(0).is_complex_type () || args(1).is_complex_type ()) |
|
79 { |
|
80 Complex cx = args(0).complex_value (); |
|
81 Complex cy = args(1).complex_value (); |
|
82 |
|
83 if (! error_state) |
|
84 { |
|
85 ComplexMatrix result = Givens (cx, cy); |
|
86 |
|
87 if (! error_state) |
|
88 { |
|
89 switch (nargout) |
|
90 { |
|
91 case 0: |
|
92 case 1: |
|
93 retval(0) = result; |
|
94 break; |
|
95 |
|
96 case 2: |
|
97 retval(1) = result (0, 1); |
|
98 retval(0) = result (0, 0); |
|
99 break; |
|
100 |
|
101 default: |
|
102 error ("givens: invalid number of output arguments"); |
|
103 break; |
|
104 } |
|
105 } |
|
106 } |
|
107 } |
|
108 else |
|
109 { |
|
110 double x = args(0).double_value (); |
|
111 double y = args(1).double_value (); |
|
112 |
|
113 if (! error_state) |
|
114 { |
|
115 Matrix result = Givens (x, y); |
|
116 |
|
117 if (! error_state) |
|
118 { |
|
119 switch (nargout) |
|
120 { |
|
121 case 0: |
|
122 case 1: |
|
123 retval(0) = result; |
|
124 break; |
|
125 |
|
126 case 2: |
|
127 retval(1) = result (0, 1); |
|
128 retval(0) = result (0, 0); |
|
129 break; |
|
130 |
|
131 default: |
|
132 error ("givens: invalid number of output arguments"); |
|
133 break; |
|
134 } |
|
135 } |
|
136 } |
|
137 } |
|
138 } |
|
139 |
|
140 return retval; |
|
141 } |
|
142 |
|
143 /* |
|
144 ;;; Local Variables: *** |
|
145 ;;; mode: C++ *** |
|
146 ;;; End: *** |
|
147 */ |