To analyze the convergence rate of a numerical method in Matlab, we need to calculate the error at each iteration and compare it to some known error bound or to the error at the previous iteration. This allows us to estimate the rate at which the method is converging.
Here's an example for the bisection method to find the root of a function f(x) within the interval [a,b], with a known error tolerance eps:
main.m680 chars31 lines
This code will plot the error versus iteration number, allowing us to visually inspect the convergence rate. We could also calculate the rate more precisely by fitting a line to the logarithm of the error history and finding its slope. This would give us an estimate of the order of convergence of the method.
gistlibby LogSnag