ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
BesselY.php
Go to the documentation of this file.
1<?php
2
4
7
8class BesselY
9{
27 public static function BESSELY($x, $ord)
28 {
31
32 try {
35 } catch (Exception $e) {
36 return $e->getMessage();
37 }
38
39 if (($ord < 0) || ($x <= 0.0)) {
40 return Functions::NAN();
41 }
42
43 $fBy = self::calculate($x, $ord);
44
45 return (is_nan($fBy)) ? Functions::NAN() : $fBy;
46 }
47
48 private static function calculate(float $x, int $ord): float
49 {
50 // special cases
51 switch ($ord) {
52 case 0:
53 return self::besselY0($x);
54 case 1:
55 return self::besselY1($x);
56 }
57
58 return self::besselY2($x, $ord);
59 }
60
61 private static function besselY0(float $x): float
62 {
63 if ($x < 8.0) {
64 $y = ($x * $x);
65 $ans1 = -2957821389.0 + $y * (7062834065.0 + $y * (-512359803.6 + $y * (10879881.29 + $y *
66 (-86327.92757 + $y * 228.4622733))));
67 $ans2 = 40076544269.0 + $y * (745249964.8 + $y * (7189466.438 + $y *
68 (47447.26470 + $y * (226.1030244 + $y))));
69
70 return $ans1 / $ans2 + 0.636619772 * BesselJ::BESSELJ($x, 0) * log($x);
71 }
72
73 $z = 8.0 / $x;
74 $y = ($z * $z);
75 $xx = $x - 0.785398164;
76 $ans1 = 1 + $y * (-0.1098628627e-2 + $y * (0.2734510407e-4 + $y * (-0.2073370639e-5 + $y * 0.2093887211e-6)));
77 $ans2 = -0.1562499995e-1 + $y * (0.1430488765e-3 + $y * (-0.6911147651e-5 + $y * (0.7621095161e-6 + $y *
78 (-0.934945152e-7))));
79
80 return sqrt(0.636619772 / $x) * (sin($xx) * $ans1 + $z * cos($xx) * $ans2);
81 }
82
83 private static function besselY1(float $x): float
84 {
85 if ($x < 8.0) {
86 $y = ($x * $x);
87 $ans1 = $x * (-0.4900604943e13 + $y * (0.1275274390e13 + $y * (-0.5153438139e11 + $y *
88 (0.7349264551e9 + $y * (-0.4237922726e7 + $y * 0.8511937935e4)))));
89 $ans2 = 0.2499580570e14 + $y * (0.4244419664e12 + $y * (0.3733650367e10 + $y * (0.2245904002e8 + $y *
90 (0.1020426050e6 + $y * (0.3549632885e3 + $y)))));
91
92 return ($ans1 / $ans2) + 0.636619772 * (BesselJ::BESSELJ($x, 1) * log($x) - 1 / $x);
93 }
94
95 $z = 8.0 / $x;
96 $y = $z * $z;
97 $xx = $x - 2.356194491;
98 $ans1 = 1.0 + $y * (0.183105e-2 + $y * (-0.3516396496e-4 + $y * (0.2457520174e-5 + $y * (-0.240337019e-6))));
99 $ans2 = 0.04687499995 + $y * (-0.2002690873e-3 + $y * (0.8449199096e-5 + $y *
100 (-0.88228987e-6 + $y * 0.105787412e-6)));
101
102 return sqrt(0.636619772 / $x) * (sin($xx) * $ans1 + $z * cos($xx) * $ans2);
103 }
104
105 private static function besselY2(float $x, int $ord): float
106 {
107 $fTox = 2.0 / $x;
108 $fBym = self::besselY0($x);
109 $fBy = self::besselY1($x);
110 for ($n = 1; $n < $ord; ++$n) {
111 $fByp = $n * $fTox * $fBy - $fBym;
112 $fBym = $fBy;
113 $fBy = $fByp;
114 }
115
116 return $fBy;
117 }
118}
$n
Definition: RandomTest.php:85
An exception for terminatinating execution or to throw for unit testing.
static flattenSingleValue($value='')
Convert an array to a single scalar value by extracting the first element.
Definition: Functions.php:649
$x
Definition: complexTest.php:9
$y
Definition: example_007.php:83