Roundoff error - double precision is not enough

  • Thread starter Thread starter coccoinomane
  • Start date Start date
  • Tags Tags
    Error Precision
AI Thread Summary
The discussion centers on the challenges of computing functions involving sine and cosine when both variables approach zero, leading to significant roundoff errors in double precision calculations. The user has successfully reformulated one function as a spherical Bessel function, which can be accurately computed using the GNU Scientific Library. However, they still face precision issues with their integral calculations and seek advice on high-precision C++ libraries. Suggestions include using power series expansions for sine and cosine to improve accuracy for small values of rx. The user acknowledges improvements in their results but remains concerned about potential precision loss in their computations.
coccoinomane
Messages
19
Reaction score
0
Hi everybody!

I kindly request your help. I have to compute functions like

\frac{ \sin (r x) - r x \cos (r x)}{r^3}
(primitive function of x sin(rx) )

or

\frac{ -r x (120 - 20 r^2 x^2 + r^4 x^4) cos(r x) + <br /> 5 (24 - 12 r^2 x^2 + r^4 x^4) \sin(r x)}{r^7}
(primitive function of x^5 sin(rx) )

when both r and x varies.

The problem with these functions is that the sin and cos factors are very similar to each other when x approaches zero. This is a big issue: double precision is not enough to compute the difference because of roundoff errors or simply because 14-15 digits are not enough to distinguish the two factors.

I kind of solved the problem for the first function. In fact, I could express it up to a factor as the first order spherical bessel function:

j1(x) = \frac{\sin(x)/x - \cos(x)}{x},

which is well computed in the GNU Scientific Library.

I need to calculate those functions to solve the integral I discussed in https://www.physicsforums.com/showthread.php?p=2028408#post2028408 and that uart helped me to solve.

Thank you very much for any suggestion,

Guido
 
Last edited:
Mathematics news on Phys.org
I forgot to mention that I need to compute the functions for a very large array of "r" values from within a C++ program. Thus, pasting the result from Mathematica is not helpful :)

Cheers,

Guido
 
The problem you have is essentially in the numerators of your expressions when rx is small. I suggest that you (on paper) use the power series for sin and cos, where the terms in rx cancel for your expressions. Programming in the cubic term and possibly the fifth order (depending on how precise you want it) should be sufficient for small rx.
 
or use any of the high precision c++ libraries...
 
Hi mathman, thank you for your answer. You are right indeed.
I tried to expand the sine & cosine as my first approach, but I made a stupid mistake in the calculation of the coefficients and I got wrong results. I re-did everything and now I get results as precise as 10^-6. Thank you!

@NoDoubts
Could you please point me to some of these libraries?
However, I am not sure it would help. Unless they have computed the same function I need, i.e.

<br /> \int_{0}^{k_0} k^{n} \frac{sin{kr}}{kr} dk<br />

(and GSL doesn't have), I am afraid the precision problem would pop up again. However precise can the library be, it boils down to a difference between very small numbers --> loss of precision.

Cheers,

Guido
 
Suppose ,instead of the usual x,y coordinate system with an I basis vector along the x -axis and a corresponding j basis vector along the y-axis we instead have a different pair of basis vectors ,call them e and f along their respective axes. I have seen that this is an important subject in maths My question is what physical applications does such a model apply to? I am asking here because I have devoted quite a lot of time in the past to understanding convectors and the dual...
Insights auto threads is broken atm, so I'm manually creating these for new Insight articles. In Dirac’s Principles of Quantum Mechanics published in 1930 he introduced a “convenient notation” he referred to as a “delta function” which he treated as a continuum analog to the discrete Kronecker delta. The Kronecker delta is simply the indexed components of the identity operator in matrix algebra Source: https://www.physicsforums.com/insights/what-exactly-is-diracs-delta-function/ by...
Back
Top