Method
Let
be a linear operator on a Hilbert space
, with inner product
. Now consider a finite set of functions
. Depending on the application these functions may be:
One could use the orthonormal basis generated from the eigenfunctions of the operator, which will produce diagonal approximating matrices, but in this case we would have already had to calculate the spectrum.
We now approximate
by
, which is defined as the matrix with entries[4]

and solve the eigenvalue problem
. It can be shown that the matrix
is the compression of
to
.[4]
For differential operators (such as Sturm-Liouville operators), the inner product
can be replaced by the weak formulation
.[5][7]
If a subset of the orthonormal basis was used to find the matrix, the eigenvectors of
will be linear combinations of orthonormal basis functions, and as a result they will be approximations of the eigenvectors of
.[8]
For matrix eigenvalue problems
In numerical linear algebra, the Rayleigh–Ritz method is commonly[13] applied to approximate an eigenvalue problem
for the matrix
of size
using a projected matrix of a smaller size
, generated from a given matrix
with orthonormal columns. The matrix version of the algorithm is the most simple:
- Compute the
matrix
, where
denotes the complex-conjugate transpose of 
- Solve the eigenvalue problem

- Compute the Ritz vectors
and the Ritz value 
- Output approximations
, called the Ritz pairs, to eigenvalues and eigenvectors of the original matrix
.
If the subspace with the orthonormal basis given by the columns of the matrix
contains
vectors that are close to eigenvectors of the matrix
, the Rayleigh–Ritz method above finds
Ritz vectors that well approximate these eigenvectors. The easily computable quantity
determines the accuracy of such an approximation for every Ritz pair.
In the easiest case
, the
matrix
turns into a unit column-vector
, the
matrix
is a scalar that is equal to the Rayleigh quotient
, the only
solution to the eigenvalue problem is
and
, and the only Ritz vector is
itself. Thus, the Rayleigh–Ritz method turns into computing of the Rayleigh quotient if
.
Another useful connection to the Rayleigh quotient is that
for every Ritz pair
, allowing to derive some properties of Ritz values
from the corresponding theory for the Rayleigh quotient. For example, if
is a Hermitian matrix, its Rayleigh quotient (and thus its every Ritz value) is real and takes values within the closed interval of the smallest and largest eigenvalues of
.
Example
The matrix
has eigenvalues
and the corresponding eigenvectors
Let us take
then
with eigenvalues
and the corresponding eigenvectors
so that the Ritz values are
and the Ritz vectors are
We observe that each one of the Ritz vectors is exactly one of the eigenvectors of
for the given
as well as the Ritz values give exactly two of the three eigenvalues of
. A mathematical explanation for the exact approximation is based on the fact that the column space of the matrix
happens to be exactly the same as the subspace spanned by the two eigenvectors
and
in this example.
Applications and examples
In quantum physics
In quantum physics, where the spectrum of the Hamiltonian is the set of discrete energy levels allowed by a quantum mechanical system, the Rayleigh–Ritz method is used to approximate the energy states and wavefunctions of a complicated atomic or nuclear system.[8] In fact, for any system more complicated than a single hydrogen atom, there is no known exact solution for the spectrum of the Hamiltonian.[7]
In this case, a trial wave function,
, is tested on the system. This trial function is selected to meet boundary conditions (and any other physical constraints). The exact function is not known; the trial function contains one or more adjustable parameters, which are varied to find a lowest energy configuration.
It can be shown that the ground state energy,
, satisfies an inequality:

That is, the ground-state energy is less than this value.
The trial wave-function will always give an expectation value larger than or equal to the ground-energy.
If the trial wave function is known to be orthogonal to the ground state, then it will provide a boundary for the energy of some excited state.
The Ritz ansatz function is a linear combination of N known basis functions
, parametrized by unknown coefficients:

With a known Hamiltonian, we can write its expected value as

The basis functions are usually not orthogonal, so that the overlap matrix S has nonzero nondiagonal elements. Either
or
(the conjugation of the first) can be used to minimize the expectation value. For instance, by making the partial derivatives of
over
zero, the following equality is obtained for every k = 1, 2, ..., N:
which leads to a set of N secular equations:

In the above equations, energy
and the coefficients
are unknown. With respect to c, this is a homogeneous set of linear equations, which has a solution when the determinant of the coefficients to these unknowns is zero:
which in turn is true only for N values of
. Furthermore, since the Hamiltonian is a hermitian operator, the H matrix is also hermitian and the values of
will be real. The lowest value among
(i=1,2,..,N),
, will be the best approximation to the ground state for the basis functions used. The remaining N-1 energies are estimates of excited state energies. An approximation for the wave function of state i can be obtained by finding the coefficients
from the corresponding secular equation.
In mechanical engineering
The Rayleigh–Ritz method is often used in mechanical engineering for finding the approximate real resonant frequencies of multi degree of freedom systems, such as spring mass systems or flywheels on a shaft with varying cross section. It is an extension of Rayleigh's method. It can also be used for finding buckling loads and post-buckling behaviour for columns.
Consider the case whereby we want to find the resonant frequency of oscillation of a system. First, write the oscillation in the form,
with an unknown mode shape
. Next, find the total energy of the system, consisting of a kinetic energy term and a potential energy term. The kinetic energy term involves the square of the time derivative of
and thus gains a factor of
. Thus, we can calculate the total energy of the system and express it in the following form:
![{\displaystyle E=T+V\equiv A[Y(x)]\omega ^{2}\sin ^{2}\omega t+B[Y(x)]\cos ^{2}\omega t}](https://wikimedia.org/api/rest_v1/media/math/render/svg/da15fb7a33f10bf601d807bd457156117b7970f5)
By conservation of energy, the average kinetic energy must be equal to the average potential energy. Thus,
which is also known as the Rayleigh quotient. Thus, if we knew the mode shape
, we would be able to calculate
and
, and in turn get the eigenfrequency. However, we do not yet know the mode shape. In order to find this, we can approximate
as a combination of a few approximating functions
where
are constants to be determined. In general, if we choose a random set of
, it will describe a superposition of the actual eigenmodes of the system. However, if we seek
such that the eigenfrequency
is minimised, then the mode described by this set of
will be close to the lowest possible actual eigenmode of the system. Thus, this finds the lowest eigenfrequency. If we find eigenmodes orthogonal to this approximated lowest eigenmode, we can approximately find the next few eigenfrequencies as well.
In general, we can express
and
as a collection of terms quadratic in the coefficients
:
where
and
are the stiffness matrix and mass matrix of a discrete system respectively.
The minimization of
becomes:

Solving this,

For a non-trivial solution of c, we require determinant of the matrix coefficient of c to be zero.

This gives a solution for the first N eigenfrequencies and eigenmodes of the system, with N being the number of approximating functions.
Simple case of double spring-mass system
The following discussion uses the simplest case, where the system has two lumped springs and two lumped masses, and only two mode shapes are assumed. Hence M = [m1, m2] and K = [k1, k2].
A mode shape is assumed for the system, with two terms, one of which is weighted by a factor B, e.g. Y = [1, 1] + B[1, −1].
Simple harmonic motion theory says that the velocity at the time when deflection is zero, is the angular frequency
times the deflection (y) at time of maximum deflection. In this example the kinetic energy (KE) for each mass is
etc., and the potential energy (PE) for each spring is
etc.
We also know that without damping, the maximal KE equals the maximal PE. Thus,

The overall amplitude of the mode shape cancels out from each side, always. That is, the actual size of the assumed deflection does not matter, just the mode shape.
Mathematical manipulations then obtain an expression for
, in terms of B, which can be differentiated with respect to B, to find the minimum, i.e. when
. This gives the value of B for which
is lowest. This is an upper bound solution for
if
is hoped to be the predicted fundamental frequency of the system because the mode shape is assumed, but we have found the lowest value of that upper bound, given our assumptions, because B is used to find the optimal 'mix' of the two assumed mode shape functions.
There are many tricks with this method, the most important is to try and choose realistic assumed mode shapes. For example, in the case of beam deflection problems it is wise to use a deformed shape that is analytically similar to the expected solution. A quartic may fit most of the easy problems of simply linked beams even if the order of the deformed solution may be lower. The springs and masses do not have to be discrete, they can be continuous (or a mixture), and this method can be easily used in a spreadsheet to find the natural frequencies of quite complex distributed systems, if you can describe the distributed KE and PE terms easily, or else break the continuous elements up into discrete parts.
This method could be used iteratively, adding additional mode shapes to the previous best solution, or you can build up a long expression with many Bs and many mode shapes, and then differentiate them partially.
In dynamical systems
The Koopman operator allows a finite-dimensional nonlinear system to be encoded as an infinite-dimensional linear system. In general, both of these problems are difficult to solve, but for the latter we can use the Ritz-Galerkin method to approximate a solution.[14]