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 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
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