\documentclass[12pt]{article}
\usepackage{fullpage,amsmath,amsfonts}

\newcommand{\x}{\boldsymbol{x}}
\renewcommand{\v}{\boldsymbol{v}}
\newcommand{\w}{\boldsymbol{w}}
\renewcommand{\a}{\boldsymbol{a}}
\renewcommand{\b}{\boldsymbol{b}}
\renewcommand{\c}{\boldsymbol{c}}
\newcommand{\e}{\mathrm{e}}
\renewcommand{\d}{\mathrm{d}}
\renewcommand{\i}{\mathrm{i}}
\renewcommand{\Re}{\operatorname{Re}}
\renewcommand{\Im}{\operatorname{Im}}
\newcommand{\Range}{\operatorname{Range}}
\newcommand{\Ker}{\operatorname{Ker}}
\newcommand{\Span}{\operatorname{Span}}
\renewcommand{\dim}{\operatorname{dim}}
\newcommand{\R}{\mathbb{R}}
\newcommand{\C}{\mathbb{C}}


\begin{document}


\title{Numerical Methods I -- Lab 7}
\author{Fall Semester 2005}
\date{November 22, 2005}
\maketitle

\begin{enumerate}

\item Write an \textsf{Octave} function for computing the weights
$w_i$ in the Newton--Cotes quadrature formula on $[0,1]$, where
\[
  \int_0^1 f(x) \, dx 
  \approx \sum_{i=0}^n w_i \, f(i/n) \,.
\]
Use the fact that Newton--Cotes quadrature is exact at least for all
polynomials of degree $\leq n$.  This yields $n+1$ linearly
independent equations for the $n+1$ unknown weights $w_i$ which can be
solved numerically; you are allowed to use the built-in
\textsf{Octave} linear algebra routines.  Compute the result up to
$n=10$.  For which $n$ do negative weights occur?

\emph{Optional.} The weights are rational numbers.  Write a program
for computing the rational expressions of the $w_i$.  You may use a
symbolic software package.

\item The computations in Part~1 might become problematic when $n >
10$ depending on the method used for solving the linear system $A w =
b$ for the weights.  Using \texttt{w=inv(A)*b} or $LU$-factorization,
you can document this by checking the error of the quadrature rule for
the monomials $f(x) = x^m$, $m = 0, \dots n$; if you have used these
$n+1$ linearly independent polynomials to derive the linear system in
Part~1, then this is equivalent to computing the residual $b - Aw$.
What is the reason for the observed instability?  How can you improve
the result?  Think of what you have learned about solving linear
systems.

\emph{Note:} There seems to be a lesser problem with using
\verb+w=A\b+.  What could be the reason?


\end{enumerate}

\noindent (Credits to P.O.)

\end{document}
