Finite difference approximation on an uniform mesh

# Finite difference approximation on an uniform mesh

We have seen the basic idea of finite difference
approximation. Now let us introduce some nomenclature and let us a try to make faster progress. So, we are looking at finite difference approximations
on a uniform mesh. So, consider uniform mesh with a spacing of delta x over a space interval
of between 0 and capital l. So, we denote the mesh index by i here and what we mean
by this is that f of the value of f at xi. So, that is the location the x value at the
ith machine index or node which we write as f subscript i here is nothing, but f of i
times delta x. So, that is what xi is here and we can also write f of i plus 1 in the
shorthand notation as the value of f at i plus 1 delta x. So, that is instead of writing
f of x and f of x plus delta x, we can write it as f subscript i and f subscript i plus
1 and similarly f subscript i minus 1. So, using this notation here we can write
the approximation that we have got from equation 2 df by dx at x as f of x plus delta x minus
f of x divided by delta x. Instead of that we can write it as f subscript i plus 1 minus
f subscript i divided by delta x plus terms of the order of delta x. Similarly from the
third equation where we expanded f of x minus delta x, we got another approximation for
d f by d x as f of i minus f of i minus 1 by delta x plus again terms of the order of
delta x other ones that are neglected. So, that neglected part is known as truncation
error. So, the leading term of the truncation error varies as delta x the magnitude instead
of that varies is delta x and that is what is denoted here as the order of accuracy of
the approximation and we also got a different expression by manipulating equation 2 and
equation 1 and 3, those 2 approximations we subtracted 3 from 1 and then we got a different
approximation, df by dx at x as f of i plus 1 minus f at i minus 1 divided by 2 delta
x plus terms of the order of delta x square. Now there is a some difference between these
3 approximations. So, first 1 is known as the forward differencing approximation because
f of x, df by dx at x given in terms of f of i plus 1 minus fi divide by delta x.
The second expression where the same derivative at the same location is expressed in terms
of fi minus fi minus 1 by delta x, that is known as backward differencing. And in this
the value of the first derivatives at x is expressed in terms of the two neighboring
points, f of i plus 1 minus f of i minus 1 divided by 2 delta x. 2 delta because the
distance between these 2 points is 2 here, we get a central differencing scheme. So,
forward and backward differencing schemes are 1 sided differencing schemes. So, that
is you have i and i plus 1 and i and i minus 1 not, where as this is central in sense that
you have points which are goes to the left i minus 1 and right of this. So, that is both
sides are being used to express the approximation of this. So, these are known as central differencing
formulas. Usually central differencing formulas are more accurate than 1 sided differencing
formula, but we need both central because are more accurate, and forward and backward
are required at the edges of the fluid of the computational domain. If a there is no
point of the right of this point x or point node i then we cannot make use of the forward
differencing. Similarly at the left edge of a boundary here,
we cannot make use of point which is outside this computation domain. So, at the edges
we would like to have 1 sided differencing and in the center we would like to have central
differencing. So, 1 sided formula’s are necessary at the ends of domains.
We can look at these derivatives that we have forward backward central in a graphical way
by looking at this function in this case it is a u here varying with x as per this particular
curve. So, fairly smooth variation, and you have your mesh nodes this is ith nodes and
then i plus 1 i plus 2 similarly i minus 1 i minus 2 like that, with uniform spacing
of delta x. Now we are looking at the derivatives dou u by dou x at i at this particular point.
So, here we have the red line here is the true slope of this particular function at
the point i. If you take i plus 1 or i plus 2 the slope is varying, but at the location
i here the red line here is what is the true slope the true derivative value at i here
forward differencing is based on the difference between i plus 1 and i. So, the value of i
here and the value of the function at i and i plus 1 here, if you join them by line and
then following it then you get this blue lines. So, that is the forward differencing and the
slope of this the angle with respect to the horizontal is the approximation of the first
derivative as given by the forward differencing. And backward differencing is based on a line
drawn between the value of i minus 1 or the function at i minus 1 and i and that is the
green line here. And the central differencing is based on a line which is drawn between
i plus 1, i minus 1 value here and i plus 1 value here and that is this black line given
by c central differencing here. And if you now look at the slopes, so that is the angle
that each of the straight lines is making with the horizontal you see that the central
differencing line here is much closer to the value of the true slope. So, it is almost
parallel to this which means it is accurate, where as both f and b the forward and backward
is at different angle compared to the true slope. So, that indicates sense of more error
with forward and backward differencing schemes that we would get as compared to the central
differencing. So, this also an indication of the mathematically derived truncation error
which is of second order accuracy in the case of central, where as f and b are first order
if you go back to the Taylor series expansion here.
So, the in a in central differencing it is this 1 which is being neglected from this
term onwards. Now, way it is the third derivatives which
is being neglected, and in the case of 1 sided differencing it is a second derivative and
terms are being neglected. So, if it is a converging series the second derivative term
is likely to be larger in magnitude, then the third derivative term so; that means that
we are neglecting a larger amount of error with 1 sided differencing involving first
order accurate comes here. Where as in the case of central differencing it is a third
derivative. So, that is the next term is the one that is has been neglected and all the
successive terms and since the next term is smaller than this term the error involved
in in the central differencing is less. So, that is also another way of looking at these
approximations. So, they can be these approximations and we can also get an approximation of even
higher order accuracy, we can get a third-order or nth order type of thing.
So, let us say that we want to have we can have a systematic way of arising at order
of accuracy for a given derivative. In this case we are going to look at only the first
derivative and we will seek a third-order one sided approximation for u of x at x. So,
we will see when we generalize it then you generalize recent requires that in order to
write this we need 4 successive points of the mesh. So, that and this is of this particular
form that is dou u by dou x at i, i is xi here. So, we are making use of that and that
is this formula here for a one sided third-order accurate approximation will involve four points
four successive points all to 1 side of i. So, that is ui, ui plus 1 ui plus 2 ui plus
3 and these are all multiplied by certain coefficients, real coefficients a b c d and
divide this whole thing is divided by delta x and this whole formula is third-order accurate
and therefore, we can write dou u by dou x at i as per this in this particular way. So,
that is we seek an approximation for dou u by dou x at I, in the form of aui plus bui
plus 1 plus cui plus 2 plus dui plus 3 divided by delta x plus terms of the order of delta
x cubed, this makes it a third-order accurate of approximation.
Now, when this is equivalent in a way to writing this approximation, because we have seen that
all these tells is expansion involve derivatives; first derivatives, second derivative, third
derivative and all that. So, what this approximation actually implies is that we are we would like
to get an approximate formula which is dou u by dou x at i equal to aui plus bui plus
1 plus cui plus 2 plus dui plus 3 divided by delta x, plus zero times dou square u by
dou x square times delta x there is if this 1 is not that is it is not there. It is there,
but being multiplied by zero. So, that it does not appear in this expression similarly
zero times the third derivative time delta x square because we divided by delta x here
it become delta x square and of course, you have factorial 3 here, but since it is zero
it does not matter here again you have factorial 2 it does not matter because multiple by this.
And a coefficient e times the fourth derivatives at x, times delta x cube by factorial four
which can be substitute in this coefficient here and when you have an expression like
this plus higher order terms, that is the fifth derivative times delta x to the power
four and all that this expression equation 7 and equation 6 are equivalent because they
both are saying that d u by d x d u by d x at i is in terms of this ui plus 1 ui i plus
2 i plus 3 like this plus 0 times this. So, this delta x term does not appear zero times
delta x square terms. So, this also does not appear and the only term the leading term
that appears is this factor coefficient e still to be determined times d 4 u by d x
four at x time delta x cube. So, this is what although we are writing it
like this what we are saying is that this approximation is a this form plus higher order
terms. Now, you can rewrite this as you bring this on to this side au i plus 1 plus bu i
plus all this things equal to du by dx minus 0 times this, minus 0 times this, minus 0
times this. So, writing this is, but how do we define the values of a , b, c, d? If we
can find unique values of a, b, c, d then we have a formula here.
And in order to find this a, b, c, d what we do is that we expand ui plus 1 ui plus
2 ui plus 3 which are appearing in this formula, in this proposed formula in terms of Taylor
series about point i for example, ui plus 1 is nothing, but u at x plus 1 delta x and
that we know is u of x plus du by dx at delta x plus d square u by dx square at delta x
square factorial 2 like this. Similar ui plus 2 is nothing, but u of x plus 2 delta x. So,
wherever we had delta x here we substitute 2 delta x here. So, and if delta x is small,
two times delta x also small. So, and assuming that it is small and it is still convergent
and all that kind of thing we can write ui plus two as ux plus dou u by dou x times 2
delta x plus dou square u by dou x square times 2 delta x whole square by factorial
2 in similarly, u at i plus 3 is u of x plus 3 delta x and therefore, we can write this
as u of x plus du by dx times 3 delta x plus dou square u by dou x square at x times 3
delta x whole square plus 3 delta x whole cube by factorial 3 and so on.
Now we have these approximations and we replace these things in the previous equation here.
So, we evaluate this term au i plus bu i plus 2 like that. So, we multiply this whole thing
by b and then this whole thing by c and this whole thing by d and then take the sum of
all this things and this will be given finally, in this particular form. This will pu i plus
q times du by dx times delta x plus r times dou square u by dou x square times delta x
whole square. For example; p will be a here, and then when we multiply this by b we get
b plus c plus d. So, p is a plus b plus c plus d and q here will be b plus 2c plus 3c,
a plus 3d. In that way we can ones we multiply and then put all these things together we
can express this p, q, r, s, t in terms of a, b, c, ds. Now we compare this equation
with the equivalent expression equation 8 that we said is equivalent to this approximation
here with zero coefficients here. From this we can say that p is equal to 1. So, that
is a plus b plus c plus d is equal to 1 and b plus 2 c plus 3 c plus 3 d equal to 0 and
this will be a square here. So, this will be 4b plus 9c plus 16d will be equal to 0
and so on like this. So, that will be give you four equations 1
for p, 1 for q, 1 for r and 1 for s. This p coefficient is 1 and the other 3 coefficients
are 0. So, it does not matter what this e is we will come out of the solution because
we have 4 equations, that is a plus b plus c plus d equal to 1 and 2 be plus 3c plus
4d equal to 0 and 4b plus 9c plus 16d equal to 0 and so on like that. So, you have 4 equations
and 4 unknowns and if you solve those things you get a equal to minus 11 by 6, b equal
to 3 and c equal to minus 3 by 2 d equal to 1 by 3. And e will be some sort of summation
of this that will come out in this way, it does not matter what the coefficient is this.
Anywhere this whole term is going to be neglected. So, that will give us the third-order approximation
and when we substitute this back into the original equation we can get dou u by dou
x at i here as minus eleven ui plus 18 ui plus 1 minus 9 ui plus 2 plus 2 ui plus 3
divided by 6 delta x plus terms of the order of delta x cubed.
So, this is a third-order 1 sided approximation for the first derivative at i involving i;
i plus 1 the value of u at i; i plus 1 i plus 2 like this and in this think on a uniform
mesh when we derive it using this Taylor series like this, we will notice that the sum of
all these coefficients will be equal to 0. So, you have minus 11 plus 9, minus 9. So,
that is minus 20 and you have 18 plus 2; 20. The sum of all these things, that is a plus
b plus c plus d will be equal to zero of here. So, that is something that that is 1 quick
way of us for us to verify that we have got the right kind of formula here. So, this kind
of expression can be derived not just the first derivative, we can derive it for any
pth derivative and we can do it for any order of q. It is possible for us to derive a qth
order of approximation for a pth derivative using either one sided or central things and
the number of points n here depends on what is order of p here, and what is the order
of q. It is equal to t plus q in the case of one sided, and it is one less in the case
of central differencing. So, this is your a general way of deriving a finite difference
approximation of some order. In the next lecture we will try to apply this to an equation and
then see what kind of approximation we get. Thank you.

## One Reply to “Finite difference approximation on an uniform mesh”

1. Study purpose says:

Very good explanation sir…