Skip to content
DeepForgeby svx
All problems
MediumCalculusca-121

Bessel J0 Series Value

Problem

Evaluate the Bessel function of the first kind J0(x) with its power series to n terms:

J0(x) ≈ sum from k = 0 to n-1 of (-1)^k * (x/2)^(2k) / (k!)^2

Accumulate the terms iteratively using the ratio -(x^2/4) / (k+1)^2.

Hint

J0 is an even function, so only even powers of x appear.

Test cases

case 1
in: [0,5]
expected: 1
case 2
in: [1,10]
expected: 0.7651976865579666
case 3
in: [2,15]
expected: 0.22389077914123562
case 4
in: [5,20]
expected: -0.17759677131433846
case 5
in: [10,25]
expected: -0.24593576445137094
Starter codePython
def bessel_j0(x, n):
    # Your code here
    pass

5 test cases · run your code against them in the editor