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