help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Catastrophic Cancellation


From: A. Kalten
Subject: Catastrophic Cancellation
Date: Tue, 1 Jul 2008 17:50:10 -0400

Just to spread some awareness of the pitfalls of floating point
calculations, I urge everyone to try this simple test.  At the
octave prompt enter:

x=-4e-8:1e-10:4e-8;
for i=1:length(x)
y(i)=(1-cos(x(i)))/x(i)/x(i);
endfor
plot(x,y)

Hopefully, the results should surprise, or even shock, you.

Also try rewriting the above function as: y(i)=1/x(i)/x(i)-cos(x(i))/x(i)/x(i)

For more info, the link is here:

http://www.cs.princeton.edu/introcs/lectures/9scientific.pdf

AK



reply via email to

[Prev in Thread] Current Thread [Next in Thread]