Lecture 29 


Gaussian Quadrature 

Today I continued my presentation of Gaussian Quadrature. I went over the two node case. Once again I showed how solving a system of 4 non-linear equations one could obtain c1,c2, x1, x2, such that the value of the integral in an interval -1..1, could be obtained by the weighted sum c1*f(x1) + c2*f(x2). The value of the integral is exact for polynomials up to degree 3 and an approximation for arbitrary functions. I then showed how one can use a change of variable so that Gaussian quadrature can be applied to integrals over any interval a..b.

I continued with some demonstrations using Matlab. I demonstrated the use of the "int" function from the symbolic toolbox,
and anonymous functions, and array multiplication. (Do help int, help function handle, and help arith for Matlab help on these topics.) I also used a Recktenwald function 'GLTable' as a means of obtaining node and weight values for Gaussian quadrature.

Here is an editted listing of the Matlab session I did this morning so that you may explore these topics on your own.

%anonymous function f
f = @(x) x.*exp(-x)

X = linspace(-1,1);
Y = f(X);
plot(X,Y)

%symbolic integration of f
syms x
int(f(x),-1,1)
int(f(x))

RightAns = -2*exp(-1)

%Recktenwald's GLTable
help GLTable
type GLTable

%2 nodes
[x2,w2] = GLTable(2)
A2 = sum(f(x2).*w2)
RightAns

%4 nodes
[x4,w4] = GLTable(4)
A4 = sum(f(x4).*w4)
RightAns - A4

%integrating the same function on a different interval
X = linspace(0,5)
Y = f(X);
plot(X,Y)
int(f(x),0,5)
RightAns = -6*exp(-5)+1
T = linspace(-1,1)
scale = 5/2
offset = 5/2
YT = f(T.*scale + offset);
plot(X,Y,T,YT)

%4 nodes
A4 = sum(f(x4.*scale+offset).*w4)
A4 = A4*scale
RightAns

%8 nodes
[x8,w8] = GLTable(8)
A8 = sum(f(x8.*scale+offset).*w8)
A8 = scale*A8
RightAns - A8 

Posted: Thu - November 17, 2005 at 10:00 AM          


©