Numerical Diff of Continuous Functions - First Derivative - Central Divided Diff

In this segment, we'll talk about how do we numerically differentiate continuous functions. We'll talk about how to find the first derivative of the function and the method which we'll use is the Central Divided Difference method. So, let's go and see how the Central Divided Difference method works.

So, let's suppose if we have a function like this. And let's suppose somebody says hey I want you to find the value of the derivative of the function right here, and the central divided scheme, what it does is that it takes a point which is h backwards, and a point h forwards, so that will be this point right here that'll be this point right here. So, it draws a secant line right here. And we already know that this distance here is 2h, that the coordinate here is x minus h, and the value of the function at x minus h the coordinate here will be x plus h, for the x value, and the y value will be the value of the function at that particular point. So, if we want to find the slope of the secant line, we'll have to find what the rise is, what the run is the run is, already 2h as shown here, the rise will be f of x plus h which is this number here, and this number here is same as this number here for the y axis, so it'll be f of x minus h. So that's the rise and this is the this is the run. So, in that case f prime of x will be approximately equal to the rise which is this quantity right here and divided by 2h as the approximate value of the derivative of the function that is the CDD or the Central Divided Difference scheme, formula right here. Let's take an example.

So, here we are asked to find the derivative of the function at 3 for this function 7 x to the power 4 using a step size of 0.16. We're also asked to calculate the true value the true error and discuss trends in true error when we change our step size. And also discuss hey what happens to the absolute relative approximate error as the step size decreased, but also what is the relationship between the absolute relative approximate error to the significant digits. So, let's do this problem one part at a time. So, let's look at part a.

Part a would be that we'll use this approximate formula, the Central Divided Difference formula, to calculate the value of the derivative of the function here. And we know that the value of x is 3 and the corresponding and also the value of h is 0.16. So, what does that give us for f prime of 3, will be the value of the function calculated at the following two points. Which gives us the value of the function at 3.16 minus the value of the function at 2.84, divided by 0.32. And since we already know that the function is 7 x to the power 4, so what do we get for f prime of 3? F prime of 3 will be 7, times 3.16 raised to the power 4, minus 7, times 2.84 raised to the power 4, divided by 0.32. And this number here turns out to 758.1504.

Part b is asking us to calculate what the true value is. So, the true value for f prime of 3 is what we know that the value of the function is what 7x to the power 4. That's expression for the function not the value. And then f prime of x if we apply our differential equation knowledge, will turn out to be this. That gives us the value of the derivative of the function at 3 to be 756.

So, part c says that hey, calculate the true error we already calculate the true value right here. So, the true error will be true value minus approximate value. The true value is 756, the approximate value is 758.1504, as found in part a, and this number here will turn out to be equal to -2.1504.

In part d we are asked to figure out hey what is the relationship between the true error and the step size. So, what we are basically doing here is we're going to tabulate hey what do we get for the derivative of the function at 3. I’m going to use different step sizes. So, I’m going to put true error right here. So, for example, h = 0.16, the derivative of the function at 3, we get this value which we just calculated. And the true error turns out to be this number right here which we just calculated.

So, we can repeat the process which we had in part a and part b and part c. And you can get these numbers for the f prime of 3 will turn out to be this, and the true error will turn out to be this. Then we go and halve the step size again, and what happens is that the value which we get for f prime of 3 turns out to be this. And the true error turns out to be this. So as you would imagine that as you decrease the step size the approximate error is becoming closer and closer to the exact value of 756, in this case. And the true error is also decreasing as you see when you go from step size of 0.16 to 0.04. However here, if you see that as you halve the step size, this true error is getting almost approximately quartered. And that's something which you should keep in mind. Because when we talk about the errors or the order of accuracy in these divided difference schemes, this will come handy to see that hey numerically, for an example, we are able to see that as we as we have the step size that the true error is getting approximately quartered.

So, in part e, since it talks about hey find the absolute relative approximate error as you change the step size, so let's go and see what we get for our approximate errors and absolute relative approximate errors. So, for h = 0.16, f prime of 3 is this number here we cannot calculate the approximate error or the relative approximate because we don't have a previous approximation. So, let's see what happens when I make the step size to be 0.08.

In this case I would get this number, this you can do just like we did in part a. The approximate error will be the difference between the current approximation minus the previous approximation and that turns out to be this number here. And what is the absolute relative approximate error? It turns out to be 0.2132%, which is the approximate error divided by the current approximation, absolute value of that multiplied by 100. That's how we get this number right here. And let's suppose if we halve the step size again, the number which I’m going to get is this. In this case the approximate error turns out 0.4032. And the absolute relative approximate error, which will be the ratio between this number and this number absolute value of that multiply by 100, because we calculated in terms of percentages, turns out to be 0.0533%.

So, the reason why we are calculating the approximate errors is because in real life we won't be privy to the exact value of the derivative of the function, because then most probably we won't be using a numerical method to find that derivative in the first place. So, we have to be able to say that hey, if I know the approximate errors, how can I figure out how much error there is in my calculation and how much I can trust my solution?

So, here we have absolute relative approximate error of 0.0533% in this value of the derivative of the functions. How many significant digits can I trust? It is less than 5%, so I can trust one significant digit. It is less than or equal to 0.5%, so I can trust two significant digits. Is it less than or equal to 0.05%? No. So what will happen is that the number of significant which I can trust in the solution will be 2. So, in this approximation of the derivative of the function at 3 which is 756.1344, without knowing the exact value, I can trust this 7 and this 5 the first two significant digits in the number. And that is the end of this segment.