As example, we considered the problem
2
d u(x) 2
------- + k u(x) = 0, u(0) = 0 and u(1) = 0.
2
d x
The following sequence of commands (for Octave or MATLAB)
generates the matrix and computes its eigenvalues:
n = 10; h = 1/(n+1); a = diag(2*ones(1:n))-diag(ones(1:n-1),-1)-diag(ones(1,n-1),+1); e = eig(a); k2 = e/h^2; k = sqrt(k2) k/piThe output is
k = 3.1309 6.1981 9.1391 11.8941 14.4069 16.6265 18.5076 20.0119 21.1088 21.7761 ans = 0.99660 1.97292 2.90908 3.78601 4.58587 5.29238 5.89114 6.36999 6.71915 6.93154We see the first n multiples of Pi appearing.
We derived the Power method to compute the eigenvector with the dominant eigenvalue and derived some variants of this method: the inverse and shifted power method.