wpdatatables
/
lib
/
phpoffice
/
phpspreadsheet
/
src
/
PhpSpreadsheet
/
Calculation
/
Engineering
/
BesselY.php
BesselY.php in wpDataTables – WordPress Data Table, Dynamic Tables & Table Charts Plugin 6.5.1.7, at lib/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Calculation/Engineering/BesselY.php
| 1 | <?php |
| 2 | |
| 3 | namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering; |
| 4 | |
| 5 | use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled; |
| 6 | use PhpOffice\PhpSpreadsheet\Calculation\Exception; |
| 7 | use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; |
| 8 | |
| 9 | class BesselY |
| 10 | { |
| 11 | use ArrayEnabled; |
| 12 | |
| 13 | /** |
| 14 | * BESSELY. |
| 15 | * |
| 16 | * Returns the Bessel function, which is also called the Weber function or the Neumann function. |
| 17 | * |
| 18 | * Excel Function: |
| 19 | * BESSELY(x,ord) |
| 20 | * |
| 21 | * @param mixed $x A float value at which to evaluate the function. |
| 22 | * If x is nonnumeric, BESSELY returns the #VALUE! error value. |
| 23 | * Or can be an array of values |
| 24 | * @param mixed $ord The integer order of the Bessel function. |
| 25 | * If ord is not an integer, it is truncated. |
| 26 | * If $ord is nonnumeric, BESSELY returns the #VALUE! error value. |
| 27 | * If $ord < 0, BESSELY returns the #NUM! error value. |
| 28 | * Or can be an array of values |
| 29 | * |
| 30 | * @return array|float|string Result, or a string containing an error |
| 31 | * If an array of numbers is passed as an argument, then the returned result will also be an array |
| 32 | * with the same dimensions |
| 33 | */ |
| 34 | public static function BESSELY($x, $ord) |
| 35 | { |
| 36 | if (is_array($x) || is_array($ord)) { |
| 37 | return self::evaluateArrayArguments([self::class, __FUNCTION__], $x, $ord); |
| 38 | } |
| 39 | |
| 40 | try { |
| 41 | $x = EngineeringValidations::validateFloat($x); |
| 42 | $ord = EngineeringValidations::validateInt($ord); |
| 43 | } catch (Exception $e) { |
| 44 | return $e->getMessage(); |
| 45 | } |
| 46 | |
| 47 | if (($ord < 0) || ($x <= 0.0)) { |
| 48 | return ExcelError::NAN(); |
| 49 | } |
| 50 | |
| 51 | $fBy = self::calculate($x, $ord); |
| 52 | |
| 53 | return (is_nan($fBy)) ? ExcelError::NAN() : $fBy; |
| 54 | } |
| 55 | |
| 56 | private static function calculate(float $x, int $ord): float |
| 57 | { |
| 58 | // special cases |
| 59 | switch ($ord) { |
| 60 | case 0: |
| 61 | return self::besselY0($x); |
| 62 | case 1: |
| 63 | return self::besselY1($x); |
| 64 | } |
| 65 | |
| 66 | return self::besselY2($x, $ord); |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Mollify Phpstan. |
| 71 | * |
| 72 | * @codeCoverageIgnore |
| 73 | */ |
| 74 | private static function callBesselJ(float $x, int $ord): float |
| 75 | { |
| 76 | $rslt = BesselJ::BESSELJ($x, $ord); |
| 77 | if (!is_float($rslt)) { |
| 78 | throw new Exception('Unexpected array or string'); |
| 79 | } |
| 80 | |
| 81 | return $rslt; |
| 82 | } |
| 83 | |
| 84 | private static function besselY0(float $x): float |
| 85 | { |
| 86 | if ($x < 8.0) { |
| 87 | $y = ($x * $x); |
| 88 | $ans1 = -2957821389.0 + $y * (7062834065.0 + $y * (-512359803.6 + $y * (10879881.29 + $y * |
| 89 | (-86327.92757 + $y * 228.4622733)))); |
| 90 | $ans2 = 40076544269.0 + $y * (745249964.8 + $y * (7189466.438 + $y * |
| 91 | (47447.26470 + $y * (226.1030244 + $y)))); |
| 92 | |
| 93 | return $ans1 / $ans2 + 0.636619772 * self::callBesselJ($x, 0) * log($x); |
| 94 | } |
| 95 | |
| 96 | $z = 8.0 / $x; |
| 97 | $y = ($z * $z); |
| 98 | $xx = $x - 0.785398164; |
| 99 | $ans1 = 1 + $y * (-0.1098628627e-2 + $y * (0.2734510407e-4 + $y * (-0.2073370639e-5 + $y * 0.2093887211e-6))); |
| 100 | $ans2 = -0.1562499995e-1 + $y * (0.1430488765e-3 + $y * (-0.6911147651e-5 + $y * (0.7621095161e-6 + $y * |
| 101 | (-0.934945152e-7)))); |
| 102 | |
| 103 | return sqrt(0.636619772 / $x) * (sin($xx) * $ans1 + $z * cos($xx) * $ans2); |
| 104 | } |
| 105 | |
| 106 | private static function besselY1(float $x): float |
| 107 | { |
| 108 | if ($x < 8.0) { |
| 109 | $y = ($x * $x); |
| 110 | $ans1 = $x * (-0.4900604943e13 + $y * (0.1275274390e13 + $y * (-0.5153438139e11 + $y * |
| 111 | (0.7349264551e9 + $y * (-0.4237922726e7 + $y * 0.8511937935e4))))); |
| 112 | $ans2 = 0.2499580570e14 + $y * (0.4244419664e12 + $y * (0.3733650367e10 + $y * (0.2245904002e8 + $y * |
| 113 | (0.1020426050e6 + $y * (0.3549632885e3 + $y))))); |
| 114 | |
| 115 | return ($ans1 / $ans2) + 0.636619772 * (self::callBesselJ($x, 1) * log($x) - 1 / $x); |
| 116 | } |
| 117 | |
| 118 | $z = 8.0 / $x; |
| 119 | $y = $z * $z; |
| 120 | $xx = $x - 2.356194491; |
| 121 | $ans1 = 1.0 + $y * (0.183105e-2 + $y * (-0.3516396496e-4 + $y * (0.2457520174e-5 + $y * (-0.240337019e-6)))); |
| 122 | $ans2 = 0.04687499995 + $y * (-0.2002690873e-3 + $y * (0.8449199096e-5 + $y * |
| 123 | (-0.88228987e-6 + $y * 0.105787412e-6))); |
| 124 | |
| 125 | return sqrt(0.636619772 / $x) * (sin($xx) * $ans1 + $z * cos($xx) * $ans2); |
| 126 | } |
| 127 | |
| 128 | private static function besselY2(float $x, int $ord): float |
| 129 | { |
| 130 | $fTox = 2.0 / $x; |
| 131 | $fBym = self::besselY0($x); |
| 132 | $fBy = self::besselY1($x); |
| 133 | for ($n = 1; $n < $ord; ++$n) { |
| 134 | $fByp = $n * $fTox * $fBy - $fBym; |
| 135 | $fBym = $fBy; |
| 136 | $fBy = $fByp; |
| 137 | } |
| 138 | |
| 139 | return $fBy; |
| 140 | } |
| 141 | } |
| 142 |