Floating point arithmetic and Fourier collocation

In summary, the conversation discusses the issue of non-zero imaginary values in a Fourier collocation scheme for a nonlinear PDE with periodic boundary conditions. This can cause problems with the coefficient corresponding to the Nyquist frequency, which should be purely real but does not remain so due to roundoff error. A simpler example is given with the function sin(pi). It is important to be aware of these issues in floating point arithmetic.
  • #1
pasmith
Science Advisor
Homework Helper
3,256
1,814
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 [itex]10^{100}[/itex].
 
Technology news on Phys.org
  • #2
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 Mark44 and anorlunda

FAQ: Floating point arithmetic and Fourier collocation

What is floating point arithmetic?

Floating point arithmetic is a method of performing numerical calculations on real numbers using a fixed number of digits. This allows for a wide range of values to be represented, but also introduces rounding errors due to the limited precision.

What is the significance of floating point arithmetic in scientific computing?

Floating point arithmetic is essential in scientific computing because it allows for the representation of real-world quantities with a high degree of accuracy. This is particularly important in fields such as physics and engineering where precise calculations are necessary for accurate results.

What is Fourier collocation?

Fourier collocation is a numerical method used to solve differential equations by approximating the solution as a sum of trigonometric functions. This method is particularly useful for problems with periodic boundary conditions.

How does Fourier collocation relate to floating point arithmetic?

In Fourier collocation, the accuracy of the solution depends heavily on the precision of the floating point arithmetic used. Rounding errors in floating point arithmetic can lead to significant errors in the solution, so it is important to use high precision arithmetic when implementing this method.

Are there any limitations to using floating point arithmetic and Fourier collocation?

One limitation of floating point arithmetic is that it cannot represent all real numbers exactly, leading to potential rounding errors. In addition, Fourier collocation may not be suitable for all types of differential equations, particularly those with irregular or non-periodic solutions.

Similar threads

Replies
7
Views
3K
Replies
4
Views
5K
Replies
1
Views
2K
Replies
2
Views
1K
Replies
13
Views
2K
Replies
2
Views
4K
Back
Top