1math::special(n) Tcl Math Library math::special(n)
2
3
4
5______________________________________________________________________________
6
8 math::special - Special mathematical functions
9
11 package require Tcl ?8.5?
12
13 package require math::special ?0.4?
14
15 ::math::special::Beta x y
16
17 ::math::special::incBeta a b x
18
19 ::math::special::regIncBeta a b x
20
21 ::math::special::Gamma x
22
23 ::math::special::digamma x
24
25 ::math::special::erf x
26
27 ::math::special::erfc x
28
29 ::math::special::invnorm p
30
31 ::math::special::J0 x
32
33 ::math::special::J1 x
34
35 ::math::special::Jn n x
36
37 ::math::special::J1/2 x
38
39 ::math::special::J-1/2 x
40
41 ::math::special::I_n x
42
43 ::math::special::cn u k
44
45 ::math::special::dn u k
46
47 ::math::special::sn u k
48
49 ::math::special::elliptic_K k
50
51 ::math::special::elliptic_E k
52
53 ::math::special::exponential_Ei x
54
55 ::math::special::exponential_En n x
56
57 ::math::special::exponential_li x
58
59 ::math::special::exponential_Ci x
60
61 ::math::special::exponential_Si x
62
63 ::math::special::exponential_Chi x
64
65 ::math::special::exponential_Shi x
66
67 ::math::special::fresnel_C x
68
69 ::math::special::fresnel_S x
70
71 ::math::special::sinc x
72
73 ::math::special::legendre n
74
75 ::math::special::chebyshev n
76
77 ::math::special::laguerre alpha n
78
79 ::math::special::hermite n
80
81______________________________________________________________________________
82
84 This package implements several so-called special functions, like the
85 Gamma function, the Bessel functions and such.
86
87 Each function is implemented by a procedure that bears its name (well,
88 in close approximation):
89
90 • J0 for the zeroth-order Bessel function of the first kind
91
92 • J1 for the first-order Bessel function of the first kind
93
94 • Jn for the nth-order Bessel function of the first kind
95
96 • J1/2 for the half-order Bessel function of the first kind
97
98 • J-1/2 for the minus-half-order Bessel function of the first kind
99
100 • I_n for the modified Bessel function of the first kind of order
101 n
102
103 • Gamma for the Gamma function, erf and erfc for the error func‐
104 tion and the complementary error function
105
106 • fresnel_C and fresnel_S for the Fresnel integrals
107
108 • elliptic_K and elliptic_E (complete elliptic integrals)
109
110 • exponent_Ei and other functions related to the so-called expo‐
111 nential integrals
112
113 • legendre, hermite: some of the classical orthogonal polynomials.
114
116 In the following table several characteristics of the functions in this
117 package are summarized: the domain for the argument, the values for the
118 parameters and error bounds.
119
120
121 Family | Function | Domain x | Parameter | Error bound
122 -------------+-------------+-------------+-------------+--------------
123 Bessel | J0, J1, | all of R | n = integer | < 1.0e-8
124 | Jn | | | (|x|<20, n<20)
125 Bessel | J1/2, J-1/2,| x > 0 | n = integer | exact
126 Bessel | I_n | all of R | n = integer | < 1.0e-6
127 | | | |
128 Elliptic | cn | 0 <= x <= 1 | -- | < 1.0e-10
129 functions | dn | 0 <= x <= 1 | -- | < 1.0e-10
130 | sn | 0 <= x <= 1 | -- | < 1.0e-10
131 Elliptic | K | 0 <= x < 1 | -- | < 1.0e-6
132 integrals | E | 0 <= x < 1 | -- | < 1.0e-6
133 | | | |
134 Error | erf | | -- |
135 functions | erfc | | |
136 | | | |
137 Inverse | invnorm | 0 < x < 1 | -- | < 1.2e-9
138 normal | | | |
139 distribution | | | |
140 | | | |
141 Exponential | Ei | x != 0 | -- | < 1.0e-10 (relative)
142 integrals | En | x > 0 | -- | as Ei
143 | li | x > 0 | -- | as Ei
144 | Chi | x > 0 | -- | < 1.0e-8
145 | Shi | x > 0 | -- | < 1.0e-8
146 | Ci | x > 0 | -- | < 2.0e-4
147 | Si | x > 0 | -- | < 2.0e-4
148 | | | |
149 Fresnel | C | all of R | -- | < 2.0e-3
150 integrals | S | all of R | -- | < 2.0e-3
151 | | | |
152 general | Beta | (see Gamma) | -- | < 1.0e-9
153 | Gamma | x != 0,-1, | -- | < 1.0e-9
154 | | -2, ... | |
155 | incBeta | | a, b > 0 | < 1.0e-9
156 | regIncBeta | | a, b > 0 | < 1.0e-9
157 | digamma | x != 0,-1 | | < 1.0e-9
158 | | -2, ... | |
159 | | | |
160 | sinc | all of R | -- | exact
161 | | | |
162 orthogonal | Legendre | all of R | n = 0,1,... | exact
163 polynomials | Chebyshev | all of R | n = 0,1,... | exact
164 | Laguerre | all of R | n = 0,1,... | exact
165 | | | alpha el. R |
166 | Hermite | all of R | n = 0,1,... | exact
167
168 Note: Some of the error bounds are estimated, as no "formal" bounds
169 were available with the implemented approximation method, others hold
170 for the auxiliary functions used for estimating the primary functions.
171
172 The following well-known functions are currently missing from the pack‐
173 age:
174
175 • Bessel functions of the second kind (Y_n, K_n)
176
177 • Bessel functions of arbitrary order (and hence the Airy func‐
178 tions)
179
180 • Chebyshev polynomials of the second kind (U_n)
181
182 • The incomplete gamma function
183
185 The package defines the following public procedures:
186
187 ::math::special::Beta x y
188 Compute the Beta function for arguments "x" and "y"
189
190 float x
191 First argument for the Beta function
192
193 float y
194 Second argument for the Beta function
195
196
197 ::math::special::incBeta a b x
198 Compute the incomplete Beta function for argument "x" with pa‐
199 rameters "a" and "b"
200
201 float a
202 First parameter for the incomplete Beta function, a > 0
203
204 float b
205 Second parameter for the incomplete Beta function, b > 0
206
207 float x
208 Argument for the incomplete Beta function
209
210
211 ::math::special::regIncBeta a b x
212 Compute the regularized incomplete Beta function for argument
213 "x" with parameters "a" and "b"
214
215 float a
216 First parameter for the incomplete Beta function, a > 0
217
218 float b
219 Second parameter for the incomplete Beta function, b > 0
220
221 float x
222 Argument for the regularized incomplete Beta function
223
224
225 ::math::special::Gamma x
226 Compute the Gamma function for argument "x"
227
228 float x
229 Argument for the Gamma function
230
231
232 ::math::special::digamma x
233 Compute the digamma function (psi) for argument "x"
234
235 float x
236 Argument for the digamma function
237
238
239 ::math::special::erf x
240 Compute the error function for argument "x"
241
242 float x
243 Argument for the error function
244
245
246 ::math::special::erfc x
247 Compute the complementary error function for argument "x"
248
249 float x
250 Argument for the complementary error function
251
252
253 ::math::special::invnorm p
254 Compute the inverse of the normal distribution function for ar‐
255 gument "p"
256
257 float p
258 Argument for the inverse normal distribution function (p
259 must be greater than 0 and lower than 1)
260
261
262 ::math::special::J0 x
263 Compute the zeroth-order Bessel function of the first kind for
264 the argument "x"
265
266 float x
267 Argument for the Bessel function
268
269 ::math::special::J1 x
270 Compute the first-order Bessel function of the first kind for
271 the argument "x"
272
273 float x
274 Argument for the Bessel function
275
276 ::math::special::Jn n x
277 Compute the nth-order Bessel function of the first kind for the
278 argument "x"
279
280 integer n
281 Order of the Bessel function
282
283 float x
284 Argument for the Bessel function
285
286 ::math::special::J1/2 x
287 Compute the half-order Bessel function of the first kind for the
288 argument "x"
289
290 float x
291 Argument for the Bessel function
292
293 ::math::special::J-1/2 x
294 Compute the minus-half-order Bessel function of the first kind
295 for the argument "x"
296
297 float x
298 Argument for the Bessel function
299
300 ::math::special::I_n x
301 Compute the modified Bessel function of the first kind of order
302 n for the argument "x"
303
304 int x Positive integer order of the function
305
306 float x
307 Argument for the function
308
309 ::math::special::cn u k
310 Compute the elliptic function cn for the argument "u" and param‐
311 eter "k".
312
313 float u
314 Argument for the function
315
316 float k
317 Parameter
318
319 ::math::special::dn u k
320 Compute the elliptic function dn for the argument "u" and param‐
321 eter "k".
322
323 float u
324 Argument for the function
325
326 float k
327 Parameter
328
329 ::math::special::sn u k
330 Compute the elliptic function sn for the argument "u" and param‐
331 eter "k".
332
333 float u
334 Argument for the function
335
336 float k
337 Parameter
338
339 ::math::special::elliptic_K k
340 Compute the complete elliptic integral of the first kind for the
341 argument "k"
342
343 float k
344 Argument for the function
345
346 ::math::special::elliptic_E k
347 Compute the complete elliptic integral of the second kind for
348 the argument "k"
349
350 float k
351 Argument for the function
352
353 ::math::special::exponential_Ei x
354 Compute the exponential integral of the second kind for the ar‐
355 gument "x"
356
357 float x
358 Argument for the function (x != 0)
359
360 ::math::special::exponential_En n x
361 Compute the exponential integral of the first kind for the argu‐
362 ment "x" and order n
363
364 int n Order of the integral (n >= 0)
365
366 float x
367 Argument for the function (x >= 0)
368
369 ::math::special::exponential_li x
370 Compute the logarithmic integral for the argument "x"
371
372 float x
373 Argument for the function (x > 0)
374
375 ::math::special::exponential_Ci x
376 Compute the cosine integral for the argument "x"
377
378 float x
379 Argument for the function (x > 0)
380
381 ::math::special::exponential_Si x
382 Compute the sine integral for the argument "x"
383
384 float x
385 Argument for the function (x > 0)
386
387 ::math::special::exponential_Chi x
388 Compute the hyperbolic cosine integral for the argument "x"
389
390 float x
391 Argument for the function (x > 0)
392
393 ::math::special::exponential_Shi x
394 Compute the hyperbolic sine integral for the argument "x"
395
396 float x
397 Argument for the function (x > 0)
398
399 ::math::special::fresnel_C x
400 Compute the Fresnel cosine integral for real argument x
401
402 float x
403 Argument for the function
404
405 ::math::special::fresnel_S x
406 Compute the Fresnel sine integral for real argument x
407
408 float x
409 Argument for the function
410
411 ::math::special::sinc x
412 Compute the sinc function for real argument x
413
414 float x
415 Argument for the function
416
417 ::math::special::legendre n
418 Return the Legendre polynomial of degree n (see THE ORTHOGONAL
419 POLYNOMIALS)
420
421 int n Degree of the polynomial
422
423
424 ::math::special::chebyshev n
425 Return the Chebyshev polynomial of degree n (of the first kind)
426
427 int n Degree of the polynomial
428
429
430 ::math::special::laguerre alpha n
431 Return the Laguerre polynomial of degree n with parameter alpha
432
433 float alpha
434 Parameter of the Laguerre polynomial
435
436 int n Degree of the polynomial
437
438
439 ::math::special::hermite n
440 Return the Hermite polynomial of degree n
441
442 int n Degree of the polynomial
443
444
446 For dealing with the classical families of orthogonal polynomials, the
447 package relies on the math::polynomials package. To evaluate the poly‐
448 nomial at some coordinate, use the evalPolyn command:
449
450
451 set leg2 [::math::special::legendre 2]
452 puts "Value at x=$x: [::math::polynomials::evalPolyn $leg2 $x]"
453
454
455 The return value from the legendre and other commands is actually the
456 definition of the corresponding polynomial as used in that package.
457
459 It should be noted, that the actual implementation of J0 and J1 depends
460 on straightforward Gaussian quadrature formulas. The (absolute) accu‐
461 racy of the results is of the order 1.0e-4 or better. The main reason
462 to implement them like that was that it was fast to do (the formulas
463 are simple) and the computations are fast too.
464
465 The implementation of J1/2 does not suffer from this: this function can
466 be expressed exactly in terms of elementary functions.
467
468 The functions J0 and J1 are the ones you will encounter most frequently
469 in practice.
470
471 The computation of I_n is based on Miller's algorithm for computing the
472 minimal function from recurrence relations.
473
474 The computation of the Gamma and Beta functions relies on the combina‐
475 torics package, whereas that of the error functions relies on the sta‐
476 tistics package.
477
478 The computation of the complete elliptic integrals uses the AGM algo‐
479 rithm.
480
481 Much information about these functions can be found in:
482
483 Abramowitz and Stegun: Handbook of Mathematical Functions (Dover, ISBN
484 486-61272-4)
485
487 This document, and the package it describes, will undoubtedly contain
488 bugs and other problems. Please report such in the category math ::
489 special of the Tcllib Trackers [http://core.tcl.tk/tcllib/reportlist].
490 Please also report any ideas for enhancements you may have for either
491 package and/or documentation.
492
493 When proposing code changes, please provide unified diffs, i.e the out‐
494 put of diff -u.
495
496 Note further that attachments are strongly preferred over inlined
497 patches. Attachments can be made by going to the Edit form of the
498 ticket immediately after its creation, and then using the left-most
499 button in the secondary navigation bar.
500
502 Bessel functions, error function, math, special functions
503
505 Mathematics
506
508 Copyright (c) 2004 Arjen Markus <arjenmarkus@users.sourceforge.net>
509
510
511
512
513tcllib 0.4 math::special(n)