Python Floating point arithmetic and Fourier collocation

AI Thread Summary
The discussion highlights issues related to floating-point arithmetic in numerical computations, specifically in the context of Fourier collocation schemes for nonlinear partial differential equations (PDEs) with periodic boundary conditions. A key point raised is the unexpected non-zero imaginary part resulting from the calculation of exp(1j*pi), which should theoretically yield -1. This non-zero component affects the Nyquist frequency coefficient, which ideally should be purely real, leading to significant discrepancies in the spectrum analysis of what is expected to be a uniform steady state. The discussion emphasizes that while libraries like scipy.fft.rfft may overlook these imaginary components, the presence of such roundoff errors can lead to misleading results, underscoring the importance of careful handling of floating-point calculations in scientific computing.
pasmith
Science Advisor
Homework Helper
Messages
3,338
Reaction score
1,879
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 Mark44 and anorlunda
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...

Similar threads

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