The Problem: How Many Terms?¶
Recall that spectral methods approximate the solution to a boundary value problem as:
where are Chebyshev polynomials and are unknown coefficients we need to find.
The challenge: We don’t know in advance!
Choose too small → the solution is inaccurate
Choose too large → we waste computation solving a bigger system
The Naive Approach: Double and Retry¶
The obvious strategy:
Try , solve the system, check if accurate enough
If not, try , solve again from scratch
If not, try , solve again from scratch
...
Problem: Each time we double , we throw away all the work we did before!
The Key Insight: Build the Solution Incrementally¶
Instead of solving separate problems for , then , etc., the adaptive QR algorithm:
Starts solving with term
Adds one term at a time, updating the solution
Checks at each step: “Is this accurate enough?”
Stops as soon as the answer is “yes”
The magic: Step 2 can be done efficiently using Givens rotations, and step 3 gives us the residual for free as a byproduct of the computation!
From ODE to Linear System¶
When we discretize a boundary value problem using spectral collocation, we get a linear system:
where:
are the Chebyshev coefficients we want
encodes the differential operator (e.g., second derivative) in coefficient space
encodes the right-hand side and boundary conditions
A Special Structure: “Almost Banded”¶
Here’s the key observation that makes everything work. The matrix has a very special structure:
┌─────────────────────────────────────────┐
│ K rows from boundary conditions │ ← Dense rows (usually 2)
├─────────────────────────────────────────┤
│ │
│ Banded part from the ODE │ ← Only a few diagonals
│ │
└─────────────────────────────────────────┘The top few rows (one per boundary condition) are dense
The rest of the matrix is banded—only a few diagonals are nonzero
Why is this useful? Banded matrices can be factored in operations instead of . The “almost banded” structure preserves most of this efficiency!
QR Factorization: A Quick Review¶
Recall that any matrix can be factored as:
where is orthogonal () and is upper triangular.
To solve :
Compute
Compute (easy, just matrix-vector multiply)
Solve by back-substitution
The key property of : Since is orthogonal, it preserves lengths:
This will be crucial for understanding the residual!
Givens Rotations: Building QR One Column at a Time¶
A Givens rotation is a simple orthogonal matrix that zeros out one element:
where (so and for some angle ).
When we apply to a 2-vector:
By choosing and , we can zero out while preserving the length .
Using Givens to Zero a Column¶
To create zeros below the diagonal in column of a matrix:
Before column j: After applying Givens:
column j column j
↓ ↓
[ × × × × × ] [ × × × × × ]
[ 0 × × × × ] [ 0 × × × × ]
[ 0 0 × × × ] → [ 0 0 × × × ] ← R[j,j]
[ 0 0 a × × ] [ 0 0 0 × × ] ← zeroed!
[ 0 0 b × × ] [ 0 0 0 × × ] ← zeroed!We apply a sequence of Givens rotations, each zeroing one entry below the diagonal.
Important: We apply the same rotations to the right-hand side !
The Adaptive QR Algorithm¶
Now we can explain the algorithm. Here’s the beautiful idea:
Step 1: Process Columns One at a Time¶
Instead of building the full matrix and then factoring it, we:
Start with just column 1
Apply Givens rotations to make it upper triangular
Add column 2, apply more Givens rotations
Add column 3, apply more Givens rotations
...continue...
At each step, we have a partial QR factorization of the columns processed so far.
Step 2: Check the Residual (For Free!)¶
Here’s the magic. After processing columns, the transformed system looks like:
The top rows form an upper triangular system
The bottom rows have zeros in the first columns
The key theorem:
Proof 1
Step 3: Stop When Accurate Enough¶
The algorithm becomes:
for j = 1, 2, 3, ...
1. Add column j to the system
2. Apply Givens rotations to zero entries below diagonal
3. Apply same rotations to right-hand side b
4. Check: is ||r_{j+1:end}|| < tolerance?
- If YES: stop, n_opt = j
- If NO: continue to j+1
Solve R_{n_opt} c = r_{1:n_opt} by back-substitutionWe get the optimal and the solution simultaneously!
Why “Almost Banded” Matters¶
Remember the matrix structure:
┌─────────────────────────────────────────┐
│ K dense boundary rows │
├─────────────────────────────────────────┤
│ Banded part (bandwidth m) │
└─────────────────────────────────────────┘When we apply Givens rotations:
Each column only has about entries below the diagonal (because of banding)
So we only need about Givens rotations per column
Total work: instead of
The dense boundary rows cause some “fill-in” (new nonzeros created), but this is limited and can be tracked efficiently.
Example: Second-Order BVP¶
Consider the problem:
The almost-banded structure arises because:
Boundary rows: and involve all Chebyshev coefficients (dense)
Interior rows: The relation between Chebyshev coefficients of and is local (banded)
For the ultraspherical spectral method (a sophisticated variant), the bandwidth is small:
Second derivative: bandwidth 3
Fourth derivative: bandwidth 5
This means we can solve BVPs with spectral accuracy in just operations!
Putting It All Together¶
The adaptive QR algorithm combines several ideas we’ve seen:
| Concept | Role in Algorithm |
|---|---|
| Chebyshev polynomials | Basis functions with exponential convergence |
| Spectral collocation | Turns ODE into linear system |
| Almost-banded structure | Enables factorization |
| QR factorization | Stable way to solve the system |
| Givens rotations | Builds QR incrementally |
| Orthogonal transformations preserve norms | Gives us the residual for free |
The result: An algorithm that automatically finds how many Chebyshev coefficients are needed, solves the system, and verifies the accuracy—all in a single pass through the columns!
Practical Impact¶
This algorithm (from Olver & Townsend, 2013) is implemented in software like Chebfun and enables:
Solving ODEs to 15 digits of accuracy automatically
Handling problems where the required resolution varies (e.g., boundary layers)
Systems of coupled ODEs with the same framework
Example 1 (Automatic Accuracy)
Consider solving on with .
With traditional spectral methods, you might:
Try , check residual: too big
Try , check residual: okay!
With adaptive QR:
Process columns 1, 2, 3, ...
At column 24, residual drops below 10-14
Stop and return the solution
No wasted work, and the residual check was free!
Looking Ahead¶
This algorithm illustrates a powerful principle in scientific computing: structure-exploiting algorithms. By understanding the mathematical structure of the problem (almost-banded matrices, orthogonal transformations, coefficient decay), we can design algorithms that are both:
Fast: instead of
Reliable: Automatic accuracy verification
This same philosophy—understanding structure to design better algorithms—appears throughout numerical analysis and is what makes scientific computing both an art and a science.
References¶
Olver, S. and Townsend, A. (2013). “A Fast and Well-Conditioned Spectral Method.” SIAM Review, 55(3), 462-489.