Spectral Methods in MATLAB

We have defined the Chebyshev differentiation matrix D N and put together a MATLAB program, cheb, to compute it. In this chapter we illustrate how such matrices can be used to solve some boundary value problems arising in ordinary and partial differential equations.
As our first example, consider the linear ODE boundary value problem
This is a Poisson equation, with solution u( x) = [ e 4x ? x sinh(4) ? cosh(4)]/16. We use the PDE notation u xx instead of u ? because we shall soon increase the number of dimensions.
To solve the problem numerically, we can compute the second derivative via D 2 N, the square of D N. The first thing to note is that D 2 N can be evaluated either by squaring D N which costs O( N 3) floating point operations, or by explicit formulas [GoLu83a, Pey86] or recurrences [WeRe00, Wel97], which cost O( N 2) floating point operations. There are real advantages to the latter approaches, but in this book, for simplicity, we just square D N.
The other half of the problem is the imposition of the boundary conditions u( 1) = 0. For simple problems like (7.1) with homogeneous Dirichlet boundary conditions, we can proceed as follows. We take the interior Chebyshev points x 1, , x N ? 1 as our computational grid, with v = (