Numerical computations performed by computers or microcontrollers are done with a rounding error. Mathematical operations can be performed with either integer numbers or fractional numbers. When using integer numbers the calculations are performed in fixed point. In this case, if the mathematical operation is either addition, subtraction or multiplication, there is no rounding error. This is true because integer numbers have an exact representation in computers/microcontrollers.
Division brings additional complexity because dividing an integer number to another integer can result in a fractional number. In this case, numbers are represented in floating point.
Having a number A, with an exact value, and a number a, as the approximation of A, we can define the absolute error ε as:
\[\bbox[#FFFF9D]{\epsilon = \left| A – a \right|} \tag{1}\]Relative error η is the ratio between the absolute error ε and the absolute value of the exact number:
\[\bbox[#FFFF9D]{\eta =\frac {\epsilon }{|A|}}\tag{2}\]Replacing the formula of the absolute error (1) in (2), we get the mathematical expression of the relative error function of the exact number and its approximation:
\[\eta ={\frac {\epsilon }{|A|}}=\left|{\frac {A-a}{A}}\right|=\left|1-{\frac {a}{A}}\right|\]Example 1. For the numbers A = 0.0005 and a = 0.0004 calculate the absolute and the relative error.
\[\epsilon = \left| A – a \right| =\left| 0.0005 – 0.0004 \right| = 0.0001 = 10^{-4}\] \[\eta =\frac {\epsilon }{|A|} =\frac {0.0001}{|0.0005|}=0.2\]Example 2. For the numbers A = 999 and a = 1000 calculate the absolute and the relative error.
\[\epsilon = \left| A – a \right| =\left| 999 – 1000 \right| = 1\] \[\eta =\frac {\epsilon }{|A|} =\frac {1}{|999|}=0.001001\]The absolute and relative errors are very important parameters of numerical solvers. Any numerical simulation package (e.g. Scilab/Xcos) allows the user to set the accuracy of the numerical solver, by adjusting the values of the absolute and relative errors.
For any questions, observations and queries regarding this article, use the comment form below.
Don’t forget to Like, Share and Subscribe!
Suthar Jayesh
x-engineer.org such a great article, clear cut explanation. But I’m still not getting why and where to use relative error?? What is the use of that??