Catastrophic Cancellation
A. Kalten
akalten at comcast.net
Tue Jul 1 16:50:10 CDT 2008
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
More information about the Help-octave
mailing list