Floating point arithmetic and Fourier collocation

Click For Summary
SUMMARY

The discussion centers on the challenges of floating point arithmetic in the context of Fourier collocation methods for nonlinear partial differential equations (PDEs) with periodic boundary conditions. A specific example using NumPy's exponential function demonstrates that the imaginary part of the result is not zero, leading to significant roundoff errors that affect the Nyquist frequency coefficient. Although the SciPy FFT implementation ignores the imaginary part, the presence of such errors can mislead users into believing they have a uniform steady state when, in fact, the magnitude of the coefficient can be astronomically large. This highlights the importance of understanding floating point precision in numerical computations.

PREREQUISITES
  • Familiarity with Fourier collocation methods for nonlinear PDEs
  • Understanding of floating point arithmetic and its implications
  • Experience with Python libraries such as NumPy and SciPy
  • Knowledge of periodic boundary conditions in numerical simulations
NEXT STEPS
  • Explore the implications of roundoff errors in numerical simulations
  • Learn about the behavior of coefficients in Fourier transforms using SciPy's FFT functions
  • Investigate strategies to mitigate floating point precision issues in numerical analysis
  • Study the implementation of periodic boundary conditions in computational models
USEFUL FOR

Mathematicians, physicists, and engineers working with numerical simulations, particularly those dealing with nonlinear PDEs and Fourier analysis, will benefit from this discussion.

pasmith
Science Advisor
Homework Helper
Messages
3,345
Reaction score
1,889
Python:
>>> from numpy import exp, pi
>>> exp(1j*pi)
(-1+1.2246467991473532e-16j)

The fact that the imaginary part of this is not zero is wrecking a fourier collocation scheme for a nonlinear PDE with periodic boundary conditions: the coefficient corresponding to the Nyquist frequency, which should be purely real, does not remain so. This had no bearing on the physical quantity, because scipy.fft.rfft apparently ignores the imaginary part of this coefficient, but it was disconcerting to look at the spectrum of what was apparently a uniform final steady state and find that the magnitude of this coefficient was on the order of 10^{100}.
 
Technology news on Phys.org
It's that pesky roundoff error again. A simpler illustration is
Python:
>>> from math import sin, pi
>>> sin(pi)
1.2246467991473532e-16
Don't go out into the world of floating point arithmetic without your big boy trousers on.
 
  • Haha
Likes   Reactions: Mark44 and anorlunda

Similar threads

  • · Replies 7 ·
Replies
7
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 13 ·
Replies
13
Views
3K