Lab 18 Interactive: Computational Complexity and Eigenvalue Computation

Compare operation counts, sparse storage, power-method convergence, and Rayleigh quotient estimates. This lab turns formulas such as $(AB)x=A(Bx)$ and $R_A(x)=\frac{x^TAx}{x^Tx}$ into experiments.

1. Cost comparison

Let $A\in\mathbb R^{m\times n}$, $B\in\mathbb R^{n\times p}$, and $x\in\mathbb R^p$.

2. Growth of $n$, $n\log n$, $n^2$, and $n^3$

The plot is log-scaled vertically so that different growth rates can be compared visually.

3. Power method for a $2\times2$ matrix

Edit $A$ and the initial vector $x_0$. The method normalizes at each step.

Matrix $A$

Initial vector $x_0$

4. Rayleigh quotient history

The black dots show the Rayleigh quotient $R_A(x_k)$ at each power-method iteration.

5. Sparse storage estimator

For an $N\times N$ tridiagonal matrix, $\operatorname{nnz}=3N-2$.

6. Generalized eigenvalue determinant

For $2\times2$ matrices, generalized eigenvalues solve $\det(A-\lambda B)=0$.

Default example: $A=\begin{bmatrix}1&2\\2&4\end{bmatrix}$, $B=\begin{bmatrix}1&1\\1&1\end{bmatrix}$.

7. Independent-study tasks with answers

Task A. Use $m=n=p=1000$. Compare forming $(AB)x$ first versus computing $A(Bx)$.
Answer: Forming $AB$ costs about $10^9$ operations; two matrix-vector products cost about $2\cdot10^6$ operations.
Task B. Try the slow convergence preset. Why is it slow?
Answer: The eigenvalue ratio $|\lambda_2/\lambda_1|$ is close to $1$.
Task C. Try the failure case. Why does it fail?
Answer: The initial vector has no component in the dominant eigendirection.
Similar practice. Use $A=\operatorname{diag}(5,2)$ and $x_0=(1,3)^T$. Predict the limiting direction before pressing the preset buttons.
Answer: The limiting direction is the $x$-axis, corresponding to the eigenvalue $5$.

8. Workspace