In the root finding algorithms, the stopping criteria determine when to stop iterating and consider the current approximation as the root. The two commonly used stopping criteria are the absolute error and the relative error.
x_i
is the current approximation and x_{i-1}
is the previous approximation, then the absolute error E_a
can be calculated as:main.m22 chars2 lines
x_i
is the current approximation and x_{i-1}
is the previous approximation, then the relative error E_r
can be calculated as:main.m30 chars2 lines
The main difference between the two stopping criteria is that the absolute error considers only the magnitude of the error, while the relative error takes into account the magnitude of the current approximation. This makes the relative error more suitable when the scale of the problem or the variable being approximated varies significantly.
In MATLAB, the stopping criteria can be implemented using conditional statements such as if
and while
loops. For instance:
main.m488 chars18 lines
Note: The specific implementation of the stopping criteria in MATLAB may vary depending on the specific root finding algorithm being used (e.g., Newton's method, bisection method, etc.).
gistlibby LogSnag