



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Numerical Methods Lecture 4 - Numerical Integration / Differentiation
Numerical Integration - approximating the area under a function
We will consider 3 methods: Trapezoidal rule, Simpson’s rule, Gauss Quadrature
The basic concept is to break the area up into smaller pieces with simple shapes fitted to approximate the func-
tion over short lengths. The area under these simple shapes are then added up to approximate the total.
Trapezoidal rule - piece-wise linear approximation to curve f(x)
Example, the figure at the bottom of the page chops a function into 4 trapezoids
over the range [a, b]. The trapeziodal rule adds up the area of each of the 4 trape-
zoids to represent the area under the fucntion f(x).
dx = (b-a)/N (a, b are limits, N is number of pieces we divide the area into)
A1= 1/2 * dx * (f(x1) + f(x2))
A2 = 1/2* dx * ( f(x2) + f(x3))
A3 = 1/2* dx * ( f(x3) + f(x4))
A4 = 1/2* dx * ( f(x4) + f(x5))
Area = 1/2 * dx * (f(x1)+2f(x2)+2f(x3)+2*f(x4)+f(x5))
The generalized equation expressing trapezoidal rule is then ==>
Error: The error (in blue) between the area of the trapezoid and the curve it represents builds up
Error reduction: We can reduce error if we can shorten the straight lines used to estimate curves. Increasing
the number (increase N) of trapezoids used over the same range [a,b] will reduce error in the area estimate.
A
A
x1 (^) x2 x
dx f(x)
A1=1/2dx(f(x1)+f(x2))
!"#$
!
"
--- %& ' & !
( ) " ' & (
( )
( #"
)
' & ) $!
≅ $ $ ( )
We can also get a little more sophisticated than straight line estimates
The error using trapezoidal rule comes from using a series of straight lines to represent a curve. To reduce
this error, we’ll now look at using a series of second order curves to represt the function.
Simpson’s Rule - piece-wise second order approximation of f(x).
N/2 smaller areas representing the curve in the range [a,b]
A=dx/3[f(x1)+4f(x2)+f(x3)]
Example, the figure at the bottom of the page chops a function into 8 pieces over the range [a, b]. Every
two adjacent pieces are joined to form a sub-area. The Simpson’s rule adds up the 4 sub-areas to represent
the area under the fucntion f(x).
A1 = dx/3 * (f(x1)+4f(x2)+f(x3))
A2 = dx/3 * ( f(x3)+4*f(x4)+f(x5))
A3 = dx/3 * ( f(x5)+4*f(x6)+f(x7))
A4 = dx/3 * ( f(x7)+4*f(x8)+f(x9))
Area = A1+A2+A3+A
=dx/3 * (f(x1)+4f(x2)+2f(x3)+4f(x4)+2f(x5)+4f(x6)+2f(x7)+4f(8)+f(x9))
Simpson’s rule is ==>
x i-
x i
x i+
A=dx/3*[f(x i-
)+4*f(x i
)+f(x i+
!"#$
!
%
--- %& ' & !
( )! & ' & *
( )
* #" '('),
)
" & ' & +
( )
+ #% *++,
) ,!
' & ) $!
≅ $ $ $ ( )
fx
x
a b
dx
x
x
x
x
x
A A2 A3 A
x
x
x
x
N = 8 segments
gives us 4 areas to add up
each area is a topped off with a
second order polynomial (red line)
(2) (3)
To apply this change of variables, we re-write equation (1) now as:
(4)
Example: Integrate the following function over the range [ 0 , 0.8 ]
Re-writing Eq. 4 above gives the general solution:
(5)
where and (6)
For this example, and. Plugging these values into (6), then plugging into (5),
we get
Gauss Quadrature Area estimate = f(0.169) + f(0.631) = 0.516741+1.305837 = 1.
Exact Answer = 1.
Note, if we truncated the function being integrated after the term, then the area we estimate using (5)
and (6) will be exact, since Gauss quadrature is exact for up to third order polynomial equations.
Extension
Gauss quadrature can be extended to higher orders, involving more evaluation points, for example
$
-
"
120 &
%
3-- &
4
4-- &
0
( $ , $ , $ ) %&
-/
$
-
!
!
$ # - - # -/5 &
& !
,
%
,!
!
!
!
"
"
. ,!
. ,!
Numerical Differentiation
Read section 23.
Derivative represents the slope of a function f(x) at a particular value
slope is = change in f(x)/change in x
formally the definition of the derivative is:
Here we will approximate the limit by taking some small rather than mathematically letting it go to 0.
Forward difference method
Backward difference method
Central difference method
.
( ) &
∆ & →-
∆ & →-
find the derivative at x
.
( ) &
∆ & →-
find the derivative at x
.
( ) &
∆ & →-
find the derivative at x
.
( ) &
∆ & →-