Presentation is loading. Please wait.

Presentation is loading. Please wait.

Numerical Integration Simpson’s Method. Trapezoid Method & Polygonal Lines One way to view the trapezoid method for integration is that the curves that.

Similar presentations


Presentation on theme: "Numerical Integration Simpson’s Method. Trapezoid Method & Polygonal Lines One way to view the trapezoid method for integration is that the curves that."— Presentation transcript:

1 Numerical Integration Simpson’s Method

2 Trapezoid Method & Polygonal Lines One way to view the trapezoid method for integration is that the curves that you are attempting to estimate the integral of is being fitted with a polygonal line (a bunch of connected line segments) and then you compute the area under (or above) each line segment. a b f(x) Simpson’s Method Simpson’s method uses a second degree polynomial (i.e. a quadratic) to estimate the curve you are trying to find the integral of. This is a curve of the form y = c 2 x 2 + c 1 x + c 0. The points are assumed to be evenly spaced. To get the estimate for the integral we will write out the 2 nd degree polynomial using the data below to the right and then integrate it. a c-h c h h xy a=c-hy 0 =f(a) cy 1 =f(a+h) b=c+hy 2 =f(b) b c+h

3 xy -hy 0 =f(-h) 0y 1 =f(0) hy 2 =f(h) We will begin with the special case with the value of c being zero. We begin by integrating the 2 nd degree polynomial p(t)=c 2 t 2 +c 1 t+c 0. We will simplify it some after integrating it. Substitute c 0 and c 2 values.

4 Shifting this over on any closed interval [ a, b ] we are interested in this becomes the same formula. xy a=c-hy 0 =f(a) cy 1 =f(a+h) b=c+hy 2 =f(b) a b f(x) On 2 partitions this formula becomes: In general this will become a kind of strange sum. Each of the function values will either be multiplied by 4 or 2 except for the first or the last. The number of subinterval points will need to be even.

5 Partition size 2 Example Estimate the integral to the right with 4 subintervals. A partition with 3 subintervals can not be used here since 3 is odd. In general the sum to estimate the integral can be split into 3 parts. One is the value at the two endpoints, the other two are the odd indexes and the even indexes. This is something important when it comes to implementation. odd index odd index even index even index

6 Algorithm for Simpson’s Method function intf ( a, b, n ) deltax = ( b - a )/ n isum = f(a)+f(b) oddsum=0 evensum=0 xodd=a+deltax xeven=xodd+deltax for( i =1, i  ( n/2)-1, i ++, evensum = evensum + f(xeven) oddsum = oddsum + f(xodd) xodd = xodd + 2*deltax xeven = xodd + deltax ) oddsum = oddsum + f(b-deltax) intf = (1/3)* deltax * ( intsum+4*oddsum+2*evensum) prevint = intf (a, b, 2) nextint = intf (a, b, 4) for( i = 3, i  maximum iterations && |prevint – nextint|  error, i++, prevint = nextint nextint = intf ( a, b, 2 i ) odd index odd index even index even index


Download ppt "Numerical Integration Simpson’s Method. Trapezoid Method & Polygonal Lines One way to view the trapezoid method for integration is that the curves that."

Similar presentations


Ads by Google