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));