2928
|
1 /* |
|
2 |
|
3 Copyright (C) 1996, 1997 John W. Eaton |
|
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 |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
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 |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
2928
|
21 |
|
22 */ |
|
23 |
|
24 // Originally written by A. S. Hodel <scotte@eng.auburn.edu> |
|
25 |
|
26 #ifdef HAVE_CONFIG_H |
|
27 #include <config.h> |
|
28 #endif |
|
29 |
|
30 #include "defun-dld.h" |
|
31 #include "error.h" |
|
32 #include "oct-obj.h" |
|
33 |
|
34 DEFUN_DLD (givens, args, nargout, |
3548
|
35 "-*- texinfo -*-\n\ |
3499
|
36 @deftypefn {Loadable Function} {@var{g} =} givens (@var{x}, @var{y})\n\ |
3372
|
37 @deftypefnx {Loadable Function} {[@var{c}, @var{s}] =} givens (@var{x}, @var{y})\n\ |
|
38 @iftex\n\ |
|
39 @tex\n\ |
|
40 Return a $2\\times 2$ orthogonal matrix\n\ |
|
41 $$\n\ |
|
42 G = \\left[\\matrix{c & s\\cr -s'& c\\cr}\\right]\n\ |
|
43 $$\n\ |
|
44 such that\n\ |
|
45 $$\n\ |
|
46 G \\left[\\matrix{x\\cr y}\\right] = \\left[\\matrix{\\ast\\cr 0}\\right]\n\ |
|
47 $$\n\ |
|
48 with $x$ and $y$ scalars.\n\ |
|
49 @end tex\n\ |
|
50 @end iftex\n\ |
|
51 @ifinfo\n\ |
|
52 Return a 2 by 2 orthogonal matrix\n\ |
3499
|
53 @code{@var{g} = [@var{c} @var{s}; -@var{s}' @var{c}]} such that\n\ |
|
54 @code{@var{g} [@var{x}; @var{y}] = [*; 0]} with @var{x} and @var{y} scalars.\n\ |
3372
|
55 @end ifinfo\n\ |
2928
|
56 \n\ |
3372
|
57 For example,\n\ |
2928
|
58 \n\ |
3372
|
59 @example\n\ |
|
60 @group\n\ |
|
61 givens (1, 1)\n\ |
|
62 @result{} 0.70711 0.70711\n\ |
|
63 -0.70711 0.70711\n\ |
|
64 @end group\n\ |
|
65 @end example\n\ |
|
66 @end deftypefn") |
2928
|
67 { |
|
68 octave_value_list retval; |
|
69 |
|
70 int nargin = args.length (); |
|
71 |
|
72 if (nargin != 2 || nargout > 2) |
|
73 { |
5823
|
74 print_usage (); |
2928
|
75 return retval; |
|
76 } |
|
77 else |
|
78 { |
|
79 if (args(0).is_complex_type () || args(1).is_complex_type ()) |
|
80 { |
|
81 Complex cx = args(0).complex_value (); |
|
82 Complex cy = args(1).complex_value (); |
|
83 |
|
84 if (! error_state) |
|
85 { |
|
86 ComplexMatrix result = Givens (cx, cy); |
|
87 |
|
88 if (! error_state) |
|
89 { |
|
90 switch (nargout) |
|
91 { |
|
92 case 0: |
|
93 case 1: |
|
94 retval(0) = result; |
|
95 break; |
|
96 |
|
97 case 2: |
|
98 retval(1) = result (0, 1); |
|
99 retval(0) = result (0, 0); |
|
100 break; |
|
101 |
|
102 default: |
|
103 error ("givens: invalid number of output arguments"); |
|
104 break; |
|
105 } |
|
106 } |
|
107 } |
|
108 } |
|
109 else |
|
110 { |
|
111 double x = args(0).double_value (); |
|
112 double y = args(1).double_value (); |
|
113 |
|
114 if (! error_state) |
|
115 { |
|
116 Matrix result = Givens (x, y); |
|
117 |
|
118 if (! error_state) |
|
119 { |
|
120 switch (nargout) |
|
121 { |
|
122 case 0: |
|
123 case 1: |
|
124 retval(0) = result; |
|
125 break; |
|
126 |
|
127 case 2: |
|
128 retval(1) = result (0, 1); |
|
129 retval(0) = result (0, 0); |
|
130 break; |
|
131 |
|
132 default: |
|
133 error ("givens: invalid number of output arguments"); |
|
134 break; |
|
135 } |
|
136 } |
|
137 } |
|
138 } |
|
139 } |
|
140 |
|
141 return retval; |
|
142 } |
|
143 |
|
144 /* |
|
145 ;;; Local Variables: *** |
|
146 ;;; mode: C++ *** |
|
147 ;;; End: *** |
|
148 */ |