The use of 'error = abs(b - a)' means you are dealing with the number of decimal places. This is OK if the root is in [1,10] but give bad results if the root is near 0 e.g. x - 0.0000000001. The sequence of intervals would be 1 [0.000000, 1.000000] 2 [0.000000, 0.500000] 3 [0.000000, 0.250000] 4 [0.000000, 0.125000] 5 [0.000000, 0.062500] ... 20 [0.000000, 0.000002] so |b - a| = 0.000002 < In this case, take the midpoint of this interval (0.000002) and we find |0.000002 - 0.0000000001| < 5*10**(-6) so that 0.000002 is an approximation to 0.0000000001 that is accurate to 5 decimal places but is a useless result. Absolute error gives decimal place - relative error '|b - a|
Dude, such great comment should not be free, you are amazing, real help for my engineering class of numeric methods
thank you very much for this
The use of 'error = abs(b - a)' means you are dealing with the number of decimal places.
This is OK if the root is in [1,10] but give bad results if the root is near 0 e.g. x - 0.0000000001.
The sequence of intervals would be
1 [0.000000, 1.000000]
2 [0.000000, 0.500000]
3 [0.000000, 0.250000]
4 [0.000000, 0.125000]
5 [0.000000, 0.062500]
...
20 [0.000000, 0.000002]
so |b - a| = 0.000002 <
In this case, take the midpoint of this interval (0.000002) and we find
|0.000002 - 0.0000000001| < 5*10**(-6)
so that 0.000002 is an approximation to 0.0000000001 that is accurate to 5 decimal places but is a useless result.
Absolute error gives decimal place - relative error '|b - a|
Just draw a vertical line around the root? That's too aggressive...