 In the last week, we have learnt some quadrature formulas to approximate a given integral. In this class, we will do some problems on quadrature formulas. Recall that in quadrature rules, our aim is to approximate the integral a to b f of x dx. We first approximate the given function f of x by an appropriate interpolating polynomial P n of x and then we will take the approximation of the required integral a to b f of x dx as integral a to b P n of x dx. With this idea, we have derived few quadrature formulas. One is rectal and the other is rectal triangle rule. Another one is trapezoidal rule and then we have also learnt Simpson's rule. Let us first consider the trapezoidal rule and ask this question, when does the trapezoidal rule give exact result? Recall in trapezoidal rule, first we will take the linear polynomial interpolation for the given integrand f of x and then we will consider the trapezoidal rule and this linear polynomial interpolation is obtained with nodes as x naught equal to a and x 1 is equal to b. Therefore, we are actually taking the straight line joining two points say a comma f of a and b comma f of b. Then we are finding the area under the graph of this line and this is the trapezoidal rule generally we denote it by it of f. Now, you are given any function say the function like this then you are supposed to get the area under this curve, but what we obtain finally is the area under this line. So, that is the trapezoidal rule idea and therefore, we do commit some error in this approximation. Now, our question is when does this trapezoidal rule give exact result? Obviously, if this integrand is a polynomial of degree 1, then we will get exact result from the trapezoidal rule. Now, the question is is there any other function which is not a polynomial of degree 1 for which the trapezoidal rule will give the exact result? The answer is yes. So, let us try to have an example for this. In this problem, we have to find a constant c such that when you try to approximate the integral 0 to 1 x cube plus c x square plus 1 by 2 dx, then the trapezoidal rule should give the exact value of this integral. So, how to find such a c? Let us see it is not very difficult. What you do is first on one hand evaluate this integral exactly remember it is just a polynomial. Therefore, you can obtain the integral explicitly and it will be like c by 3 plus 3 by 4. On the other hand, you use the trapezoidal rule and find an approximation to this integral. Recall the trapezoidal rule formula is given like this where a is equal to 0, b equal to 1. Therefore, you can plug in these values in the formula with f given by this expression. Then you can see that the trapezoidal rule applied to this integral will take the value 1 plus c by 2. Therefore, we obtained the exact integral on 1 plus c by 2. Therefore, we obtained the exact integral on one hand and we also obtained the value from the trapezoidal rule. Now, what we want? We want to find this constant c such that this trapezoidal rule gives exact result. That is equivalent to saying that we have to find the constant c such that the exact value which is coming from the direct integration is equal to the value coming from the trapezoidal rule. Therefore, you subtract these two quantities we should get 0. Let us substitute these expressions into this equation and let us see what we get? We get c by 3 plus 3 by 4 minus 1 plus c by 2 equal to 0. From here, you can directly find the value of c as minus 3 by 2. It is very simple. You can see that the integrand is not a straight line, but when you take c equal to minus 3 by 2 that is when you take f of x equal to x cube minus 3 by 2 x square plus 1 by 2 then the trapezoidal rule applied to this function in the interval 0 to 1 will give you the exact result integral 0 to 1 f of x dx. You can see that the function f is not a straight line, but still you get the exact result. Let us try to view this geometrically to see what exactly made trapezoidal rule to get exact value of the integral for this particular integrand. For that, let us try to develop a python code for the trapezoidal rule. First, let us define the integrand f as x cube plus c into x square plus 0.5. Recall this is the integrand that we have taken in our problem with a c and we have also found that c is equal to minus 3 by 2 and our integral is over the interval 0 to 1. Therefore, these are the inputs that we have to take in our code and if you recall the formula for the trapezoidal rule is given by i t of f is equal to b minus a by 2 into f of a by 2 into f of a by 2. So, that is what is written here b minus a divided by 2 into f of a here what I am doing is I am also sending the value of c as a parameter into my lambda expression. Therefore, I have two arguments in f one is the point at which I want to find the value of the function f and another one is this constant c. So, therefore, as per the formula I have to evaluate f of a which I am doing here plus f of b which I am doing here in order to get this expression. So, this is precisely the formula for the trapezoidal rule then I am asking the python to print the value computed using the trapezoidal rule and I am also asking the python to print the exact value recall the exact value is c by 3 plus 0.75 this is what we have evaluated exactly from the integral I am just directly taking that expression here and asking the python to print the value of this expression. Now, I am also interested in seeing the graph of the function f as well as the graph of the polynomial p 1 of x which interpolates the function f at the node points a and b. Let us see how to do that well first let us generate the x vector which will be in the x coordinate and for the y coordinate what we are doing is we are taking the linear interpolating polynomial at the node points a and b remember with Newton's form we can write p 1 of x is equal to f of a right which is nothing but the value of f at a only plus f of a comma b into x minus a right. So, that is the interpolating polynomial for the function f at the node points a and b that is what I am writing here f of a plus this is the first order divided difference f of a comma b which is f of b minus f of a divided by b minus a right into x minus a is written here therefore I am interested in plotting x versus p 1 and also I am interested in plotting the graph of the given function f. So, what I am doing here is I am plotting x versus f of x as the y coordinate and again x comma y now y is the linear interpolating polynomial. So, I am plotting both this graphs in one command and then I want to fill the area under the graph of these two functions that is what I am doing in these two commands and then I am just giving the title to my graph and finishing my plotting part. Let us execute this code and see how the output looks like well the code is executed successfully as we wanted python printed these two print commands by that we have the trapezoidal rule value is 0.25 and the exact integral value is also 0.25 how we got that because we have taken the constant c as minus 1.5 if you recall that is what we obtained here as long as you are taking c equal to minus 1.5 you will have the exact result from the trapezoidal rule. That is what we have seen computationally here now let us see how this graph looks like well as we have given the title of the graph geometrical interpretation of the trapezoidal rule that is printed as the title in the graph. Let us see how the graph looks like we have plotted the function f of x and that is shown in the blue color and we have also plotted the linear interpolating polynomial of this function f with nodes as a which is 0 and b which is 1 in this example and in between that it is just a straight line because it is a linear interpolating polynomial and we have also asked the python to fill the area under the graph of these two functions that is what is written in these two the first one is to fill the area under the graph x comma y y is nothing but your p 1 right. So, your y is p 1 therefore this command will fill the area under the graph of p 1 with red color and this command will fill the area under the graph of the function f with blue color. So, that is what we are seeing here you can see that this purple color is the area which is covered both by the exact integral as well as the trapezoidal rule whereas trapezoidal rule had excluded this area which is actually there in the exact value, but it included this area which is actually not there in the exact integral. Now it so happened that the area excluded by the trapezoidal rule is equal to the area included by the trapezoidal rule that is why even though the function and the polynomial are looking entirely different the integrals are the same. So, that is the beautiful geometric interpretation of the trapezoidal rule and it explains geometrically why trapezoidal rule has captured the exact value of the integral in this particular example with this let us pass on to the next problem. The next problem involves an important concept called degree of precision we are given a quadrature formula and important question generally people ask is what is the degree of precision of our quadrature formula what does it mean well the degree of precision is nothing but the largest positive integer n such that the quadrature formula is exact for all polynomials of degree less than or equal to n. So, this is what is called the degree of precision let us see how to find the degree of precision of some quadrature formulas as an example let us try to find the degree of precision of the Simpson's rule recall that the Simpson's rule for the integral a to b f of x dx is given by this formula. Now our interest is to find the degree of precision of the Simpson's rule that is we have to find the largest positive integer n such that integral a to b that polynomial p of x dx which is a polynomial of degree less than or equal to n is actually equal to the value computed from the Simpson's rule to achieve this we will do the following steps we want to show that a to b the integrand is a polynomial of degree n should be equal to the value obtained from the Simpson's rule. Remember any polynomial of degree n can be written as a naught plus a 1 x plus a 2 x square plus so on till a n x n. Now you cannot verify this condition for all polynomials which looks like this for any given set of constants a naught a 1 a 2 up to a n right. So what you can do is we will check this equality only for the basis of this polynomial remember the monomial basis of this are precisely 1 x x square and so on till x n right. We will simply apply this condition on only the monomial basis and see till what n does this equality holds the largest n for which this equality holds will be the degree of precision for that we have to fix a interval a to b right. In general you can fix any interval you want because the process of finding the degree of precision does not depend on the interval that we work with. Therefore you can fix the interval conveniently so that the calculations are not so difficult I will choose this interval as 0 to 2 because I have to evaluate the Simpson's formula at a b and then the midpoint of a b right. So if I choose my interval as 0 to 2 then my midpoint will become 1 all are integers that will make my computation more easy. Therefore I am choosing the interval 0 to 2 you can also choose the interval minus 1 to 1 that will be little more easy in fact. Let us see I have chosen the interval like this with that we have to check the equality of this value obtained from the Simpson's rule with the exact integral for the monomial basis. First let us start with f of x is equal to 1 on one side you have the value 2 from the exact integral on the interval 0 to 2 on the other hand from the Simpson's method you also have the same value. Therefore f of x equal to 1 that is the degree 0 is satisfied let us go to check the degree 1 for that we will take f of x equal to x and now you have the integral 0 to 2 x dx equal to 2 on one hand and also the Simpson's rule applied to f of x equal to x gives us the value 2. Therefore the polynomial of degree 1 is also exact with the Simpson's rule. Now let us go to take x square the exact integral value is 8 by 3 and Simpson's method also gives 8 by 3 when we go to apply it on the interval 0 to 2. Therefore degree 2 polynomials are also fine with Simpson's rule. Remember in one of the previous lectures in fact we have derived the Simpson's rule by assuming that the rule is exact for all polynomials of degree less than or equal to 2. Therefore it is not surprising for us that the Simpson's rule is giving exact value for polynomials of degree up to 2. Now let us go to check the condition for the cubic polynomial for that let us take f of x equal to x cube and perform the exact integral of x cube in the interval 0 to 2 and that gives us the value 4 surprisingly even Simpson's rule gives exact value for cubic polynomial also. Therefore up to now we have seen that degree 3 polynomials are getting exact value from the Simpson's rule when we go to integrate them. Now let us go to x 4 so x 4 when you integrate exactly in the interval 0 to 2 it gives 32 by 5 whereas the Simpson's rule gives 20 by 3. So that is the first degree at which Simpson's rule value is not equal to the exact value therefore you have to take 3 and declare that the degree of precision of Simpson's rule is 3. From the way Simpson's rule is derived we have imposed the condition that the rule is exact for polynomials of degree less than or equal to 2 but in reality its degree of precision is 1 greater than how we have derived the Simpson's rule. This is the nice part of the Simpson's rule similarly if I give you any quadrature rule for instance trapezoidal rule or rectangle rule or any Gaussian rule and ask you what is the degree of precision what you have to do is you keep on integrating the monomial basis elements and check whether the equality holds between the exact integral and the quadrature rule that was asked. Here we are doing it for Simpson's rule similarly you can do it for trapezoidal rule in which case you have to find the trapezoidal rule value here and see whether this equality holds. And if that holds then you will go for f of x equal to x if that holds you will go for f of x equal to x square and so on. At some n say x power n gives exact value but x n plus 1 is not giving exact value then you have to take this n and declare that as the degree of precision of that quadrature formula. So, this is the method in which you can find the degree of precision of any given quadrature formula with this let us pause on to the next problem. Here we are interested in deriving the arithmetic error for the Simpson's rule. In fact the method that we are going to learn here can be used to obtain arithmetic error for any formula whether it is quadrature formula or finite difference formula that we will be learning in the next section the idea is more or less the same. Therefore, let us learn this very carefully remember the Simpson's rule is given by this expression. Now our interest is to derive the formula for the arithmetic error. How the arithmetic error is committed? Well we want to work with the exact value of the function but due to some reason we only have the approximate value say just assume that we are only given approximate value of this function value f of a and the error between these two that is f of a minus f a is say epsilon a ok. So, this error may come into our function value through some rounding process or it may be just a human error whatever it may assume that there is a error that is when we go to apply Simpson's rule we want this three function values due to some reason instead of having exact function values we are having an approximate value which is denoted by f a and the error committed in this is just denoted by epsilon a similarly f of a plus b by 2 is given as f suffix a plus b by 2 and the error in f suffix a plus b by 2 when compared to the exact value is denoted by epsilon suffix a plus b by 2 and similarly we want to work with f of b which is the exact value but we are only working with an approximate value f b and the error between them is denoted by epsilon b. Now, let us take the Simpson's rule and apply the rule with approximate values instead of the exact values given here right then the Simpson's rule will take this form and let us denoted by i tilde s of f. Now, what is the arithmetic error well by definition arithmetic error is given by exact value that is the Simpson's rule obtained using the exact function values minus the approximate value obtained from the Simpson's rule using approximate function values. Now, let us directly put the formula and see how this definition looks like finally well you have to take this expression minus this expression right that will precisely be written as say f of a minus f a will come from this first term inside this bracket right that is taken as epsilon a. So, that is what we are writing here plus 4 times again f of a plus b by 2 minus f suffix a plus b by 2 and that will be epsilon suffix a plus b by 2 and finally, we will have f of b minus f b and that is epsilon b. Therefore, the arithmetic error formula finally looks like this expression well this is the arithmetic error formula for the Simpson's rule similarly any formula is given and you are asked to derive the arithmetic error formula what you have to do is you take whatever values involved in the expression and write them as approximate value plus some error and then take only the approximate value and put it in the required formula and then find the difference between the exact value and the approximate value and that will be the expression for your arithmetic error I hope you understood it you try to write the arithmetic error expression for trapezoidal rule in the same way that I have explained here that will give you more understanding on how to write the arithmetic error for any given formula. In fact, in the next section we will also write the arithmetic error for some finite difference formulas. Suppose, if you want to find an estimate for the arithmetic error how to do that let us see assume that your function values that is f of a f of a plus b by 2 and f of b are only provided with 6 significant digits then what is the estimate of your arithmetic error that is what the question is asking us now let us see how to find the estimate remember the estimate means you have to bound your arithmetic error by some constant that is what we meant by estimate here the function f is taken as e power minus x and a is equal to minus 0.5 and b is equal to 1 now you see we have to use the Simpsons rule and then get an upper bound for the arithmetic error we have already found the expression for the arithmetic error in the case of Simpsons rule and that is given by this expression. Now, we have to take modulus on both sides and somehow we have to find out what is the expression for the arithmetic error find the values of this epsilon from the given condition that the function values are given with 6 significant digits how to do that let us see first let us take the modulus on both sides of this equation and use the triangle inequality on the right hand side that is when you take modulus here you will have this that is less than or equal to anyway b minus a by 6 is positive now when you take the modulus to each of this terms in the bracket you will have epsilon a plus 4 times mod epsilon a plus b by 2 plus mod epsilon b right. So, that by triangle inequality will give us a less than or equal to sin here that is why I put less than or equal to into the expression that I have shown here is here ok. So, this is the bound for the arithmetic error, but now we have to get more precise bound from the given condition that the function values are given only with 6 significant digits what is mean by function values are given with 6 significant digits well if you recall we have seen a definition for significant digits in one of our previous chapters that is on errors right as per the definition we have the exact value minus approximate value divided by exact value that is the relative error is less than or equal to minus 1 by 2 into 10 to the power of minus 6 plus 1 that is what we mean by saying that this approximate value f a has 6 significant digits when compared to the exact value f of a right that is why I have written here 1 by 2 into 10 to the power of minus 5 now what you do is you take this mod f of a to the other side and you write this inequality as mod f of a minus f a is less than or equal to this constant which is coming from our significant digit definition into mod f of a remember f of a is e to the power of minus x right that is why I have put here e to the power of minus a remember f of a minus f a is precisely what we have taken as epsilon a right therefore we have a bound for epsilon a now what is a is minus 0.5 right therefore your epsilon a which is epsilon minus 0.5 right therefore minus 0.5 is less than or equal to this constant which is coming from the definition into e to the power of minus of minus 0.5 that is e to the power of 0.5 and that will give us mod epsilon a that is epsilon minus 0.5 that is sitting here and we have now an upper bound for this similarly we have to find the upper bound for this epsilon as well as epsilon b how to do that you do the same idea you apply the formula for f of a plus b by 2 as well as for f of b that will give you epsilon a plus b by 2 which is 0.25 is less than or equal to this number and similarly mod epsilon b where b is in our case 1 therefore epsilon 1 is less than or equal to this quantity now you put this number for epsilon a and this number for epsilon a plus b by 2 and this number for epsilon b and this number for epsilon and let us see how the upper bound for the arithmetic error looks like you have to put these three numbers into this expression ok. So, this is the idea and when you put that you will have mod a e f is less than or equal to remember b minus a is 1.5 divided by 6 into epsilon b the sum of all these numbers where the middle term is multiplied by 4 into 10 to the power of minus 5 which is sitting in all the upper bounds of the epsilon's. Therefore, finally the arithmetic error involved in the Simpson's rule when we use only 6 significant digits in the function value is bounded by 0.6 4 1 5 into 10 to the power of minus 5. Similarly if I give you any other formula say trapezoidal rule and give you that the function values are considered only up to some n significant digits then now you know how to first write the arithmetic error formula and then how to find the upper bound as per this kind of given conditions. With this let us conclude this tutorial session. Thank you for your attention.