Page 104 -
P. 104

∫ π    2
                             Pb. 4.24         2   dx
                                       0  1+ cos ( )x



                             Example 4.6
                                                               ∫ x
                             Plot the value of the indefinite integral   0  fx dx()   as a function of x, where f(x)
                             is the function sin(x) over the interval [0, π].

                             Solution: We solve this problem for the general function f(x) by noting that:


                                           ∫ 0 x  f x dx()  ≈ ∫ 0 x−∆ x  f x dx()  +  f x( − ∆ x + ∆ x / )2 ∆ x  (4.5)



                             where we are dividing the x-interval into subintervals and discretizing x to
                             correspond to the coordinates of the boundaries of these subintervals. An
                             array {x } represents these discrete points, and the above equation is then
                                    k
                             reduced to a difference equation:

                                          Integral(x ) = Integral(x ) + f(Shifted(x ))∆x    (4.6)
                                                               k–1
                                                   k
                                                                             k–1
                             where
                                                   Shifted(x ) = x  + ∆x/2                  (4.7)
                                                           k–1
                                                                 k–1
                             and the initial condition is Integral(x ) = 0.
                                                             1
                              The above algorithm can then be programmed, for the above specific func-
                             tion, as follows:

                                a=0;
                                b=pi;
                                dx=0.001;
                                x=a:dx:b-dx;
                                N=length(x);
                                xshift=x+dx/2;
                                yshift=sin(xshift);
                                Int=zeros(1,N+1);
                                Int(1)=0;
                                   for k=2:N+1
                                   Int(k)=Int(k-1)+yshift(k-1)*dx;



                             © 2001 by CRC Press LLC
   99   100   101   102   103   104   105   106   107   108   109