Integration (1)

6
Z b a f (x) dx a, b n T (f ; P ) P (a = x 0 <x 1 <x 2 < ...................... <x n = b) i th A i = Z x i+1 x i f (x) dx = {x i+1 - x i 1 2 n f (x i) + f (x i+1 ) o T (f ; P )= Z b a f (x) dx = n-1 X i=0 A i = 1 2 n-1 X i=0 {x i+1 - x i } n f (x i) + f (x i+1 ) o n x i x i+1 h = b - a n x i = a + ih x i+1 - x i = h T (f ; P )= Z b a f (x) dx = h 2 n-1 X i=0 n f (x i) + f (x i+1 ) o = h 2 {[f (x 0 )+ f (x 1 )] + [f (x 1 )+ f (x 2 )] + [f (x 2 )+ f (x 3 )] + ....................... +[f (x n-1 )+ f (x n )]} x i x 0 x n T (f ; P )= Z b a f (x) dx = h 2 {f (a)+ f (b)} + h n-1 X i=1 f (a + ih)

description

class note

Transcript of Integration (1)

  • Numerical Integration (nite integrals)

    Trapezoid method

    In order to nd the integral baf(x) dx

    in the interval [a, b], we use the area under the curve method.

    Divide the area under the curve into n tapezoids (Fig. (a)) Calculate the area of each trapezoid Sum all areas Total area is denoted by T (f ;P ), where P (a = x0 < x1 < x2 < ...................... < xn = b).

    Area of the ith trapezoid (Fig. (b))

    Ai = xi+1xi

    f(x) dx = {xi+1 xi} 12

    {f(xi) + f(xi+1)

    }Total area

    T (f ;P ) = baf(x) dx =

    n1i=0

    Ai =1

    2

    n1i=0

    {xi+1 xi}{f(xi) + f(xi+1)

    }Here we have not specied the nature of division into n trapezoids. Without loss of generality,we can divide uniform spacing between xi and xi+1. This implies that the spacing between thetwo iintervals

    h =b an

    so that xi = a+ ih and xi+1 xi = h. Then

    T (f ;P ) = baf(x) dx =

    h

    2

    n1i=0

    {f(xi) + f(xi+1)

    }

    =h

    2{[f(x0) + f(x1)] + [f(x1) + f(x2)] + [f(x2) + f(x3)] + .......................+ [f(xn1) + f(xn)]}Since each xi term gets added twice other than x0 and xn, we can write

    T (f ;P ) = baf(x) dx =

    h

    2{f(a) + f(b)}+ h

    n1i=1

    f(a+ ih) (1)

    This is the basic trapezoid method.

    1

  • Problem:

    Write a Fortran 90 program to nd the integral 10

    4

    1 + x2dx

    using Eqn. (1).

    Recursive Trapezoid

    We see that the accuracy of the calculation depends on the number of intervals n. Thus we canuse the recursive method to improve the accuracy. In this case, we divide the interval [a, b] into2n equal intervals rather than n intervals and replace the notation T (f ;P ) by R(n, 0). Then

    R(n, 0) = baf(x) dx = hC + h

    2n1i=1

    f(a+ ih) (2)

    We see that while calculating R(n, 0), we also evaluate the function at points which is alreadyevauated by R(n 1, 0). This repeatation of the calculation can be avoided by the followingsimplication. Take for example,

    R(2, 0) = hC + h {f(a+ h) + f(a+ 2h) + f(a+ 3h)}R(3, 0) = hC + h {f(a+ h) + f(a+ 2h) + f(a+ 3h) + f(a+ 4h)

    + f(a+ 5h) + f(a+ 6h) + f(a+ 7h)}Since h = h/2

    R(3, 0) =h

    2C +

    h

    2

    {f(a+

    h

    2) + f(a+ h) + f(a+

    3

    2h) + f(a+ 2h)

    + f(a+5

    2h) + f(a+ 3h) + f(a+

    7

    2h)

    }While calculating R(3, 0), we can use 1

    2R(2, 0) and then the remaining terms in R(3, 0).

    R(3, 0) 12R(2, 0) =

    h

    2

    {f(a+

    h

    2) + f(a+

    3

    2h) + f(a+

    5

    2h) + f(a+

    7

    2h)

    }

    = h {f(a+ h) + f(a+ 3h) + f(a+ 5h) + f(a+ 7h)}This implies that

    R(3, 0) =1

    2R(2, 0) +

    {R(3, 0) 1

    2R(2, 0)

    }This can be generalized as

    R(n, 0) =1

    2R(n 1, 0) +

    {R(n, 0) 1

    2R(n 1, 0)

    }(3)

    2

  • From eqn.(2), we have

    R(n, 0) = hC + h2n1i=1

    f(a+ ih)

    R(n 1, 0) = hC + h2n1j=1

    f(a+ jh)

    But h = 2h. Hence

    R(n 1, 0) = 2hC + 2h2n1j=1

    f(a+ 2jh)

    R(n, 0) 12R(n 1, 0) = h

    2n1i=1

    f(a+ ih) h2n1j=1

    f(a+ 2jh) = h2n1k=1

    f(a+ [2k 1]h)

    Hence Eqn. (3) can be written as

    R(n, 0) =1

    2R(n 1, 0) + h

    2n1k=1

    f(a+ [2k 1]h) (4)

    For example

    R(3, 0) =1

    2R(2, 0) + h {f(a+ h) + f(a+ 3h) + f(a+ 5h) + f9(a+ 7h)}

    which is same as the one calcuated earlier. All the even terms get calculaed in the R(2, 0) term,and the odd terms are added to the new term.

    Problem:

    Write a Fortran 90 program to nd the integral 10

    4

    1 + x2dx

    using Eqn. (4).

    Romberg Algorithm

    The recursive trapezoid can be further extrapolated using Romberg Algorithm to improve the

    accuracy. Instead of calculating R(n, 0), one can calculate R(n,m), extraplated from R(n, 0)using the equation

    R(n,m) = R(n,m 1) + 14m 1 {R(n,m 1)R(n 1,m 1)} (5)

    This will form a triangular matrix of the form

    R(0, 0) h = b aR(1, 0) R(1, 1) h1 = h/2R(2, 0) R(2, 1) R(2, 2) h2 = h1/2.... ....... ..... ..........

    R(n, 0) ...... ........ ........ R(n, n) hn = hn1/2

    For exampe:

    R(2, 1) = R(2, 0) +1

    3{R(2, 0)R(1, 0)}while R(0, 0) is given by

    R(0, 0) =1

    2(b a) {f(a) + f(b)}

    3

  • Problem:

    Write a Fortran 90 program to nd the integral 10

    4

    1 + x2dx

    using Eqn. (5).

    Simpson's rule for integration

    Basic Simson's equation a+2ha

    f(x) dx h3{f(a) + 4f(a+ h) + f(a+ 2h)} (6)

    Problem:

    Write a Fortran 90 program to nd the integral 10

    4

    1 + x2dx

    using Eqn. (5).

    Error Estimation

    f(a+ h) = f(a) + hf +h2

    2f +

    h3

    6f +

    h4

    24f + ...............

    f(a+ 2h) = f(a) + 2hf +4h2

    2!f +

    8h3

    3!f +

    16h4

    4!f + ...............

    = f(a) + 2hf + 2h2f +4h3

    3f +

    2h4

    3f + ...............

    4f(a+ h) = 4f(a) + 4hf + 2h2f +2h3

    3f +

    h4

    6f + ...............

    f(a) + 4f(a+ h) + f(a+ 2h) = 6f(a) + 6hf + 4h2f + 2h3f +5h4

    6f + ...............

    h

    3{f(a)+4f(a+h)+f(a+2h)} = 2hf(a)+2h2f + 4

    3h3f +

    2

    3h4f +

    5h5

    18f + ............... (7)

    Eqn. (7) is the RHS of eqn. (6), the basic Simpson.

    Now consider another arbitrary function F and take the expansion at a+ 2h. i.e.,

    F (a+ 2h) = F (a) + 2hF + 2h2F +4h3

    3F +

    2h4

    3F + ...............

    If we take

    F (x) = xaf(t) dt (8)

    then F (a) = 0, F = f , F = f , F = f , ......., etc. Then eqn. (8) can be written as a+2ha

    f(x) dx = F (a+ 2h) = 2hf + 2h2f +4h3

    3f +

    2h4

    3f +

    4h5

    15f + ............... (9)

    =h

    3{f(a) + 4f(a+ h) + f(a+ 2h)} 5h

    5

    18f +

    4h5

    15f + ......... (10)

    using eqn. (7). This implies a+2ha

    f(x) dx =h

    3{f(a) + 4f(a+ h) + f(a+ 2h)}+O(h5)That is, basic Simpson is accuracte upto the order of h5.

    4

  • Adaptive Simpson Method

    In order to improve the accuracy further, Adaptive Simpson method is used where the interval

    [a,b] is further divided into subintravals and basic Simpson is used in each interval and summed

    together. Basic Simpson (1-Simpson) can be written as

    I = baf(x) dx = S1[a, b] + E1[a, b] (11)

    where integral value

    S1[a, b] =h

    3{f(a) + 4f(a+ h) + f(a+ 2h)}and the error

    E1[a, b] = 190h5f

    In 2-Simpson, the inerval [a,b] is divided into two equal subintervals [a,c] and [c,b], where c is

    the midpoint of [a,b]. 1-Simpson is calculated in each interval and added together to obtain I.That is

    I = S2[a, b] + E2[a, b] (12)

    where

    S2[a, b] = S1[a, c] + S1[c, b] (13)

    E2[a, b] = E1[a, c] + E1[c, b] = 190

    (h

    2

    )5f 1

    90

    (h

    2

    )5f =

    1

    16E1[a, b] (14)

    From eqn. (11) and eqn. (12), we have

    S2[a, b] S1[a, b] = E1[a, b] E2[a, b] = 15E2[a, b] (15)

    From eqn. (12)

    I = S2[a, b] + E2[a, b] = S2[a, b] +1

    15

    {S2[a, b] S1[a, b]

    }(16)

    Thus we can use the second term as an accuracy check for guiding the adaptive process. i.e.,

    check whether

    1

    15

    S2[a, b] S1[a, b] < for exiting the loop. Otherwise, the intervals are further divided and the Simpsons are calculated

    for each interval and summed.

    Method:

    Since a+2h = b, h = (b a)/2 and c = (a+ b)/2, calculate S1[a, b] and S2[a, b] using thefollowing equations

    S1[a, b] =h

    6

    {f(a) + 4f

    (a+ b

    2

    )+ f(b)

    }

    S2[a, b] =h

    12

    {f(a) + 4f

    (a+ c

    2

    )+ 2f(c) + 4f

    (c+ b

    2

    )+ f(b)

    }

    If |S2 S1| < 15, where is the required accuracy, then exit and the integral value willbe

    I[a, b] =1

    15

    {16S2 S1

    }(17)

    5

  • If |S2 S1| > 15, then divide the interval [a,b] into two subintervals [a,c] and [c,b] andcalculate S1 and S2 for each interval.

    Check whether the condition, |S2 S1| < 15 2, is satised for each interval. If it satises

    both the intervals, then I[a, b] = I[a, c] + I[c, b] where I[a, c] and I[c, b] are given by thecondition from Eqn. (17).

    The process can be continued until the required condition is satised for each subinterval.

    6