Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Calculating spherical Bessel functions

  1. Jan 23, 2006 #1
    I'm not really sure which forum this is appropriate for, so I'll put it here and hope someone can help! I can't find the link to the LaTeX guide that used to be in General Physics (I think), so underscores will have to do for saying something is a subscript.

    I have to write a program to calculate the spherical Bessel function, j_l (actually, I need to calculate j_5(x) for x = 0.1, 1 and 10). We are given a recursion relation:

    j_(l - 1) = (j_l)*(2l + 1)/x - j_(l + 1)

    We're also told that j_0 = (sin x)/x and that we should pick values for "large" l, so we can define j_l = j_(l + 1) = 1. I've tried l = 100 and have written a program as follows (in C++):

    The user is prompted for a value of x and then the value of j_0 is calculated. I then declare and initialise 4 variables, one to hold each of j_l, j_(l + 1), j_(l - 1) and j_5 when it's found. The first two are given the value one (since we're given that) and the other two the value 0 (for the time being).

    Then, I have a for loop that decrements l each time through, going from 100 to 1 so that the value of j_(l - 1) can be calculated from j_(l + 1) and j_l (so when l = 100, the value of j_99 is calculated). The problem is, the values are too high:

    j_99 = 2009
    j_98 = 3.9979 x 10^6
    j_5 = 1.288 x 10^280! (Maple and MathCad tell me I should have a value of 2.60 x 10^-9).

    We're also told that we have to scale our values by j_0 (so have to compare the calculated value from the loop, with that calculated after the user entered the value for x). The one I get from the loop is of the order 1 x 10^289, whereas when I do the normal calculation, I get a value close to 1 (which is very close to what Maple tells me).

    I don't think the problem is with my code, because I get the same results when doing the calculation on paper (well, I only did the first few, I didn't go all the way to j_5).

    Where am I going wrong? Perhaps using a too high value of l? We weren't given a definition of "large", the word is in inverted commas on the sheet and that suggests that it probably shouldn't be too large. Even with using l = 10, I get j_5 = 1 x 10^11.

    Any help appreciated.
  2. jcsd
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?
Draft saved Draft deleted