Take the 2-minute tour ×
Physics Stack Exchange is a question and answer site for active researchers, academics and students of physics. It's 100% free, no registration required.

I have written a program in cpp that computes the magnetic field at a point from a current carrying loop. It uses the biot savart law and the monte carlo technique to carry out the integral. The program functions as expected for points that are not too close to the loop but from looking at a plot of the vectors you can see strange errors close to the loop.

I checked my results against http://hyperphysics.phy-astr.gsu.edu/hbase/magnetic/curloo.html#c3 for a point on the axis and http://www.netdenizen.com/emagnet/offaxis/iloopcalculator.htm for a point off the axis. My program agrees with these sources for points not too close to the loop.

This is my code. http://pastebin.com/4BH9qEZz

My main question is if there is anything inherent in the monte carlo technique that would cause this error?

share|improve this question
add comment

1 Answer 1

up vote 4 down vote accepted

If you're very close to the loop, there is a small range of theta that provides almost all of the field. When you're randomly choosing points, a relatively small fraction of those points will happen to be in that crucial range. This will amplify the random sampling error. In other words, the closer you get to the loop, the larger the number of sample points required in order to get a reasonable accuracy.

I suggest to increase the number of sample points and see if the answer gets more accurate. If not, then probably you have a formula error or coding error.

If the number of sample points required is too large, maybe uniform random sampling is a bad strategy. You can use a modified Monte Carlo technique where there is a weighting function, making some theta's more likely to occur than others. Or just don't use Monte Carlo. :-)

share|improve this answer
    
Thank you that I ran the simulation overnight and got better results so you are probably right. If I have time I will try a weighting function, thanks again. –  user1750289 Nov 21 '12 at 8:03
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.