# The Rayleigh-Ritz method

### Intro

This method starts straight from the weak form of a differential equation. It follows by taking the same functional space for the solution functions and the weight functions. This makes it similar to the straight Galerkin method – indeed it is often equivalent, as we will discuss in a future article.

### The variational point of view

In a linear problem, the RR method is quite simple. In this case, our weak problem can be written as

$B(u,w)=l(w)$,

where $B$ is a bilinear operator, and $l$ is a linear one.

In our example our final expression in the weak form was:

ex. $\int\left[ a\frac{du}{dx}\frac{d w }{dx}-wf\right]-w(L)Q_0=0$

ex. $B(u,w)=\int\left[a\frac{du}{dx}\frac{dw}{dx}-wf\right]$  and  $l(w)=wf+w(L)Q_0.$

It is quite interesting physically that $w$ can be considered a variation from the true solution $u^*$, so we may write $w=\delta u$, and solve

$B(u,\delta u)-l(\delta u)=0$.

For these (bi)linear operators, this can be written, with a little functional analysis, as

$\delta \left( \frac{1}{2} B(u,u)-l(u)\right)=0,$

IF $B$ is symmetric, on top of bilinear.

So, indeed, we are solving a variational problem in the spirit of classical mechanics. One would call the quantity $B(u,u)/2-l(u)$ the potential energy, or the Lagrangian perhaps. Sometimes, such a physical name is not appropriate, but clearly the quantity is still useful as the thing that is being minimized (or, rather, extremized).

### The Rayleigh-Ritz method

Since in this method we take the same functional space for the solution functions and the weight functions, we end up with N equations:

$B(\phi_i,\sum c_j\phi_j + \phi_0 )-l(\phi_i)=0$

Given the (bi)linearity, we can arrive at a standard linear algebra problem:

$\sum_j B_{ij}c_j=F_i,$

where the coefficient matrix has components

$B_{ij}=B(\phi_i,\phi_j)$

and the vector is

$F_i=l(\phi_i)-B(\phi_i,\phi_0)$.

Notice $B$ is bilinear, but doesn’t have to be symmetric. Hence the matrix does not have to be symmetric either.

### Boundary conditions

We recall that NBCs are already included in a proper weak formulation. Hence, our solution function $u_N=\sum c_j\phi_j+\phi_0$ must only comply with the EBCs. This is why we keep dragging the $\phi_0$: this function usually satisfies the non-homogeneous BCs that may be, while the rest satisfies homogeneous BCs. If the BCs are homogeneous to start with, $\phi_0$ is simply zero, and we don’t even have to write it down (as is done as an easy case in some books). Don’t forget that the $\phi_j$ are also used for $w$ in the RR method, which is fine: the weight should indeed comply with homogeneous BC.

### Examples

Let us consider this case:

$A(u)=-\frac{d}{dx}(au')-cu\qquad f(x)=-x^2.$

The weak form from which we begin is:

$\int_0^L (au'w'-cuw+x^2w)dx=0$ + boundary terms

We don’t write down the boundary terms since we are going to consider two sets. Also, we will set $a=c=L=1$, so

$\int_0^1 (u'w'-uw+x^2w)dx=0$ + boundary terms

#### Set 1

Homogeneous Dirichlet BCs: $u(0)=u(1)=0$. These are clearly two EBCs. They therefore impose $w(0)=w(1)=0$. The weak form is, in this case simply

$\int_0^1 (u'w'-uw+x^2w)dx=0$

Also, we may set $\phi_0=0$ since they are homogeneous. Hence our linear algebra problem is

$\sum_j B_{ij}c_j=F_i,$

with

$B_{ij}=\int_0^1(\phi'_i\phi'_j-\phi_i\phi_j)dx\qquad F_i=-\int_0^1x^2\phi_idx.$

The set of functions must comply with the EBCs. For example, we may try the following:

$\phi_i=x^i (x-1) .$

The results are trivial but really tedious to copy (see Reddy, p. 45).

A fair convergence is obtained with only $N=3$. This kind of polynomials is, nevertheless, known to behave badly as N increases, since they are “not too orthogonal”. By the way, the exact solution to this problem is

$u(x)=\frac{\sin(x)+2\sin(1-x)}{\sin(1)}+x^2-2$

#### Set 2

Homogeneous Dirichlet BC on 0 only: $u(0)=0$, plus Neumann on L: $u'(1)=1$.

There only one EBC, the first one, which imposes $w(0)=0$. The weak form is, in this case

$\int_0^1 (u'w'-uw+x^2w)dx=w(1)$

(The Neumann BC is not a EBC since it is w which appears in the weak form, not w‘.)

We may set $\phi_0=0$ again since the EBC is homogeneous. Hence our linear algebra problem is

$\sum_j B_{ij}c_j=F_i,$

with the same $B_{ij}$ as before, but now

$F_i=-\int_0^1x^2\phi_idx+\phi_i(1).$

The set of functions must comply with the EBC. For example, we may try:

$\phi_i=x^i$

so that $\phi_i(1)=1$.

Now the coefficients are easier:

$B_{ij}=\frac{ij}{i+j-1}-\frac{1}{i+j+1}\qquad F_i=1-\frac{1}{i+3}.$

Again, fair convergence is obtained with only $N=3$, but these simple polynomials are known to be treacherous. By the way, the exact solution to this problem is

$u(x)=\frac{-\sin(x)+2\cos(1-x)}{\cos(1)}+x^2-2.$