Hands-on-Numerical Differentiation and Integration with MATLAB

Composite Trapezoidal Rule. To approximate the integral

\begin{displaymath}
\int_a^b\approx\frac{h}{2}(f(a)+f(b))+h\sum_{k=1}^{M-1}f(x_k)
\end{displaymath}

by sampling $f(x)$ at the $M+1$ equally spaced points $x_k=a+kh$, for $k=0,1,2,\ldots,M$. Notice that $x_0=a$ and $x_M=b$.

\includegraphics[scale=1]{figures/5-10}
You are given the function $f(x)=2+sin(2\sqrt x)$ for the interval $[1 ,6 ]$.
  1. Plot the function.
  2. Use the composite trapezoidal rule with 11 sample points to compute an approximation to the integral of $f(x)$ taken over $[1 ,6 ]$ by using the MATLAB program given above.
  3. Do the error analysis. Error term for the composite trapezoidal rule is given as;

    \begin{displaymath}
E(f,h)=-\frac{(b-a)}{12}h^2f''(\xi)=O(h^2)
\end{displaymath}

  4. Calculate the exact value of the integration by using MATLAB. Compare your results for the aspects of integration and error analysis.
  5. Repeat the procedure with increased number of sample points. Solution:

    \includegraphics[scale=1]{figures/5-11}

    save with the name week12lsg.m. Then;

    >> vec=[10 20 40 50 100 500 1000]';
    >> week12lsg(?,?,?,vec);
    
Cem Ozdogan 2011-01-05