Created
April 18, 2025 08:47
-
-
Save tai2/ce426db0adee85a2b2848e56a56472d5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const bessel = (x, alpha, n) => { | |
if (n < 0) { | |
throw new Error("n must be non-negative"); | |
} | |
if (alpha < 0) { | |
throw new Error("alpha must be non-negative"); | |
} | |
let sum = 0; | |
for (let m = 0; m <= n; m++) { | |
const term = | |
(Math.pow(-1, m) * Math.pow(x / 2, alpha + 2 * m)) / | |
(factorial(m) * factorial(alpha + m)); | |
sum += term; | |
} | |
return sum; | |
}; | |
const factorial = (n) => { | |
if (n < 0) { | |
throw new Error("n must be non-negative"); | |
} | |
if (n === 0 || n === 1) { | |
return 1; | |
} | |
let result = 1; | |
for (let i = 2; i <= n; i++) { | |
result *= i; | |
} | |
return result; | |
}; | |
console.log(bessel(1, 0, 5)); | |
console.log(bessel(1, 1, 5)); | |
console.log(bessel(2, 0, 5)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment