# numerical derivate and central difference

43 views (last 30 days)
payam abubakr on 10 May 2020
Commented: payam abubakr on 12 May 2020
can anyone help me with this function, please?
find numerical derivative of f(x) = tan−1(?) at x = 2 using central difference scheme where is x is in radians. Use different values of step size h in central difference scheme and compare with true value of the derivative by plotting error for the different h. f(x) means function of x.

Ameer Hamza on 10 May 2020
This seems like a homework question. What have you already tried?
payam abubakr on 10 May 2020
i have tried nothing because i don't knoe how to start.

Jim Riggs on 10 May 2020
Edited: Jim Riggs on 10 May 2020
Here are some Numerical difference formulas using the central difference method (substitute dt = h).
You can find more formulas with even higher accuracy on wikipedia. (see "numerical differentiation" and also "finite difference coefficient" payam abubakr on 11 May 2020
we are taught online, and i cannot understand it like that.
can you help me with the codes, please?
Jim Riggs on 11 May 2020
Since this looks like homework, you should give it a try first, or ask a more specific coding question.
I offer the following explanation of the central difference method;
Central difference is a method to estimate derivatives of numerically sampled data. The method, as described here, requires that the data is sampled at a constant spacing, h, i.e. h is the spacing of the values on the x (independent) axis.
For a given sample (point "i"), we want to find the first derivative (y'), which is the slope of the tangent line at point i. This can be approximated using difference formulas (e.g. forward, backward, central). The central difference formula is more accurate than the other two, because it uses data on either side of the point of interest (point i), so point i is "in the center" of the data being used.
To calculate the slope at point i, we take the change in Y-distance (delta Y) divided by the change in the X-disrtance (delta X). Using the central difference, the change in the Y-distance is y(i+1) - y(i-1) and the X-distance is two samples, which is 2h. You can easily see this in the diagram, below. The red line is the approximation of the slope at point i, which you can see is a pretty good approximation when we translate it to go through point i (the red dashed line). This is the simplest form of the central difference formula, and hopefuly this will help you understand the equations I posted above. The first derivative is y', so you can see that this equation matches the above figure (just substitude dt = h).
(The second group of equations (with error of order dt4) is just a more accurate method which uses two points on either side of point i)
So, given a series of data sampled at uniform spacing h on the x axis, assume that the data is in the form of two vectors X() and Y(). h = X(i+1) -X(i) and is the X-distance between samples.
The derivative (using the central difference) is given by
dy(i) = (Y(i+1) - Y(i-1))/2/h
Suppose further that there are n points in both X() and Y(). Note that since the calculation uses Y(i+1) and Y(i-1), i can only have values of 2 to n-1
payam abubakr on 12 May 2020
thank you