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 |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
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 "help.h" |
|
32 #include "oct-obj.h" |
|
33 |
|
34 DEFUN_DLD (givens, args, nargout, |
|
35 "G = givens (X, Y)\n\ |
|
36 \n\ |
|
37 compute orthogonal matrix G = [c s; -conj (s) c]\n\ |
|
38 such that G [x; y] = [*; 0] (x, y scalars)\n\ |
|
39 \n\ |
|
40 [c, s] = givens (x, y) returns the (c, s) values themselves.") |
|
41 { |
|
42 octave_value_list retval; |
|
43 |
|
44 int nargin = args.length (); |
|
45 |
|
46 if (nargin != 2 || nargout > 2) |
|
47 { |
|
48 print_usage ("givens"); |
|
49 return retval; |
|
50 } |
|
51 else |
|
52 { |
|
53 if (args(0).is_complex_type () || args(1).is_complex_type ()) |
|
54 { |
|
55 Complex cx = args(0).complex_value (); |
|
56 Complex cy = args(1).complex_value (); |
|
57 |
|
58 if (! error_state) |
|
59 { |
|
60 ComplexMatrix result = Givens (cx, cy); |
|
61 |
|
62 if (! error_state) |
|
63 { |
|
64 switch (nargout) |
|
65 { |
|
66 case 0: |
|
67 case 1: |
|
68 retval(0) = result; |
|
69 break; |
|
70 |
|
71 case 2: |
|
72 retval(1) = result (0, 1); |
|
73 retval(0) = result (0, 0); |
|
74 break; |
|
75 |
|
76 default: |
|
77 error ("givens: invalid number of output arguments"); |
|
78 break; |
|
79 } |
|
80 } |
|
81 } |
|
82 } |
|
83 else |
|
84 { |
|
85 double x = args(0).double_value (); |
|
86 double y = args(1).double_value (); |
|
87 |
|
88 if (! error_state) |
|
89 { |
|
90 Matrix result = Givens (x, y); |
|
91 |
|
92 if (! error_state) |
|
93 { |
|
94 switch (nargout) |
|
95 { |
|
96 case 0: |
|
97 case 1: |
|
98 retval(0) = result; |
|
99 break; |
|
100 |
|
101 case 2: |
|
102 retval(1) = result (0, 1); |
|
103 retval(0) = result (0, 0); |
|
104 break; |
|
105 |
|
106 default: |
|
107 error ("givens: invalid number of output arguments"); |
|
108 break; |
|
109 } |
|
110 } |
|
111 } |
|
112 } |
|
113 } |
|
114 |
|
115 return retval; |
|
116 } |
|
117 |
|
118 /* |
|
119 ;;; Local Variables: *** |
|
120 ;;; mode: C++ *** |
|
121 ;;; End: *** |
|
122 */ |