3155
|
1 /* |
|
2 |
|
3 Copyright (C) 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 #ifdef HAVE_CONFIG_H |
|
24 #include <config.h> |
|
25 #endif |
|
26 |
|
27 #include "lo-specfun.h" |
|
28 |
|
29 #include "defun-dld.h" |
|
30 #include "error.h" |
|
31 #include "gripes.h" |
|
32 #include "oct-obj.h" |
|
33 #include "utils.h" |
|
34 |
|
35 #define DO_BESSEL(type, alpha, x) \ |
|
36 do \ |
|
37 { \ |
|
38 switch (type) \ |
|
39 { \ |
|
40 case 'j': \ |
|
41 retval = besselj (alpha, x); \ |
|
42 break; \ |
|
43 \ |
|
44 case 'y': \ |
|
45 retval = bessely (alpha, x); \ |
|
46 break; \ |
|
47 \ |
|
48 case 'i': \ |
|
49 retval = besseli (alpha, x); \ |
|
50 break; \ |
|
51 \ |
|
52 case 'k': \ |
|
53 retval = besselk (alpha, x); \ |
|
54 break; \ |
|
55 \ |
|
56 default: \ |
|
57 break; \ |
|
58 } \ |
|
59 } \ |
|
60 while (0) |
|
61 |
|
62 static void |
|
63 gripe_bessel_arg_1 (const char *fn) |
|
64 { |
|
65 error ("%s: alpha must be scalar or range with increment equal to 1", fn); |
|
66 } |
|
67 |
|
68 octave_value_list |
|
69 do_bessel (char type, const char *fn, const octave_value_list& args) |
|
70 { |
|
71 octave_value retval; |
|
72 |
|
73 int nargin = args.length (); |
|
74 |
|
75 if (nargin == 2) |
|
76 { |
|
77 octave_value alpha_arg = args(0); |
|
78 |
|
79 if (alpha_arg.is_scalar_type ()) |
|
80 { |
|
81 double alpha = alpha_arg.double_value (); |
|
82 |
|
83 if (! error_state) |
|
84 { |
|
85 Matrix x = args(1).matrix_value (); |
|
86 |
|
87 if (! error_state) |
|
88 DO_BESSEL (type, alpha, x); |
|
89 else |
|
90 error ("%s: expecting matrix as second argument", fn); |
|
91 } |
|
92 else |
|
93 gripe_bessel_arg_1 (fn); |
|
94 } |
|
95 else |
|
96 { |
|
97 Range alpha; |
|
98 |
|
99 if (! alpha_arg.is_range ()) |
|
100 { |
|
101 ColumnVector tmp = alpha_arg.vector_value (); |
|
102 |
|
103 if (! error_state) |
|
104 { |
|
105 int len = tmp.length (); |
|
106 |
|
107 double base = tmp(0); |
|
108 |
|
109 for (int i = 1; i < len; i++) |
|
110 { |
|
111 if (tmp(i) != base + i) |
|
112 { |
|
113 gripe_bessel_arg_1 (fn); |
|
114 break; |
|
115 } |
|
116 } |
|
117 |
|
118 if (! error_state) |
|
119 alpha = Range (tmp(0), tmp(len-1)); |
|
120 } |
|
121 } |
|
122 else |
|
123 alpha = alpha_arg.range_value (); |
|
124 |
|
125 if (! error_state) |
|
126 { |
|
127 ColumnVector x = args(1).vector_value (); |
|
128 |
|
129 if (! error_state) |
|
130 DO_BESSEL (type, alpha, x); |
|
131 else |
|
132 error ("%s: expecting vector as second argument", fn); |
|
133 } |
|
134 } |
|
135 } |
|
136 else |
|
137 print_usage (fn); |
|
138 |
|
139 return retval; |
|
140 } |
|
141 |
|
142 DEFUN_DLD (besselj, args, , |
|
143 "besselj (alpha, x)\n\ |
|
144 \n\ |
|
145 Compute Bessel functions of the first kind.\n\ |
|
146 \n\ |
|
147 X must be a real matrix, vector or scalar.\n\ |
|
148 \n\ |
|
149 If ALPHA is a scalar, the result is the same size as X. If ALPHA is a\n\ |
|
150 range, X must be a vector or scalar, and the result is a matrix with\n\ |
|
151 length(X) rows and length(ALPHA) columns.\n\ |
|
152 \n\ |
|
153 ALPHA must be greater than or equal to zero. If ALPHA is a range, it\n\ |
|
154 must have an increment equal to one.") |
|
155 { |
|
156 return do_bessel ('j', "besselj", args); |
|
157 } |
|
158 |
|
159 DEFUN_DLD (bessely, args, , |
|
160 "bessely (alpha, x)\n\ |
|
161 \n\ |
|
162 Compute Bessel functions of the second kind.\n\ |
|
163 \n\ |
|
164 X must be a real matrix, vector or scalar.\n\ |
|
165 \n\ |
|
166 If ALPHA is a scalar, the result is the same size as X. If ALPHA is a\n\ |
|
167 range, X must be a vector or scalar, and the result is a matrix with\n\ |
|
168 length(X) rows and length(ALPHA) columns.\n\ |
|
169 \n\ |
|
170 ALPHA must be greater than or equal to zero. If ALPHA is a range, it\n\ |
|
171 must have an increment equal to one.") |
|
172 { |
|
173 return do_bessel ('y', "bessely", args); |
|
174 } |
|
175 |
|
176 DEFUN_DLD (besseli, args, , |
|
177 "besseli (alpha, x)\n\ |
|
178 \n\ |
|
179 Compute modified Bessel functions of the first kind.\n\ |
|
180 \n\ |
|
181 X must be a real matrix, vector or scalar.\n\ |
|
182 \n\ |
|
183 If ALPHA is a scalar, the result is the same size as X. If ALPHA is a\n\ |
|
184 range, X must be a vector or scalar, and the result is a matrix with\n\ |
|
185 length(X) rows and length(ALPHA) columns.\n\ |
|
186 \n\ |
|
187 ALPHA must be greater than or equal to zero. If ALPHA is a range, it\n\ |
|
188 must have an increment equal to one.") |
|
189 { |
|
190 return do_bessel ('i', "besseli", args); |
|
191 } |
|
192 |
|
193 DEFUN_DLD (besselk, args, , |
|
194 "besselk (alpha, x)\n\ |
|
195 \n\ |
|
196 Compute modified Bessel functions of the second kind.\n\ |
|
197 \n\ |
|
198 X must be a real matrix, vector or scalar.\n\ |
|
199 \n\ |
|
200 If ALPHA is a scalar, the result is the same size as X. If ALPHA is a\n\ |
|
201 range, X must be a vector or scalar, and the result is a matrix with\n\ |
|
202 length(X) rows and length(ALPHA) columns.\n\ |
|
203 \n\ |
|
204 ALPHA must be greater than or equal to zero. If ALPHA is a range, it\n\ |
|
205 must have an increment equal to one.") |
|
206 { |
|
207 return do_bessel ('k', "besselk", args); |
|
208 } |
|
209 |
|
210 /* |
|
211 ;;; Local Variables: *** |
|
212 ;;; mode: C++ *** |
|
213 ;;; End: *** |
|
214 */ |
|
215 |