Spectral Methods in MATLAB

Up to now we have been solving ODEs, PDEs, and related eigenvalue problems. Now suppose that we are faced with the simpler task of evaluating an integral such as
How could we compute I by a spectral method?
One approach is to note that an integral is the special case of an ODE u ? = f ( x, u) in which f is independent of u. Thus (12.1) can be restated as the initial value problem
where our goal is to evaluate I = u(1). For this we can set up a spectral method on [ ?1, 1] on our usual Chebyshev grid. To impose the boundary condition u( ?1) = 0, we strip off the last row and column of the differentiation matrix D N in the usual manner described in Chapter 7. If
is the resulting matrix of dimension N N, we are left with the linear system of equations
with f = ( f( x 0), , f ( x N ?1)) T. Our approximation to I is given by I N = v 0.
In fact, since we care only about the first component of v, there is no need to solve the whole system of equations. If we let w T denote the first row of
, a row vector of length N,...