Ask your own question, for FREE!
Computer Science 17 Online
OpenStudy (anonymous):

Trying to solve Bessel function with C++. http://www.twiddla.com/738376

OpenStudy (asnaseer):

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.

OpenStudy (anonymous):

Source Code: http://ideone.com/Wju5T

OpenStudy (asnaseer):

you erased the formula from twiddla?

OpenStudy (anonymous):

yep, let me draw it again

OpenStudy (asnaseer):

ok - I'm reviewing the code now...

OpenStudy (asnaseer):

where is it going wrong?

OpenStudy (anonymous):

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

OpenStudy (asnaseer):

it may be fruitful to insert some trace statements in your BESSEL function. trace out the values of each component being constructed.

OpenStudy (asnaseer):

you can use std::cout to trace the values out

OpenStudy (asnaseer):

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

OpenStudy (anonymous):

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.

OpenStudy (asnaseer):

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.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!