Trying to solve Bessel function with C++. http://www.twiddla.com/738376
you can post your source code at http://ideone.com/ and then post a link to it here. I think that would be easier to read than at twiddla.
you erased the formula from twiddla?
yep, let me draw it again
ok - I'm reviewing the code now...
where is it going wrong?
in the BESSEL function, it seems i get an infinite loop. I want the loop to stop when the absolute number of a part of the sum is less than 10^(-12).
it may be fruitful to insert some trace statements in your BESSEL function. trace out the values of each component being constructed.
you can use std::cout to trace the values out
on a separate note, the function could be made more efficient by not computing \((-1)^{m}\) but instead having an integer that just toggles between 1 and -1, e.g.: int numerator =1 while (...) { sm = ... numerator = -numerator; }
I changed \[(-1)^m\] with num and that seems to solve the infinite loop problem. I don't know why. But stills the BESSEL function doesn't work for n=2.
What you should try and do is write some unit tests for each of the methods you have created to ensure they are working as expected. Also, as I suggested above, tracing out the values while looping in the BESSEL function might help you spot where the problem is.
Join our real-time social learning platform and learn together with your friends!