3 ms·
> The quadratic equation violated the cardinal rule of numerical analysis: avoid subtracting nearly equal numbers. The more similar two numbers are, the more pr
by venning 8y ago
> The quadratic equation violated the cardinal rule of numerical analysis: avoid subtracting nearly equal numbers. The more similar two numbers are, the more precision you can lose from subtracting them.
Are there other "rules" like this, regarding numerical analysis? I understand this, but I've never thought of articulating it like that.
- nabla9 8y agoIf you add together many numbers, do it in ascending order, numbers with smallest absolute values first. Comparing floats is tricky. Use either epsilon, epsilon with relative error or ULP's (all are tricky)
- jjgreen 8y agoThat costs a sort, better to use the Kahan summation formula https://en.wikipedia.org/wiki/Kahan_summation_algorithm https://en.wikipedia.org/wiki/Kahan_summation_algorithm
- Retric 8y agoLook at the accuracy comment, it's faster but less accurate than sorting first.
- srean 8y agoIf the numbers happen to be >=0, one could do a little better by merging in Huffman order. In big 'O' the time complexity is the same.
- toolslive 8y agoThere are surprisingly many situations where the unwary end up violating this cardinal rule. For example: solving a system of linear equations. Mathematically, you can use any pivot, but numerical stability suffers if you don't take the largest possible one. All of this uses to be standard in 1st year engineering classes, so I'm always quite surprised when I see articles like this on HN.