CHAPTER 01.03: SOURCES OF ERROR : Truncation Error: Example: Differentiation
In this segment, we'll talk about an example of truncation error. So we'll look at the example of differentiation. So we already know that truncation error is basically the error which is caused by approximating a mathematical procedure, whether it's taking a series and trying to truncate it by using only a certain number of terms in the series, or otherwise. So let's see what this example pertains to. Let's suppose somebody tells you that, hey, you learned in your differential . . . in your differential calculus class that the derivative of a function is defined as follows: that if you want to find the derivative of a function f of x, you need to take the limit of this particular term here, this being the rise, this being the run. So let's suppose if we were looking at it from a graphical point of view, and this was your function f of x as a function of x, and you wanted to find out the derivative at this particular point, let's suppose, you will choose a point which is delta x ahead of it, x plus delta x. And then you will draw a secant line between x and x plus delta x. So what's going to happen is that this particular distance which you are seeing here will be the difference between the value of the function at x plus delta x minus the value of the function at x. Because the fact . . . this is the y-coordinate of this particular point is the value of the function at x, and the y-coordinate at this particular point is the value of the function at x plus delta x, and of course, the run is delta x. So as we make the delta x approaching 0, what's going to happen? The secant line's going to go closer and closer to this particular point, and whatever that limit turns out to be is your derivative of the function. Now from a numerical point of view, you can already see that you cannot use delta x approaching 0 in a numerical method. So what we have to do is we have to maybe use delta x which is a finite number. So in that case, we'll drop out the limit term, still use the same rise over run term, the numerator and the denominator term from the definition from your differential calculus class, but now the reason why it's approximate is because we are going to choose delta x to be a finite number. So let's go ahead and see what kind of truncation error does this cause. So again, what you are doing is the truncation error is coming from the fact that you are no longer choosing delta x approaching 0, but that you are choosing delta x to be a finite number. So let's take an example like this one.
Let's suppose somebody says that, hey, take f of x equal to 6 x squared, and what you want to do is you want to find out what f prime of 3 is. What is f prime of 3? So let's go ahead and first use the approximate formula, which we just showed, and then we will use the exact analysis. So let's find out the approximate value. The approximate value is going to come from this definition, or this formula, which we said will give you the approximate value of the derivative of the function, that you calculate the value of the function at x plus delta x, you calculate the value of the function at x, and you divide it by delta x. So we already know that x is 3. Let's go ahead and choose delta x equal to 0.2. So let's choose x to be 3, that's where we have to find out the derivative of the function, and the delta x is our choice, because delta x . . . the only thing which is required of delta x is that it's a finite number, so I'm going to choose delta x equal to 0.2, let's suppose. Let's see what we get. So from here, if we substitute we get f prime of 3 is equal to the value of the function at x, which is 3, plus delta x, which is 0.2, minus the value of the function at 3, divided by 0.2. That's what we get there. So that gives you, this is approximate, of course, and this gives the value of the function at 3.2 minus the value of the function at 3, divided by 0.2. All we have to do now is to substitute the value of the function at 3.2 and 3. So that turns out to be 6 times 3.2 squared minus 6 times 3 squared, divided by 0.2. And this number here turns out to be 37.2. So the approximate value of the derivative of the function 6 x squared, which is this one here, the function 6 x squared at the value of 3 by using this approximate formula here turns out to be 37.2 by using the formula there. So let's go ahead and see what do we get as the exact value of f prime of 3, because the difference will then tell us what the truncation error is. Now how do we calculate the exact value? I'm going to go back to the basic definition of this. Because that is the definition which you learned in your differential calculus class, and I'm going to use this one. So in this case what we have, limit of delta x approaching 0, the value of the function x plus delta x for the function which is our choice is 6 x squared, so the value of the function at x plus delta x will be 6 x plus delta x squared minus 6 times x squared, divided by delta x. What I'm going to do is I'm going to use the formula of a plus b, whole squared, which I learned in my high school algebra, I'll get 6 x squared plus 2 x times delta x plus delta x squared minus 6 x squared divided by delta x. So from here, I get limit of delta x approaching 0, if I expand it I get 6 x squared plus 12 x delta x plus 6 delta x squared minus 6 x squared divided by delta x. This 6 x squared, this 6 x squared cancels out, and if I divide the numerator denominator by delta x, I'll get 12 times x plus 6 times delta x. And clearly, as delta x approaches 0, I'll get 12 times x. So your f prime of x for 6 x squared, so for f of x equal to 6 x squared, you're getting f prime of x to be 12 x, and that's from your differential calculus knowledge. You could have derived this very formula by using the formula which you learned in your differential calculus class. You already learned the differential calculus formula that d by dx of x raised power n, for example, is n times x raised power n minus 1, we'll say n is not equal to 0. So if I was going to use d by dx of 6 x squared, I would get 6 outside, and then 2 for n, and then x raised power 2 minus 1, and I'll get 12 x there also. But this formula was also derived from the basic definition of the derivative of a function. So going back to what is the value of f prime of 3 there? So the value of f prime of 3 would be 12 times 3, which is 36. So that's the exact value of the derivative of the function at 3. However we got 37.2. So we got f prime of 3 equal to 37.2 by choosing delta x to be a finite number of 0.2. So the truncation error is exact value minus approximate value, which is -1.2. So you can see here that because you approximated the mathematical procedure where you had to choose delta x approaching 0, and now you are choosing delta x to be a finite number, that you're getting some truncation error in this particular case here. The question which you can do at home is that choose delta x to be a smaller number, like 0.1, and find the truncation error. The second one can be, hey, choose delta x equal to 10 to the power -20, and find the truncation error. The reason why I'm asking you to do this particular problem is because you might think that, hey, it looks like that when I do this particular problem, I'll get a lesser truncation error, so what's the harm of choosing delta x to be a very small number, because smaller the value of delta x, the better the value of the derivative of the function is going to turn out to be. But go ahead and do this exercise, do this exercise on your nonprogrammable calculator, and see what happens, what kind of truncation error do we get, or what kind of value do we get for the derivative of the function in the first place at x equal to 3. And reason with yourself why choosing a very, very, very small delta x is also not a good idea when you are trying to use numerical differentiation. And that's the end of this segment.