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