From 95ec369faed4b9c6c457e77aafdc87179632fff4 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Sat, 6 Jul 2019 17:36:56 -0500 Subject: [PATCH] Migrate aether post from 01331134959 --- _posts/2012-03-07-Cancellation-error.html | 189 ++++++++++++++++++++++ 1 file changed, 189 insertions(+) create mode 100644 _posts/2012-03-07-Cancellation-error.html diff --git a/_posts/2012-03-07-Cancellation-error.html b/_posts/2012-03-07-Cancellation-error.html new file mode 100644 index 0000000..93f2330 --- /dev/null +++ b/_posts/2012-03-07-Cancellation-error.html @@ -0,0 +1,189 @@ +--- +layout: default +title: "Cancellation error" +redirect_from: + - /01331134959 +--- + + + +Cancellation error + + + + + + + + + + + + + + + + +I was recently reminded of the importance of choosing numeric algorithms that +don't behave catastrophically for certain inputs. One example is the +calculation of 1-cos(θ) for small θ. In this case, cos(θ) is very close to 1, +leading to a large +cancellation error in the subtraction step. + +

What is to be done about this? Seek out an equivalent expression that does +not suffer from cancellation error. In this case, employ the double-angle +formula cos(2u) = 1-2sin²(u). This yields the equivalent expression +2sin(θ/2)², which gives good numeric results for θ close to zero. + +

This plot shows how the accuracy of the original formula starts to visibly +degrade at around 1e-7 and gets steadily worse until, at about 1e-8, it +actually drops to 0. + + +

+ +

I wonder whether it would be useful to have a valgrind-like tool warn when +disastrous cancellation occurs, or whether typical programs would have way +too many such errors to ever contemplate fixing them all… +

Entry first conceived on 7 March 2012, 15:42 UTC, last modified on 16 October 2013, 14:35 UTC + + \ No newline at end of file