How to numerically calculate a eigenvalue problem? Suppose we have a eigenvalue problem:
\begin{array}{c}
y^{\prime \prime}+\lambda y=0,0<x<l \\
y(0)=0,  y(l)=0
\end{array}
and we know the eigenvalue is $\lambda =\frac{n^{2}\pi ^{2}  }{l^{2}}  $, and eigenfunction $y\left ( x \right ) =C\sin \frac{n\pi x}{l}  $. But if I want to calculate the eigenvalue numerically, I think first I should choose basis for the funtion, and then represent the linear operator in ODE as a matrix. My question is what basis should I pick for this problem? Can I choose basis such as $\left \{1,x,x^{2} , x^{3},... \right \}$  ?
The eigenvalue for this problem is also determined by the boundary conditons, but how does the boundary conditons affect the matrix?
I also found people with related  question:(Solve the eigenvalue problem $y''=\lambda y$ numerically), and he numerically calculate the problem using finite difference. It seems that his method do not need to find basis. Is this a trick to solve this problem or still related to some kind of basis I am not aware of?
 A: OK, let's try using that basis.  If $y(x) = \sum_{i=0}^\infty a_i x^i$, the differential equation tells you
$$ (i+2)(i+1) a_{i+2} + \lambda a_i = 0$$
the boundary condition at $0$ says $a_0 = 0$, but the boundary condition at $\ell$ says
$$ \sum_{i=0}^\infty a_i \ell^i = 0$$
It's easy to see that $a_{2j} = 0$ and
$$a_{2j+1} = a_1 \frac{(-\lambda)^j}{(2j+1)!} $$
Of course we happen to know that this makes $y(x) = a_1 \sin(\sqrt{\lambda} x)/\sqrt{\lambda}$, but let's pretend we didn't know that and see what we could do numerically.  Truncating the series, we'd be looking for solutions of the polynomial
equation
$$ \sum_{j=0}^N \frac{(-\lambda)^j \ell^{2j+1}}{(2j+1)!} = 0 $$
Of course we'll only get finitely many roots; moreover, only some of them will be
approximations of the actual eigenvalues.  In this case it helps to know that this is a self-adjoint problem so the eigenvalues should be real, and therefore we can ignore the non-real roots of the polynomial.  For example, if we take $N=20$ and $\ell = 1$
the real roots, according to Maple, are approximately
$$ 9.86960440108936, 39.4784176043574, 88.8264396100380, 157.913599364066, 248.158150630799, 285.945743386340$$
of which the first four are close to the actual eigenvalues $\pi^2$, $4 \pi^2$, $9 \pi^2$ and $16 \pi^2$, but the last two are not close to actual eigenvalues.
A: The next idea is the Ritz-Galerkin method, set $y(x)=N(x)\beta$, $N(x)$ some row-vector valued function with $N(0)=N(l)=0$ and insert. This gives an over-determined problem, dimension of $\beta$ to infinity. This can be solved as usual by multiplying with the transpose matrix, or here
$$
0=\int_0^l [ N(x)^TN''(x)+λN(x)^TN(x) ]\,\beta\,dx
=\int_0^l [ -N'(x)^TN'(x)+λN(x)^TN(x) ]\,\beta\,dx
$$
This results in a finite-dimensional (generalized) eigenvalue problem $Aβ= λBβ$ with symmetric positive (semi-)definite matrices $A,B$
