Richardson Extrapolation Matlab Code: Example and try out code included.

4.9k Views Asked by At

currently I am studying Numerical Methods in Matlab and I need a Matlab code which would calculate Richardson Extrapolation using data given in a table, respectively for x and f(x).

For example: Use the table below to calculate f'(0) as accurately as possible.

enter image description here

Our professor suggested to use the find function in Matlab, as I did, but so far I only get an empty matrix as a result..

function G = richEx(x,y,xp)

h=x(2)-x(1);

h2=h;

h1=h2*2;

g1 = (-3 * ( find(y==(xp))) + 4 * (find(y==(xp + h1))) - (find(y==(xp) + 2*h1)))) / 2*h1;

g2 = (-3 * (find(y==(xp))) + 4 * (find(y==(xp + h2))) - (find(y==(xp + 2*h2)))) / 2 * h2;

G=(4*g2-g1)/3;

Can someone help me? Thank you.

1

There are 1 best solutions below

2
On

Your find method is returning empty matrices because it's looking for values of y equal to some condition.

For instance, find(y == xp) looks for values of y equal to xp and it returns the index. You haven't told us what xp is, but chances are, there aren't any values of y that equal xp.

Furthermore, find returns the index of the value. So find([4 5 6]==4) returns 1.

I would re-visit the Richardson extrapolation algorithm, because your code does not reflect what the algorithm does.