You are here
A funny error
Dear All,I have written a finite element code in C++. The results have generally high accuracy. But when I change the order of evaluating r and theta of the polar coordinates in terms of x and y in the sub-program of computing the shape functions, then the results are changed about 10^-9 of the initial results. The change is negligible but I wonder why this happens? I had initially supposed it may be related to some memory linkage in the program but since now I have not been successful to find any. Is there any one to have an idea about this funny error???
- Arash Zamani's blog
- Log in or register to post comments
- 3092 reads
Comments
Dear Zamani,
Well it is hard to tell! But generally speaking loss of precision is due to the finite nature of number representation in computers (I mean when bugs are out). Some operations are more prone to introduce errors that others, and divisions are of those. I suppose that, in order to convert your coordinates to polar one you use some division, by a square root don't you? May be you could try the following trick and let me know what it does. Assume that you want to compute r = sqrt(x*x+y*y), then you should use the following algorithm http://en.wikipedia.org/wiki/Hypot
Best Regards,
Thomas Laverne
My blog on research on Hybrid Solvers: http://mechenjoy.blogspot.com/