Centre for Computer Technology

ICT114 Mathematics for Computing
Week 10

Numerical Differentiation and Integration

Objectives
Review week 9  Numerical Differentiation  Newton’s Forward Difference formula  Newton’s Backward Difference formula  Numerical Integration  Trapezoid rule  Simpson’s one third rule

March 20, 2012

Copyright Box Hill Institute

Newton's Method
Using an initial guess at the root and the slope of f(x), Newton's method uses extrapolation to estimate where f(x) crosses the x axis. This method converges very quickly, but it can diverge if f’(x) = 0 is encountered during iterations. (f’(x) is the differential of f(x))
March 20, 2012

Copyright Box Hill Institute

Algorithm
initialize: x1 = . . . for k = 2, 3, . . . xk = xk-1 - f(xk-1)/f’(xk-1) if converged, stop end

March 20, 2012

Copyright Box Hill Institute

Secant Method
The secant method approximates f’(x) from the value of f(x) at two previous guesses at the root. It is as fast as the Newton's method but can also fail at f’(x)=0.

March 20, 2012

Copyright Box Hill Institute

Algorithm
initialize: x1 = . . ., x2 = . . . for k = 2, 3 .. . xk+1 = xk - f(xk)(xk - xk-1)/(f(xk) - f(xk-1)) If f(xk+1)<0, xk-1 = xk+1, xk=xk else xk-1= xk-1, xk=xk+1 if converged, stop end
March 20, 2012

Copyright Box Hill Institute

Centre for Computer Technology

Newton’s Forward Difference Formula

Numerical Differentiation
 We

discuss Newton’s forward difference formula in detail.  This is suitable for differentiation for the the values towards the beginning of the table

March 20, 2012

Copyright Box Hill Institute

Forward Difference formula (1)
   

For functions tabulated with constant interval h, E f(x) = f (x+h) E2 f(x)= E (E f(x)) = E f(x+h)=f(x+2h) Like this, Epf(x) = f (x + ph) Again, Δ f(x) = f(x+h) - f(x) Hence f(x+h) = f (x) + Δ f(x) = ( 1 + Δ ) f(x) That is, E f(x) = ( 1 + Δ ) f(x) or simply, E  ( 1 + Δ )
Copyright Box Hill Institute


  

March 20, 2012

Forward Difference formula (2)
Hence, f(x0 +p.h) = Epf (x0)  = (1 + Δ)p f(x0)  = ( 1 + p Δ +pC2 Δ2 +pC3 Δ3+ .... ) f(x0)  = ( 1 + p Δ + p(p-1)/2! Δ2 + p(p-1)(p-2)/3! Δ3 + ……) f(x0)

March 20, 2012

Copyright Box Hill Institute

Forward difference formula (3)
 Putting,

x = x0 + ph,

df df dp 1 df ---- = ---- . ---- = ---- . ----dx dp dx h dp

March 20, 2012

Copyright Box Hill Institute

Forward difference formula (4)
So, f/(x)= (1/h) [ Δ + (2p-1)/2. Δ2 + (3p2 - 6p +2)/6 Δ3 + (4p3-18p2+22p-6)/24 Δ4 +…]  Putting p = 0,

f/(x)= (1/h) [ Δ –1/2 Δ2 ++1/3 Δ3 –1/4 Δ4 +….]

This is Newton’s forward difference formula for differentiation suitable for values given in the table
Copyright Box Hill Institute

March 20, 2012

An example : f(x) = ex (1)
x
1.0

f(x)
2.718282

1.2

3.320117

1.4

4.055200

1.6

4.953032

1.8
March 20, 2012

6.049646
Copyright Box Hill Institute

An example : f(x) = ex (2)
x
1.0

f(x)
2.718282

Δ
0.601835

1.2

3.320117
0.735083

1.4

4.055200 0.897832

1.6

4.953032 1.096615

1.8

6.049646

March 20, 2012

Copyright Box Hill Institute

An example : f(x) = ex (3)
x
1.0

f(x)
2.718282

Δ
0.601835

Δ2

1.2

3.320117
0.735083

0.133248

1.4

4.055200 0.897832

0.162749

1.6

4.953032 1.096615

0.198783

1.8

6.049646

March 20, 2012

Copyright Box Hill Institute

An example : f(x) = ex (4)
x
1.0

f(x)
2.718282

Δ
0.601835

Δ2

Δ3

1.2

3.320117

0.133248

0.735083
1.4 4.055200 0.897832 1.6 4.953032 1.096615 1.8
March 20, 2012

0.029501
0.162749 0.036034 0.198783

6.049646
Copyright Box Hill Institute

An example : f(x) = ex (5)
x
1.0

f(x)
2.718282

Δ
0.601835

Δ2

Δ3

Δ4

1.2

3.320117

0.133248

0.735083
1.4 4.055200 0.162749

0.029501
0.006532

0.897832
1.6 4.953032 0.198783

0.036034

1.096615
1.8
March 20, 2012

6.049646
Copyright Box Hill Institute

Example (continued)
    

To find the differential coefficient for x=1.0 From the table, Δ = 0.601835, Δ2 = 0.133248 Δ3 = 0.029501, and Δ4 = 0.006532 Here h = 0.2 The approximate value of the diff coeff = (1/0.2) [ Δ –1/2 Δ2 +1/3 Δ3 –1/4 Δ4 ] = 2.717060 The true value is 2.718282
Copyright Box Hill Institute

March 20, 2012

Formula for value not in table
Suppose we want to find derivative at a point not given in the table,say at x=1.1  So, ph = 0.1.  Then, as h=0.2, p=0.5  Putting p=0.5,we get f/(x)= (1/h) [ Δ + 0 * Δ2 – 0.25/6 Δ3 + 1/24 Δ4 +…]

March 20, 2012

Copyright Box Hill Institute

Forward difference formula
So, f/(1.1)= (1/0.2) [Δ + - 0.25/6 Δ3 + 1/12 Δ4 +…] = 5*[0.601835 - 0.029501* 0.25/6 + 0.006532/12] = 3.005750 The true value is = 3.004166
March 20, 2012

Copyright Box Hill Institute

Centre for Computer Technology

Newton’s Backward Difference Formula

Backward difference formula
Backward difference formula is given by  f/(x)= (1/h) [ +1/2 2+1/3 3 + 1/4 4+..]  Where,  f(x) = f(x) – f(x-h), 2 f(x) =  ( f(x)), and so on  This is suitable for finding derivative towards the end of the table

March 20, 2012

Copyright Box Hill Institute

An example : f(x) = ex
x
1.0

f(x)
2.718282

Δ
0.601835

Δ2

Δ3

Δ4

1.2

3.320117

0.133248

0.735083
1.4 4.055200 0.162749

0.029501
0.006532

0.897832
1.6 4.953032 0.198783

0.036034

1.096615
1.8
March 20, 2012

6.049646
Copyright Box Hill Institute

Backward difference formula
    

To find the differential coefficient for x=1.8 From the table,  = 1.096615,  2 = 0.198783  3 = 0.036033, and  4 = 0.006532 Here h = 0.2 The approximate value of the diff coeff = (1/0.2) [ +1/2  2 +1/3  3 +1/4  4 ] = 6.048252 The true value is 6.049647
Copyright Box Hill Institute

March 20, 2012

Some remarks
There is a central difference formula for finding differential coefficient when the values are around middle of the table. We did not discuss that.  It may be remembered that at times numerical differentiation might be very inaccurate when there are large fluctuations.

March 20, 2012

Copyright Box Hill Institute

Centre for Computer Technology

Trapezoid Rule

Numerical Integration
Value of a definite integral within its limits is the area under the curve in the limits  In numerical integration, the function is approximated by a polynomial, and the area under the polynomial is taken as the value of the integral  We study two simple rules (1) Trapezoidal rule and (2) Simpson's one-third rule

March 20, 2012

Copyright Box Hill Institute

Trapezoid rule (1)

Area below the curve is approximated by a Trapezium
f(x)

a

b

Value of integral of f (x) between a and b is the area under the curve between a and b
March 20, 2012

Copyright Box Hill Institute

Trapezoid rule (2)

Area below the curve is approximated by a Trapezium

f(x)

a

b

Value of the integral is approximated as = area of the trapezium = ½ [f(a) +f(b)] . (b – a)
March 20, 2012

Copyright Box Hill Institute

Trapezoid rule (3)

Now two intervals
Trapezoid Rule for two intervals

f(x)

a0=a

a1

a2 = b

Value of the integral is better approximated by = area of trapezium 1 + area of trapezium 2 = ½ [f(a0) +f(a1)].(a1 – a0)+½ [f(a1) +f(a2)](a2 –a1)
March 20, 2012

Copyright Box Hill Institute

Trapezoid rule (4)

If a1=a0 + h , and, a2 =a1+ h= a0 +2h, The approximate area under the curve (when there are two intervals) = h/2 [ f(a0) + f(a1) ] + h/2 [ f(a1) + f(a2) ] = h/2 [ f(a0) + 2 f(a1) + f(a2) ]

March 20, 2012

Copyright Box Hill Institute

Trapezoid rule (5)
When there are n equidistant intervals, the approximate value of the integral is equal to  =(h/2) [ f(a0) + 2 f(a1) + 2f(a2) +……. + 2 f(an-1) + f(an)]

March 20, 2012

Copyright Box Hill Institute

An example : f(x) = ex
x
1.0

f(x)
2.718282

1.2

3.320117

1.4

4.055200

1.6

4.953032

1.8
March 20, 2012

6.049646
Copyright Box Hill Institute

Example (continued)
To evaluate the value of integral f(x) = exp(x) between x= 1.0 and 1.8  Suppose we take interval h = 0.4  Then a0 = 1.0, a1 =1.4, a2= 1.8  The value is given by
(0.4/2)[2.718282 + (2) 4.055200 + 6.049646]

= 3.375666
March 20, 2012

Copyright Box Hill Institute

Example (low interval length)
Suppose we take interval h = 0.2  Then a0 = 1.0, a1 =1.2, a2= 1.4 , a3 =1.6, a4= 1.8  The value is given by (0.2/2) [2.718282 + (2) 3.320117 + (2) 4.055200 + (2) 4.953032 + 6.049646 ] = 3.342463 Actual value is 3.331366
March 20, 2012

Copyright Box Hill Institute

Centre for Computer Technology

Simpson’s One Third Rule

Simpson’s one third rule (1)
In trapeziod rule,the curve is approximated by a line  In Simpson’s rule , the curve is approximated by a second degree polynomial  It requires even number of intervals

March 20, 2012

Copyright Box Hill Institute

Simpson’s one third rule (2)
Consider three equidistant points, a , (a+b)/2 and b, and a second degree polynomial f(x)= c0 +c1 x +c2 x2  So, we have, f(a) = c0 +c1 a +c2 a2,  f((a+b)/2) = c0 +c1 ((a+b)/2) +c2 ((a+b)/2) 2  And, f(b) = c0 +c1 b +c2 b2

March 20, 2012

Copyright Box Hill Institute

Simpson’s one third rule (3)
On integration of the second degree polynomial , the value of the integral equals c0 (b – a) +c1 (b2 – a2)/2 +c2 (b3 - a3)/3  This can be shown equal to ((b – a )/ 6)[f(a) + 4 f((a+b)/2) +f(b)] = ( h /3 ) [f(a) + 4 f((a+b)/2) +f(b)]

March 20, 2012

Copyright Box Hill Institute

Simpson’s one third rule (4)
If we denote the points as a0, a1, a2 and h is the interval length, the value of the integral is (h/3)[ f(a0) + 4f (a1) + f(a2)]  In general case, the value equals (h/3)[ (f(a0) + 4f (a1) + f(a2)) + (f(a2) + 4f (a3) + f(a4)) + (f(a4) + 4f (a5) + f(a6)) + ….]

March 20, 2012

Copyright Box Hill Institute

Simpson’s one third rule (5)

This may be compactly written as (h/3)[ ( f(a0) + f (an) ) + 4 (f(a1) + f (a3) + f(a5)+… f(an-1) ) + 2 (f(a2) + f (a4) + f(a6) + .. f(an-2) ) ] Remember that the number of intervals have to be even

March 20, 2012

Copyright Box Hill Institute

An example : f(x) = ex
To evaluate the value of integral f(x) = exp (x) between x= 1.0 and 1.8  Suppose we take interval h = 0.4  Then a0 = 1.0, a1 =1.4, a2= 1.8  The value is given by

(0.4/3)[2.718282 + (4) 4.055200 + 6.049646]

= 3.331831
March 20, 2012

Copyright Box Hill Institute

Example (less interval length)
Suppose we take interval h = 0.2  Then a0 = 1.0, a1 =1.2, a2= 1.4 , a3 =1.6, a4= 1.8  The value is given by (0.2/3) [ (2.718282 + 6.049646) + 4 ( 3.320117 + 4.953032) + 2 ( 4.055200) ] = 3.331395 As noted earlier, the actual value is 3.331366
March 20, 2012

Copyright Box Hill Institute

Summary

Newton’s Forward Difference Formula f/(x)= (1/h) [ Δ –1/2 Δ2 ++1/3 Δ3 –1/4 Δ4 +….]

Newton’s Backward Difference Formula f/(x)= (1/h) [ +1/2 2+1/3 3 + 1/4 4+..]
Copyright Box Hill Institute

March 20, 2012

Summary

Trapezoid Rule = (h/2) [ f(a0) + 2 f(a1) + 2f(a2) +……. + 2 f(an-1) + f(an)] Simpson’s One Third Rule (the number of intervals have to be even) = (h/3)[ ( f(a0) + f (an) ) + 4 (f(a1) + f (a3) + f(a5)+… f(an-1) ) + 2 (f(a2) + f (a4) + f(a6) + .. f(an-2) ) ]
Copyright Box Hill Institute

March 20, 2012

References


H L Verma and C W Gross : Introduction to Quantitative Methods,John Wiley JB Scarborough : Numerical Mathematical Analysis, Jon Hopkins Hall, New Jersey Gerald W. Recktenwald, Numerical Methods with MATLAB, Implementation and Application, Prentice Hall Murray Spiegel, John Schiller, Alu Srinivasan, Probability and Statistics, Schaums easy Outlines http://mathworld.wolfram.com
Copyright Box Hill Institute

March 20, 2012

Master your semester with Scribd & The New York Times

Special offer for students: Only $4.99/month.

Master your semester with Scribd & The New York Times

Cancel anytime.