Chapter18

# Chapter18 - GaussLegendre quadrature is used to calculate...

This preview shows page 1. Sign up to view the full content.

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: GaussLegendre quadrature is used to calculate integrals 1 f ( x)dx c 1 0 f ( x0 ) c1 f ( x1 ) cn 1 f ( xn 1 ) The locations and weights for different values of n are given in Table 18.1 Integrals of the form f ( x)dx are transformed to the right limits by a change of variable a b x (b a) (b a ) xd 2 2 ba ba And then f ( x)dx 1 f d ( xd )dxd 2 c0 f d ( x0 ) c1 f d ( x1 ) cn1 f d ( xn1 ) 2 a b 1 Where f d ( xi ) f xi 2 Problem 18.4 The error function is b a ba 2 erf (a) 2 e 0 a x2 dx Calculate erf(1.5) it by 2point and 3point GaussLegendre quadrature. Compare to the exact value given by Matlab function erf >> derf=@(x)2/sqrt(pi)*exp(x.^2) derf = @(x)2/sqrt(pi)*exp(x^2) >> a=0;b=1.5;x(1)=1/sqrt(3);x(2)=x(1) x = 0.5774 0.5774 >> intgl2=(derf(xm(1))+derf(xm(2)))*(ba)/2 intgl2 = 0.9742 Compared to the exact integral >> erf(1.5) ans = 0.9661 An error of about 0.8% With three points >> x(1)=sqrt(0.6);x(2)=0;x(3)=x(1) x = 0.7746 0 0.7746 >> xm=(b+a)/2+(ba)*x/2 xm = 0.1691 0.7500 1.3309 >> c(1)=5/9;c(2)=8/9;c(3)=5/9 c = 0.5556 0.8889 0.5556 >> intgl2=derf(xm)*c'*(ba)/2 intgl2 = 0.9655 Now the error is 0.06%. For comparison take trapezoidal integration with 2 and 3 points. >> xt=[0 1.5]; yt=derf(xt) yt = 1.1284 0.1189 >> trap2=trapz(xt,yt) trap2 = 0.9355 >> xt=linspace(0,1.5,3) xt = 0 0.7500 1.5000 >> yt=derf(xt) yt = 1.1284 0.6429 0.1189 >> trap3=trapz(xt,yt) trap3 = 0.9499 The error reduces much more slowly. We can also apply Richardson extrapolation to improve the result >> richardson=(4/3)*trap3trap2/3 richardson = 0.9548 We can also try Matlab adaptive integration routine quad (good for low accuracy, nonsmooth functions) or quadl (high accuracy smooth functions) >> [intq,fcnt]=quad(derf,0,1.5,0.001) intq = 0.9661 fcnt = 13 >> [intq,fcnt]=quadl(derf,0,1.5,0.001) intq = 0.9661 fcnt = 18 Good accuracy but many evalutions. ...
View Full Document

## This note was uploaded on 03/27/2012 for the course EGM 3344 taught by Professor Raphaelhaftka during the Spring '09 term at University of Florida.

Ask a homework question - tutors are online