Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

DSE-1:

1: Numerical Techniques
Techniques-Unit-4
Numerical integration: The basic problem in numerical integration is to
compute an approximate solution to a definite integral to a given degree of
accuracy. It is useful when the explicit function is not known and some samples of
the function are available or the function is complicated to find the integration.
integration
Trapezoid rule: In numerical analysis
analysis, the trapezoidal rule (also known as
the trapezoid rule or trapezium rule) is a technique
technique for approximating the definite
integral.

The trapezoidal rule works by approximating the region under the graph of the
function as a trapezoid and calculating its area.

The function f(x) (in blue) is


approximated by a linear function (in
red).
It follows that

The integral can be even better


approximated by partitioning the area
under the curve to intervals, applying the
trapezoidal rule to each subinterval, and
summing the results.
Let f(x) be continuous on [a,b]. We partition the interval [a, b] into n equal
subintervals, each of width h = (b−a)/n, such that a = x0 < x1< x2< ... < xn = b.
Area of the 1st trapezium = h*(y0 + y1)/2
Area of the 2nd trapezium = h*(y1 + y2)/2
.
.
.
Area of the nth trapezium= h*(yn-1 + yn)/2
So,

∫ab f(x) dx ≈ h/2[(y0+yn) +2(y1+y2+y3+…. +yn-1)]


The approximation becomes more accurate as the number of partitions increases.
Example: A function f(x) is given by the table of values. Approximate the area under
the curve y = f(x) between x = 0 and x = 8 using the Trapezoidal Rule
with n = 4 subintervals.

x 0 2 4 6 8

f(x) 3 7 11 9 3

Solution: The Trapezoidal Rule formula for n = 4 subintervals has the form

∫08 f(x) dx = h/2[(y0+y4) +2(y1+y2+y3)]


The width of the subinterval is h = (8−0)/4 = 2. Substituting the values of the function
from the table, we find the approximate area under the curve:
A = 2/2 [3 + 3 + 2(7 + 11 + 9)]
= 6 + 54
= 60

Simpson's 1/3 Rule:

Manas Ku Mishra, Asst. Prof. of Comp. Sc., FM (A) College, BLS. Page 2 of 9
Simpson's method is a method for numerical integration, the
nd
numerical approximation of definite integrals. Specifically, it is 2 degree polynomial
approximation for n+1 values x0, x1, .................. xn boudnding n eaually spaced
divisions. It takes 2 strips for local integration.
The Simpson’s 1/3 rule can be written as follows:

∫ab f(x) dx ≈ h/3[(y0+yn) +4(y1+y3+y5+…. +yn-1) +2(y2+y4+y6+…..+yn-2)]


Where, n is the number of strips
y = f(x)

y0 = f(x0) = f0

y1 = f(x1) = f1 ... and so...on

h = (b–a)/n = (xn – x0)/n


Example-1: A function f(x) is given by the table of values. Approximate the area
under the curve y=f(x) between x=0 and x=4 using Simpson’s 1/3 Rule
with n=4 subintervals.

x 0 1 2 3 4

f(x) 2 7 12 10 5

Solution: For n = 4 subintervals, Simpson’s 1/3 rule is given by the following


equation: S4 = h/3[(y0+y4)+4*(y1+y3) +2*(y2)]
Where the width of the subinterval is h = (b−a)/n = (4−0)/4 = 1.
Substituting the values of the function from the table, the approximate value of the
area under the curve can be calculated as follows:
A ≈ 1/3[(2+5) + 4*(7+10) + 2*12] = 1/3[7+68+24] = 99/3 =33
Simpson’s 3/8 Rule: Simpson’s 3/8 Rule for numerical integration uses 3rd
degree polynomial approximation. It takes 3 strips for local integration. The formula
can be writtern as follows:

∫ab f(x) dx ≈ 3h/8[(y0+yn) + 3(y1+y2+y4+y5+…. +yn-2+yn-1) + 2(y3+y6+y9+…..+yn-3)]


Where, n is the number of strips and
h = (b–a)/n = (xn – x0)/n

Manas Ku Mishra, Asst. Prof. of Comp. Sc., FM (A) College, BLS. Page 3 of 9
Example: Find Solution of an equation 1/x using Simpson's 3/8 rule for x = 1 to 2.
Take Step value (h) = 0.25

Solution: Equation is f(x) =1/x.


The value of the table for x and y can be constructed as follows:

x 1 1.25 1.5 1.75 2

f(x) 1 0.8 0.6667 0.5714 0.5

Using Simpson's 3/8 Rule


∫ f(x)dx = 3h/8[(y0+y4) + 3(y1+y2) + 2(y3)]
∫ f(x)dx = 3×0.25/8[(1+0.5) + 3×(0.8+0.6667) + 2×(0.5714)]
∫ f(x)dx = 3×0.25/8[(1+0.5) ) + 3×(1.4667) + 2×(0.5714]
∫ f(x)dx = 0.6603
Solution by Simpson's 3/8 Rule is 0.6603

Newton−Cotes formulas: In numerical analysis, the Newton–Cotes formulas,


also called the Newton–Cotes quadrature rules or simply Newton–Cotes rules,
are a group of formulas for numerical integration based on evaluating the integrand
at equally spaced points. They are named after Isaac Newton and Roger Cotes. The
formulas are as follows:

Degree
of
Step Common
approxi Formula Remark
size, h name
mation,
n

(b – a)/n n is any
Trapezoidal h/2[(y0+yn)
1 = positive
rule +2(y1+y2+y3+…. +yn-1)]
(xn–x0)/n integer

(b – a)/n h/3[(y0+yn) n is a positive


Simpson’s
2 = +4(y1+y3+y5+…. +yn-1) integer
1/3 rule
(xn–x0)/n +2(y2+y4+y6+…..+yn-2)] multiple of 2

(b – a)/n 3h/8[(y0+yn) n is a positive


Simpson’s
3 = +3(y1+y2+y4+y5+…. +yn-2+yn-1) integer
3/8 rule
(xn–x0)/n +2(y3+y6+y9+…..+yn-3)] multiple of 3

Manas Ku Mishra, Asst. Prof. of Comp. Sc., FM (A) College, BLS. Page 4 of 9
Gaussian quadrature: The Gauss quadrature rule of approximating integrals is

Where Weighting factors c and function arguments x used in Gauss quadrature


formulas for different values of n is listed in the following table.

Number of Points, n Weighting Factors Function Arguments

c1 = 1 x1 = -1/√3 = −0.577350269
2
c2 = 2 x2 = 1/√3 = 0.577350269
√3
c1 = 5/9 = 0.555555556 x1 = 5
= −0.774596669
3 c2 = 8/9 = 0.888888889 x2 = 0
c3 = 5/9 = 0.555555556 x = √3 = 0.774596669
3
5

c1 = 0.347854845 x1 = -0. 861136312


c2 = 0.652145155 x2 = -0.339981044
4
c3 = 0.652145155 x3 = 0.339981044
c4 = 0.347854845 x4 = 0.861136312

Now the integration, I = can be written as

I = =

The change of integration from a to b, to -1 to 1 can be made by putting


t = (2x – a – b) / (b – a)
when x = a, t = -1 & when x = b, t = 1

Example-1:

= 1 * (−0.577350269) + 1 * 0.577350269

=0

The above example shows the solution of two point form.

Manas Ku Mishra, Asst. Prof. of Comp. Sc., FM (A) College, BLS. Page 5 of 9
Example-2:

= 0.555555556 * (−0.774596669) + 0.888888889 * 0 +


0.555555556 * 0.774596669

=0

The above example shows the solution of three point form.

f(x) = ∫01exdx = e1 – e0 = 2.71828 – 1 = 1.71828 (by using integration


Example:
formula)

Now let us find evaluate the integral by using 2 point Gaussian quadrature rule.

put t = (2x-0-1)/(1-0)

= 2x-1

 x = (t+1)/2

 dx = ½ dt

So ∫01exdx = ∫-11e(t+1)/2 ½ dt = ½ ∫-11e(t+1)/2 dt

= ½ [1*e(−0.577350269+1)/2 + 1*e(0.577350269+1)/2]

= 1.717896

Ordinary differential equation:

Euler’s method: For many of the differential equations, we need to solve in the
real world, there may not exist an algebraic solution. As a result, we need to find an
approximate solution using numerical methods for solving such DEs. The Euler
method is a first-order numerical procedure for solving ordinary differential equations
(ODEs) with a given initial value. The Euler method is a first-order method, which
means that the local error (error per step) is proportional to the square of the step
size, and the global error (error at a given time) is proportional to the step size.

Consider a differential equation dy/dx = y′ = f(x, y) with initial condition y (xo) = yo,
then approximate solution to this equation by using Euler’s method is as follows:

yn+1 = yn + h f(xn, yn) for n = 0,1,2,3.......... where


xn+1 = xn + h

Manas Ku Mishra, Asst. Prof. of Comp. Sc., FM (A) College, BLS. Page 6 of 9
h indicates step size. Choosing smaller values of h leads to more accurate results
and more computation time.

Example: Given y′ = x + 2y, y (0) = 0, step size h = 0.25


Find value of y at x = 0.5
Solution:
x1 = xo + h = 0 + 0.25 = 0.25 Now, x2 = x1 + h = 0.25 + 0.25 = 0.5
Now, y1 = yo + h f(xo, yo) Now, y2 = y1 + h f(x1, y1)
= yo + h (xo + 2yo) = y1 + h (x1 + 2y1)
= 0 + 0.25 (0 + 2*0) = 0 + 0.25 (0.25 + 2*0)
 y(0.25) = 0  y(0.5) = 0.0625

the results can be summerized in a tabular form, as follows:

n xn yn

0 0 0 So the value of y at x = 0.5 is 0.0625


1 0.25 0 or y(0.5) = 0.0625

2 0.5 0.0625

Modified Euler’s method: Consider a differential equation dy/dx = y′ = f(x, y)


with initial condition y (xo) = yo, then approximate solution to this equation by using
modified Euler’s method is as follows:

yn+1,c = yn + h/2 [f(xn, yn) + f(xn+1, yn+1,p)] for n=0,1,2,3....... where


yn+1,p = yn + h f(xn, yn)

Where yn+1,p = yn + h f(xn, yn) is known as the predictor and


yn+1,c is known as the corrector.

Example: Given dy/dx = y – 2x2 + 1, y(0) = 0.5, step size h = 0.2 , Find y(0.2)
Solution: Given x0 = 0, y0 = 0.5, h = 0.2
So, y1,p = y0 + h f(x0, y0)
= 0.5 + 0.2*(0.5 – 2*02 + 1) = 0.5+ 0.2 * 1.5 = 0.5 + 0.3 = 0.8
Now, y1,c = y0 + h/2 [f(x0, y0) + f(x1, y1,p)
= 0.5 + 0.2/2 * [(0.5 – 2*02 + 1) + (0.8 - 2*0.22 + 1)]
= 0.5 + 0.1 * [(1.5) + (0.8 - 0.08 + 1)]

Manas Ku Mishra, Asst. Prof. of Comp. Sc., FM (A) College, BLS. Page 7 of 9
= 0.5 + 0.1 * (1.5+1.72)
= 0.5 + 0.1 * 3.22
= 0.5 + 0.322
= 0.822
So, y(0.2) = 0.822 (ans)

Runge-Kutta second methods: Consider a differential equation dy/dx = y′ = f(x, y)


with initial condition y(xo) = yo , then approximate solution to this equation by using
Runge-Kutta methods is as follows:

Runge-Kutta method of order 2 Runge-Kutta method of order 4

k1 = h f(xn, yn) k1 = h f(xn, yn)


k2 = h f(xn+h, yn+k1) k2 = h f(xn+h/2, yn+ k1/2)
yn+1 = yn + (k1 + k2)/2 k3 = h f(xn+h/2, yn+ k2/2)
k4 = h f(xn+h, yn+k3)
This formula is known as the second
y = yn + (k1 + 2k2 + 2k3+ k4)/6
order Runge-Kutta method. Here the n+1
local error is O (h3) and global error is This formula is known as the Runge-
O (h2). Kutta method of order 4. Here the local
error is O(h5) and global error is O(h4).

Example: Find y(0.2) for y′ = (x-y)/2, y(0) = 1, with step length 0.1 by using both
second order and fourth order R-K method.

Solution by using Second order R-K method


k1 = hf(x0,y0) = (0.1)f(0,1) = (0.1)*(-0.5) = -0.05
k2 = hf(x0+h,y0+k1) = (0.1)f(0.1,0.95) = (0.1)*(-0.425) = -0.0425
y1 = y0+(k1+k2)/2 = 1 + (-0.05-0.0425)/2 = 0.95375
∴ y(0.1) = 0.95375

Again taking (x1,y1) in place of (x0,y0) repeat the process


k1 = hf(x1,y1) = (0.1)f(0.1,0.95375) = (0.1)*(-0.42688) = -0.04269
k2 = hf(x1+h,y1+k1) = (0.1)f(0.2,0.91106) = (0.1)*(-0.35553) = -0.03555
y2 = y1+(k1+k2)/2 = 0.95375 + (-0.04269-0.03555)/2 = 0.75464
∴ y(0.2)=0.91463

Manas Ku Mishra, Asst. Prof. of Comp. Sc., FM (A) College, BLS. Page 8 of 9
Solution by using Forth order R-K method:
k1 = hf(x0,y0) = (0.1)f(0,1) = (0.1)*(-0.5) = -0.05
k2 = hf(x0+h/2,y0+k1/2) = (0.1)f(0.05,0.975) = (0.1)*(-0.4625) = -0.04625
k3 = hf(x0+h/2, y0+k2/2) = (0.1)f(0.05,0.97688) = (0.1)*(-0.46344) = -0.04634
k4 = hf(x0+h, y0+k3) = (0.1)f(0.1,0.95366) = (0.1)*(-0.42683) = -0.04268
y1 = y0 + (k1+2k2+2k3+k4)/6
y1 = 1 + [-0.05+2(-0.04625) + 2(-0.04634) + (-0.04268)]/6 = 0.95369
∴ y(0.1) = 0.95369

Again taking (x1,y1) in place of (x0,y0) repeat the process


k1 = hf(x1,y1) = (0.1)f(0.1,0.95369) = (0.1)*(-0.42684) = -0.04268
k2 = hf(x1+h/2,y1+k1/2) = (0.1)f(0.15,0.93235) = (0.1)*(-0.39118) = -0.03912
k3 = hf(x1+h/2,y1+k2/2) = (0.1)f(0.15,0.93413) = (0.1)*(-0.39206) = -0.03921
k4 = hf(x1+h,y1+k3) = (0.1)f(0.2,0.91448) = (0.1)*(-0.35724) = -0.03572
y2 = y1+(k1+2k2+2k3+k4)/6
y2 = 0.95369 + [-0.04268+2(-0.03912) + 2(-0.03921) + (-0.03572)]/6 = 0.91451
∴ y(0.2)=0.91451

Manas Ku Mishra, Asst. Prof. of Comp. Sc., FM (A) College, BLS. Page 9 of 9

You might also like