[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Catastrophic Cancellation
From: |
Rob Mahurin |
Subject: |
Re: Catastrophic Cancellation |
Date: |
Tue, 1 Jul 2008 18:54:39 -0400 |
That's a great example! I love the distinction between the one-bit
and the continuous errors.
In Octave, you don't need the loop, though:
octave-3.0.1> x = 1e-7*linspace(-1,1,1e3);
octave-3.0.1> y = [ (1-cos(x))./x.^2;
1./x.^2 - cos(x)./x.^2;
(1 - x.^2/12)/2;
];
octave-3.0.1> plot(x,y,'o-');
Cheers,
Rob
On Jul 1, 2008, at 5:50 PM, A. Kalten wrote:
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
_______________________________________________
Help-octave mailing list
address@hidden
https://www.cae.wisc.edu/mailman/listinfo/help-octave
--
Rob Mahurin
Dept. of Physics & Astronomy
University of Tennessee phone: 865 207 2594
Knoxville, TN 37996 email: address@hidden
- Catastrophic Cancellation, A. Kalten, 2008/07/01
- Re: Catastrophic Cancellation,
Rob Mahurin <=
- Re: Catastrophic Cancellation, A. Kalten, 2008/07/02
- Re: Catastrophic Cancellation, Jordi GutiƩrrez Hermoso, 2008/07/02
- Re: Catastrophic Cancellation, Sergei Steshenko, 2008/07/02
- Re: Catastrophic Cancellation, A. Kalten, 2008/07/02
- Re: Catastrophic Cancellation, Sergei Steshenko, 2008/07/03
- Re: Catastrophic Cancellation, Rob Mahurin, 2008/07/03
- Re: Catastrophic Cancellation, Sergei Steshenko, 2008/07/04
Re: Catastrophic Cancellation, Francesco Potorti`, 2008/07/03