CHAPTER 07.05: GAUSS QUADRATURE RULE: 2-pt Gaussian Quadrature Rule: Derivation   I'm this segment, we're going to derive the two-point Gauss quadrature rule for integration. So we're going to derive a formula which is going to integrate our function going from a to b, and if you look at the method of undetermined coefficients, we approximated it as c1 times f of a, plus c2 times f of b for deriving the trapezoidal rule, and when we did that, what it allowed us to do was to get the exact value of the integral by using this particular formula, as obtained by integral calculus for a straight line.  And the reason why we're only able to choose a straight line is because we have only two values which are not known, c1 and c2, those are something which are of our choice.  Now, what two-point Gaussian quadrature rule does is that we don't fix these two numbers.  We don't fix a and b, we say, hey, let's go ahead and make these also to be something which I can choose, because when I make the choice of this being a and this being b, then I have only two choices, but if I make this to be a choice which I can choose, and this to be a choice which I can choose, then I'll have four choices.  In that case, what I can do is I can start at a third-order polynomial for which I want the formula to give me the exact value, and hence, that's why the two-point Gaussian quadrature rule will turn out to be more accurate than your trapezoidal rule, and will give you exact results for up to third-order polynomial. as opposed to trapezoidal rule being only for first-order polynomial So what I'm going to do is I'm going to, the two-point Gaussian quadrature rule will look like this, c1 times f of x1, plus c2 times f of x2, now.  So we have four choices, c1, x1, c2, x2, the only limitation which I am going to use is that x1 is somewhere between a and b, and x2 is somewhere between a and b, because you cannot possibly find the value of an integral by choosing points which are outside of the lower and upper limit range.  So let's go ahead and see what we can . . . how we can go about doing that is that I'm going to assume that for a function which is a third-order polynomial like a0, plus a1 x, plus a2 x squared, plus a3 x cubed, that whatever I get by integral calculus will be same as what I get from the formula which I wrote.  So from integral calculus, a to b, f of x dx is, a to b, a0, plus a1 x, plus a2 x squared, plus a3 x3, dx.  And that turns out to be a0 times b minus a, plus a1 times b squared minus a squared by 2, plus a2 times b cubed minus a cubed, divided by 3, plus a3 times b to the power 4 minus a to the power 4, divided by 4. So that's what I get for the exact value of a third-order polynomial. Now, what do I get from substituting from the formula.  So I want to get exactly the same result from the formula itself, c1 times f of x1, plus c2 times f of x2.  So I'll get c1, times a0, plus a1 x1, because that's the value of the function . . . value of x is x1, plus a2 times x1 squared, plus a3 times x1 cubed.  Then from f of x2, I'll get a0, plus a1 times x2, plus a2 times x2 squared, plus a3 times x2 cubed. And what I'm going to do is I'm going to separate out the a0 terms, I'll get c1 plus c2, like this, c1 plus c2.  In a1, I'll get c1 x1, plus c2 x2.  In a2, I'll get c1 x1 squared, plus c2 x2 squared.  And then a3, I'll get c1 x1 cubed, plus c2 x2 cubed, and all these terms are coming from separating out the a0 terms, c1 plus c2, which is here, then c1 times x1, c2 times x2, which is right there, and so on and so forth.  The reason why I am doing that is because I want to equate the coefficients of a0, a1, a2, and a3, because I want this formula to give me exactly the same results as I'm getting from the integral calculus for any values of a0, a1, a2, and a3, because all these coefficients, a0, a1, a2, a3, are arbitrary. If I am choosing any arbitrary third-order polynomial, I have no . . . I have no control of what a person can choose for a0, a1, a2, and a3.  So what that means is that the coefficients of a0, a1, a2, and a3 in both of these formulas, this is the exact . . . exact value of the integral, this is the approximate value of the integral which I am getting, and I want both of them to be same, that means that these coefficient should be same.  So for example, c1 plus c2 here should be same as b minus a, and so on and so forth.  So let me write down those, I'll get four of those, I'll get an expression for this, this, this, and this.  So what I'm going to get is as follows, I'm going to get c1 plus c2 is equal to b minus a, then I'm going to get c1 times x1, plus c2 times x2 is equal to b squared minus a squared by 2, then I'm going to get c1 times x1 squared, plus c2 times x2 squared is equal to b cubed minus a cubed, divided by 3, and then I'm going to get c1 times x1 cubed, plus c2 times x2 cubed is equal to b to the power 4 minus a to the power 4, divided by 4.  So I'm going to get four equations, because I am equating the four coefficients, so this is 1, this is 2, this is 3, and this is 4, however, what you can see is that these equations are not simultaneous linear equations, but actually, they are simultaneous nonlinear equations. So you have to basically choose whatever solution you're going to get, because you can get multiple solutions for solving these four equations and four unknowns, so you have to choose the one which is acceptable.  So I'm not going to show you the solution for it, but the solution which turns out to be acceptable is c1 is equal to b minus a, divided by 2, c2 is b minus a, divided by 2, x1 turns out to be b minus a, divided by 2, times -1 divided by square root of 3, plus b plus a, divided by 2, and x2 turns out to be b minus a, divided by 2, times -1 divided by square root of 3, plus b plus a, divided by 2. So that's what turns out to be the value of c1, c2, x1, and x2, and as you can see that these are all in terms of a and b, they are a little bit more complicated than what you get in your trapezoidal rule, but that's what you're going to get.  So basically what you are saying is that the two segment . . . the two point Gaussian quadrature rule . . . Gauss quadrature rule is giving you the formula of c1 times f of x1, plus c2 times f of x2, where c1, c2, x1, x2 are defined by these numbers here, and that is going to give the approximate value of any integral which you can integrate going from a to b.  For a third-order polynomial or less, for third-order polynomial, second-order polynomial, first-order polynomial, and a constant line, the formula which you have derived right here, the formula which you have derived here is going to give you the exact value of those integrals. For any other integral the value which you're going to get will be approximate. So that's the end of this segment.