Page 270 - Applied Numerical Methods Using MATLAB
P. 270

PROBLEMS   259
                For example, the volume of a sphere with the radius of unit length (Fig.
                P5.13) can be obtained from this equation with Eq. (P5.12.2). Starting from
                the program “nm5p11.m”, make a program “nm5p13.m” that uses the numer-
                ical integration routines “smpsns()” (with the number of segments N=
                100), “adapt_smpsn()”, “quad()”, “quadl()” (with the error tolerance
                         −6
                tol=10 ), and “Gauss_Legendre()” (with the number of grid points
                M=2) to evaluate the integral (P5.13.1). Run the program and fill in
                Table P5.11 with the errors of the results, noting that the volume of a
                unit sphere is 4π/3.




















                                                          1
                    −1
                                 −0.5          0
                                                           0.5           1
                                     −1
                          Figure P5.13 The surface and the volume of a unit sphere.



            5.14 Double Integral
                 (a) Consider the following double integral


                          2     π             2                 2
                                                        π                  2
                    I =       y sin xdx dy =  −y cos x    dy =  2ydy = y  2    = 4
                                                      0                   0
                        0   0               0                 0
                                                                       (P5.14.1)
                    Use the routine “int2s()” (Section 5.10) with M=N= 20, M=N=
                    50 and M=N= 100 and the MATLAB built-in routine “dblquad()”
                    to compute this double integral. Fill in Table P5.14.1 with the results
                    and the times measured by using the commands tic/toc to be taken
                    for carrying out each computation. Based on the results listed in
                    Table P5.14.1, can we say that the numerical error becomes smaller
                    as we increase the numbers (M,N) of segments along the x-axis and
                    y-axis for the routine “int2s()”?
   265   266   267   268   269   270   271   272   273   274   275