gaussian quadrature dc (v3) (pdf)

Post on 11-Jul-2015

248 Views

Category:

Education

2 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Gaussian Quadrature

A different kind of introduction

David Coulson, 2014 dtcoulson@gmail.com

Setting the scene: You are working on some extraordinary physics problem and you are required to find the area under a curving graphline. You will know from your calculus days that this means integrating some function over a given domain, and there are several procedures for doing this. But let’s say that the integral is a particularly gnarly one and you just don’t know how to work it out analytically. You are reduced to using approximate methods.

The normal practise is to calculate or measure the height of the curve at regular intervals and treat the region between any two vertical lines as a trapezium. The area in each trapezium is simply the average height times the base width. You can see, however, just how inaccurate this approach can be for a line that bends consistently in one direction. All those little errors at the top of each region accumulate to become a very significant total error.

Now what if it were possible instead to put the line segment at some higher point so that it was more representative of the curve in that region, a kind of average height instead of simply the heights of the curve at each end? What this means is that there is probably an optimal place to put a straight line so that the errors above the line are balanced perfectly by the errors underneath it.

To illustrate this further, I want to use a better diagram, one which exaggerates the curvature of the line.

2

BA

B

A

yyABdxy

The area under the curve, therefore is the area under the trapezoid as shown:

To illustrate this further, I want to use a better diagram, one which exaggerates the curvature of the line.

2

BA

B

A

yyABdxy

The area under the curve, therefore is the area under the trapezoid as shown:

What I’m going to do now is try to express the area under the trapezoid in terms of the two crossover points, y1 and y2.

Ax

yy

xB

yy

xx

yym AB

2

2

1

1

12

12

12

1211

xx

yyxByyB

12

1222

xx

yyAxyyA

You can do this by noting that the slope through y1 and y2 is the same as the slope anywhere else on that line.

12

1211

12

12222

1 xx

yyxBy

xx

yyAxyABdxy

B

A

Therefore

12

1211

12

12222

1 xx

yyxBy

xx

yyAxyABdxy

B

A

You can see already how quickly this turns into a very messy business.

12

1

12

21 1

xx

xB

xx

Axc

where

12

1

12

22 1

xx

xB

xx

Axc

221121 ycycAB

B

A

dxy

But we can tidy it up a bit:

12

1

12

21 1

xx

xB

xx

Axc

where

12

1

12

22 1

xx

xB

xx

Axc

221121 ycycAB

B

A

dxy

Can you see that the parts that make up c1 and c2 are very similar?

where 221121 ycycAB

B

A

dxy

12

1

12

2

xx

xB

xx

Axq

qc 11

qc 12

where

Therefore I can simplify things even further:

where 221121 ycycAB

B

A

dxy

This may look like an unholy mess, but there is a happy outcome, just a few screens away. To get there, I’m going to have to stop thinking like a mathematician and apply a wee bit of nonmathematical common sense.

12

1

12

2

xx

xB

xx

Axq

qc 11

qc 12

where

where 221121 ycycAB

B

A

dxy

12

1

12

2

xx

xB

xx

Axq

qc 11

qc 12

where

You see, c1 and c2 have to be the same.

where 221121 ycycAB

B

A

dxy

12

1

12

2

xx

xB

xx

Axq

qc 11

qc 12

where

You see, c1 and c2 have to be the same. How come?

221121 ycycAB

B

A

dxy

You see, c1 and c2 have to be the same.

Think about it: If they weren’t the same, one crossover point would have to be more important than the other in determining the area under the graph. Why should one side of a trapezoid be more important than the other side? That makes no sense.

221121 ycycAB

B

A

dxy

Therefore this q term has to equal zero.

12

1

12

2

xx

xB

xx

Axq

where

qc 11

qc 12

where

221121 ycycAB

B

A

dxy where

This has a LOT of implications.

12

1

12

20xx

xB

xx

Ax

11 c

12 c

B

A

dxy

12

1

12

20xx

xB

xx

Ax

2121 yyAB First of all it means that I can

throw away those c terms entirely. They don’t do anything to the approximation.

B

A

dxy

12

1

12

20xx

xB

xx

Ax

2121 yyAB

Secondly, the two numerators in these fractions have to be the same

B

A

dxy 2121 yyAB

That means these distances have to be the same.

B

A

dxy 2121 yyAB

Which means that the distance from the centre has to be the same, and that has to be true no matter what the function is.

That’s really counterintuitive. I would never have guessed that. Regardless of the shape of the curve, the best straight line approximation for it always cuts through the curve at the same two places, equidistant from the middle.

So for all functions y(x), whatever their shape, the best trapezoidal approximation for the integral is...

2121

B

yyABdxxyA

...for some δ which is still to be determined.

2

BA yx y y iiwhere

2121

B

yyABdxxyA

This can be done in a trial-n-error sort of way, by choosing a very simple integral for which I already know the answer.

2

BA yx y y iiwhere

...for some δ which is still to be determined.

2121

B

yyABdxxyA

2

BA yx y y iiwhere

For example, the integral of y=x2, between B and A. I know from calculus that this has to be 1/3( B3 – A3 )

2

2

2

221 BABAAB

2

2

2

121

B

2 xxABdxxA

22

2

22

221 BABAAB BABA

22

2 BAAB

32

A-B δ 33

3122

2 ABAB BA

This is great, because now I can get the best Trapezoid approximation to the integral of any function.

2121 xfxfAB dxx f

B

A

where 32

2

1

A-BAB x

32

2

2

A-BAB x

For example...

where

3

2

3

121

1

0

3 xx dx x

32

1

2

11 x

32

1

2

12 x

41

331

0

3

32

1

2

1

2

1

32

1

2

1

2

1

dx x

For example...

This is exactly the value I would get from calculus.

41

331

0

3

32

1

2

1

2

1

32

1

2

1

2

1

dx x

For example...

All polynomials of degree four or less will be matched perfectly by this approximation. Transcendental functions, like ex, ln(x), Sin, Cos and Tan will not be matched perfectly, but the approximation will still be very good.

12 21

21

2

1

xxx ee dx e

211325.1 32

1

2

31 x

688675.1 32

1

2

32 x

669727.4 (2.3 % error)

Here’s how it looks with f(x) = ex, between x=2 and x=1.

(8 % error)

The same integration done by the Trapezoidal rule is far less accurate.

.0545 5.0 21

2

1

ee dx ex

(8 % error)

The same integration done by the Trapezoidal rule is far less accurate.

.0545 5.0 21

2

1

ee dx ex

The difference, however, is that the Trapezoidal rule is easier to remember and easier to implement. So is the Gaussian approach really worth the effort? Hard to say....

Improvements

(1) – Multiple regions

Gauss’s method is already accurate over a single region, but it’s accuracy can be improved further by slicing the region into thinner parts and applying the method to each part, and then adding the results.

4321

2121 ffMB ffMB dxx f

B

A

Here’s how it looks for ex.

1 5.1 5.1 2 4321

21

21

2

1

xxxxx eeee dx e

where

32

.51 2

2

.51 21

- x

32

.51 2

2

.51 22

- x

32

1 .51

2

1 .513

- x

32

1 .51

2

1 .514

- x

where

Here’s how it looks for ex.

34

1

4

71 x

34

1

4

72 x

34

1

4

53 x

34

1

4

54 x

4321

41

41

2

1

xxxxx eeee dx e

where

Here’s how it looks for ex.

4321

41

41

2

1

xxxxx eeee dx e

605662.11 x

894338.12 x

105662.13 x

394338.14 x

670708.4 (Error 0.001%)

Here’s how it looks for ex.

394338.1105662.1

41894338.1605662.1

41

2

1

eeee dx ex

Improvements

(2) – More crossover points

Instead of interpolating a straight line through the curve over a region, you could interpolate a parabola.

332211 fcfcfcarea That would lead to three crossover points, the middle one probably being tangential. The approximation would be almost exact, for any curve. The c values, called weights, can be determined by the same kind of analysis I used for the two-point method. It just takes a lot longer.

Fortunately this has all been done before, so I can take the easy way out and refer to some online tables. The weights are 5/9, 8/9 and 5/9.

5

15

2

2

1

A-BAB x

2

2

AB x

5

15

2

2

3

A-BAB x

The crossover points are

Therefore the full 3-point approximation is

xf xf xf AB dxx f

B

A

32121

9

5

9

8

9

5

5

15

2

2

1

A-BAB x

2

2

AB x

5

15

2

2

3

A-BAB x

e e e dx e xxxx 321

9

5

9

8

9

521

2

1

If applied to the function ex over the region 1 to 2, the integral would become

10

15

2

31 x

2

32 x

10

15

2

33 x

e e e dx ex 887298335.15.1112701665.1

21

2

19

5

9

8

9

5

= 4.670772

(correct answer 4.670774)

If applied to the function ex over the region 1 to 2, the integral would become

What tends to happen these days is that some keen engineer creates a program using these numbers and stores it away for future use. Over time, this and other tedious numerical programs find their way into program libraries, so that people like you and me get to use them, and all we have to do is simply feed the numbers into the right places.

This is dizzyingly accurate, but I have to wonder how often people need this kind of accuracy? Even simply computing these values for the sake of this demonstration took me a long time, even after I had looked up the weights on the internet. How often, and in what sort of situations will this kind of effort be justified?

Are there 4-point and 5-point approximations based on the same idea? Absolutely! Which gives you an idea of the obsessive extremes that mathematicians will go to to explore the potential of a new mathematical method. Go and search on the internet for sites containing the words “Legendre Gaussian Quadrature Tables”. You will find a complete list of weights and crossover points for all Gaussian approximations: 2-point, 3-point, 4-point, 5-point... All the way up to 20- or 30-point approximations! It kind of scares me that there are people driven to investigate procedures like this that are so beyond the scope of practical use. And yet that’s how progress is made. I think....

Gaussian Quadrature in higher dimensions

It’s also possible to use this kind of method to find the volume under a curved 2-dimensional surface. Now the 2-point method evolves into a 4-point method, arranged in a 2-by-2 grid.

32

2

xxxxi

A-BAB x

32

2

yyyy

i

A-BAB y

where + +

+ +

222112114

1 , f f f f ABAB dxdyyxf yyxx

surface

etcyxff , 1111

It’s also possible to use this kind of method to find the volume under a curved 2-dimensional surface. Now the 2-point method evolves into a 4-point method, arranged in a 2-by-2 grid.

+ +

+ +

You could also create a 9-point method based on the one-dimensional 3-point method.

ij ijyyxx

surface

f ABAB dy dxyxf ,41

95

95

98

95

95

95

98

95

98

98

98

95

95

95

98

95

95

95

This already looks pretty frightening, with calculations to be performed on 9 separate regions of the surface. But on a machine this is not so bad.

ij ijyyxx

surface

f ABAB dy dxyxf ,41

95

95

98

95

95

95

98

95

98

98

98

95

95

95

98

95

95

95

You can even solve problems in three dimensions! Now the integral represents something like the heat distribution across a cube-shaped object. Instead of two crossover points on a line, or four points on a 2x2 square surface, now we are looking at 8 points in a 2x2x2 cube. That’s 8 x coordinates, 8 y coordinates, and 8 weights that have to be determined before we even start the integral, which will require the addition of 8 numbers. In all, I estimate that some 32 terms have to be created in order to generate an answer. This is clearly not something for the fainthearted, even with access to a computer and a big pile of paper.

For odd-shaped objects, you have to slice the object into cubic chunks and solve the integral in each of these chunks. Or alternatively you can apply some weird axis transformation that will twist and stretch the shape you’ve been given into a tidy cube that you can then integrate over. Typically you might be looking at 1000 or more cubes inside some bizarre curved shape. We are now very far out of the realm of ever doing these sorts of calculations by hand.

But we’re also deeply in the realm of real maths, the mathematics that helps us to analyse the complicated processes of the real world, such things as the movement of heat through an engine or the microscopic alteration to its shape as it is subjected to all kinds of pressure. We are just inches away from steeping into a conversation on Finite Element Analysis, a process so mind-boggling in complexity my head hurts even wondering how I would introduce it to you. Good place to stop, I think.

[END]

David Coulson, 2014 dtcoulson@gmail.com

top related