I was recently trying the Hamiltonian Simulation Codebook and ran into an issue, where it says I’m not producing the correct type of output.
My code is as follows:
`bessel_1 = [
0.7651976865579666,
0.44005058574493355,
0.1149034849319005,
0.019563353982668414,
]
def approximation_error(theta):
"""
Returns the absolute error in the Jacobi-Anger expansion
Args:
- theta (float): The angle argument of the expansion.
Returns:
- (float): The absolute error.
"""
####################
###YOUR CODE HERE###
####################
exact = np.exp(1j * np.cos(theta))
approx = 0
for n in range(-3, 0):
approx +=(-1)**(np.abs(n))*((1j) ** (n)) * (bessel_1[np.abs(n)]) * np.exp(1j * n * theta)
for n in range(0, 4):
approx += (1j) ** (n) * (bessel_1[n]) * np.exp(1j * n * theta)
return np.abs(exact - approx)`
I tried comparing it to the result when using the Scipy Bessel function, and it yields the same result, so I think it is correct in that front. The typing of my result is also type float, so I’m not sure where exactly the error resides.
Also, I believe the description text needs updating with regards to the behaviour of the bessel function. J-n(z)=(-1)^(n)Jn(z)