Friday, August 10, 2012

Trapezoid rule and Simpson's Formula


Okay so recently reading a bit on numerical methods relating to Function values using formulas.

As a pre requisite, I'd assume you'd have some calculus under your belt and enough algebra experience here...especially when it comes to manipulating equations, although I'll show an example derivation of the Simpson's rule.

Starting, we'd like to find the formula for integrating a function between two given endpoints a and b.

The two given endpoints are denoted (a, y(a)) and (b,y(b)), and the interpolating line is given by







Keep in mind y(x) is simply a function y that maps x to a y value...this could be written f(x) likewise, so this function operator y is not to be confused with a Cartesian position. Thus y(x) maps x to a y position but y of the expression y(x) is a functional operator in such mapping and the value y(x) is the y value that is mapped from such x value.

Okay so if you are wondering where this came from. Using the formula for a slope with 2 points we have.










Using our more familiar point slope formula which is y(x) – y1 = m * (x – x1):










means 









multiplying y(a) by (b-a)/(b-a) and separating term (-y(a))/(b-a)*(x-a) yields











distributing y(a) in the numerator to term expression (b-a) and distributing term – y(a) to term expression (x-a), and remembering that all of these terms in the numerator can be rearranged and added since we have a like denominator term expression (b-a), we have









More conveniently, I've re arranged our terms so that we can see our cancellations here.
Namely, -a*y(a) and a*y(a) are like terms and are added to simplify to zero. Thus we are left with b*y(a) – x*y(a) in the numerator, thus since y(a) is common to both terms we can factor this leaving y(a) (b-x) in the numerator which yields











or adding both terms with common denominators 










which is what we set out to derive (show).


Now getting into some calculus stuff. If you have no calculus under your belt, I can explain a basic integral formula rule used in calculation here. I'd also indicate that in polynomial expressions integrated, we can distribute the integral to each term of the polynomial. Meaning that the entire polynomial can be integrated under one integral, or we can split the integration to each term of the polynomial.

Thus for example,

a polynomial of the form

ax2 +bx + c

with integration looks as follows:







Now there is a power rule with integration which is the opposite of a derivative (hence, the other name for the integral which is anti derivative).










also remembering constants can be written outside the integral or







 
so integrating the polynomial in this case would look as follows:










 
Now let's go ahead and integrate the function y(x) above.










keep in mind b, a, y(a), y(b), b-a, all other fractional variations of the same form are constants, and thus can be treated outside the integral here. We are integrating with respect to x, so that we can write the integral in subsequent parts as mentioned above. To do this let's distribute the constant y(a) to the term (b-x) and let's distribute y(b) to the term (x-a), this yields










Now let's break this polynomial up into separate terms. Keep in mind when you have two algebraic expressions with one dividing the other, we can break the terms in the numerator into separate terms as long as we preserve the expression in the denominator.


Now let's apply rewrite the integral to each term


keep in mind some all but two of these terms are constants so we can write these outside the integral and integrate and those that aren't constants can still have the constants written outside the integral when integrating, so that we have









This is much easier to integrate! Integrating each integral we have










where evaluating further we have










we might be tempted to cancel (b-a) in at least two of the terms but we should probably recombine terms for more convenient cancellation here.

First match on either side outer most terms by multiplying by 2/2, then we'll distribute on outer most terms b to (b-a) and on the other outer most term a to (b-a)

this yields










we can see for the first two terms y(a) is a common factor, while the last two terms have y(b), and for all such terms 2(b-a) in the denominator are also common factors so we can factor and combine terms as follows










Let's simplify group terms we'll notice 









Similarly if we simplify on the numerator in the right most term, we have the same, so that we have











we see now cancellations of (b-a) in the numerator on both terms with the denominator, so that we have










 
This is better known as the Trapezoid rule.

Now on to demonstrating the Simpson's formula.

Consider a quadratic of the form 









We'll take three points (-1, y(-1)), (0,y(0)), (1,y(1)). Substituting for each value of x for these given points, we have












Substituting (2) into (3) we have









and 









substituting (4) into (1), and (2) into (1), we have








and



 






Integrate the quadratic above 











substitute (2), (5), and (6) which gives












 

Equation (7) is Simpson's Formula.

What does this say to us, well it says that the definite integral over a given interval is equal to the values of the function at the specified points above in equation (7). While this could seem more trivial to us with respect to the more easy integrable polynomial in so far as integration, this has more purposeful application with respect to more difficult functions that are neither easily interpolated or integrable.






No comments:

Post a Comment

Oblivion

 Between the fascination of an upcoming pandemic ridden college football season, Taylor Swift, and Kim Kardashian, wildfires, crazier weathe...