Finding derivative using matlab

62 Views Asked by At

Suppose I can generate infinitely many values of x and f(x). The functional form of f(x) is now known. Now I need the value of f'(x) at each point. What is the best way to find it with satisfactory accuracy using matlab. In short it is described below

x:    1     1.1    1.2..............................
f(x): 2      4      5...............................
f'(x):?      ?      ?...............................
1

There are 1 best solutions below

2
On

Using finite many points, you can use the finite difference formula $$\frac{f(x+h) - f(x-k)}{h+k}$$ to approximate the derivative $f'(x)$ at $x$. For example, to evaluate $f'(1.1)$, you can take $h = 0.1 = k$. Then $$f'(1.1) = \frac{f(1.2) - f(1.0)}{0.2} = 5\times(5-2) = 15$$ The accuracy is improved if the partition is finer, i.e. $h$ an $k$ are chosen smaller. But that requires more points.

There are more finite difference formulas. You can goggle for more.