When solving the linear inviscid shallow water equations with variable depth in one dimension using
finite differences, a tridiagonal system of equations must be solved. Here we present an approach,
which is more efficient than the commonly used numerical method, to solve this tridiagonal system of
equations using a recursion formula. We illustrate this approach with an example in which we solve
for a rectangular channel to find the resonance modes. Our numerical solution agrees very well with
the analytical solution. This new method is easy to use and understand by undergraduate students, so
it can be implemented in undergraduate courses such as Numerical Methods, Lineal Algebra or
Differential Equations.