# solving the wave equation using separation of variables

How can I solve the following Wave equation using separation of variables? I am interested in a general way of solving all problems of this type, not some sort of tricks that for some reason happen to work on this problem only (not sure if there are any).

$\frac{\partial^2 u}{\partial t^2}=\frac{\partial^2 u}{\partial x^2}$

$0<x<L$, $t>0$

With the initial and boundary conditions:

$u(x,0)=f(x)=5cos(\frac{10x\pi}{L})$

$u_t(x,0)=0$

$u_x(0,t)=u_x(L,t)$

What I have done:

Assume: $u(x,t)=X(x)T(t)$

=> $\frac{X''}{X} = \frac{T''}{T}=-\lambda$

Now I can solve $X''+\lambda X=0$ I get the conditions $X'(0)=X'(L)=0$

case1: $\lambda>0$

Characteristic equation $r^2 + \lambda =0 <=> r_1=\sqrt\lambda i, r_2=-\sqrt\lambda i$

General solution: $X(x)=c_1 cos(\sqrt\lambda x) + c_2 sin(\sqrt\lambda x)$

$X'(x)=-c_1 \sqrt\lambda sin(\sqrt\lambda x) + c_2 \sqrt\lambda cos(\sqrt\lambda x)$

Now from the conditions $X'(0)=X'(L)=0$ I get

$0=0 + c_2 \sqrt\lambda *1 => c_2=0$ and

$0=-c_1 \sqrt\lambda sin(L\sqrt\lambda)$

Therefore, the eigenvalues are the values of $lambda$ for which $L\sqrt\lambda=n*\pi$ (has to do with when $sin(L\sqrt\lambda)=0$

The eigenvalue is $\lambda_n = \frac{n^2 \pi ^2}{L^2}$ for $n=1,2,...$ and corresponding eigenfunction is $cos(\frac{xn\pi}{L})$

case2: $\lambda=0$

The eigenfunction is 1.

case3: $\lambda <0$

no eigenvalues.

Note: If I let $\lambda_n=\frac{n^2 \pi^2}{L^2}$ for $n=0,1,2,...$ Then case1 and case2 are both accounted for.

$T''+\lambda_n T=0 => T_n(t)=k_1 cos(\frac{tn\pi}{L})+k_2 sin(\frac{tn\pi}{L})$

$T_n'(t)=-k_1 \frac{n\pi}{L}sin(\frac{tn\pi}{L}) + k_2 \frac{n\pi}{L} cos(\frac{tn\pi}{L})$

using the initial condition $T'(t)=0$ I get $k_2=0$ so the fundamental solutions are $u_n(x,t)=X_n(x)T_n(t)$ (the two eigenfunctions multiplied together).

The solution is:

$u(x,t)=\sum_{n=0}^\infty a_n cos(\frac{tn\pi}{L})cos(\frac{xn\pi}{L})$

Now what I am wondering, first of all is what I have done so far fine, I suppose to have more of a complete answer I should have probably explained a bit about lambda <0. Secondly what is the logic in how to find $a_n$ ? How is finding $a_n$ generally done on these type of problems? I understand that I have to use the last initialvalue condition (that I haven't used yet), but how?

The solution you got looks okay.

In general, to get the coefficient $a_n$, plug in the initial condition $u(x,0) = f(x)$,then multiply by $\cos(x n' \pi/L)$.

$$\sum_{n=0}^\infty a_n \cos( \frac{n \pi x}{L}) \cos(\frac{n' \pi x}{L}) = f(x)\cos(\frac{n' \pi x}{L})$$

Now integrate from $0$ to $L$

$$\sum_{n=0}^\infty a_n \int_0^L \cos( \frac{n \pi x}{L}) \cos(\frac{n' \pi x}{L})dx = \int_0^L f(x)\cos(\frac{n' \pi x}{L})dx$$

If $n \ne n'$ the integral is $0$. In the case that $n = n'$, we get

$$a_n \int_0^L \cos(\frac{n \pi x}{L})^2 dx = \int_0^L f(x) \cos(\frac{n \pi x}{L}) dx$$

So if you divide by the integral on the left (because it is non-zero) we get an equation for $a_n$. (Note that the expression is of a different form if $n = 0$)

However, this is not necessary here, because of the form of $f(x)$

$$\sum_{n=0}^\infty a_n \cos(\frac{n \pi x}{L}) = 5 \cos(\frac{10 \pi x}{L})$$

This implies that $a_{10} = 5$ and $a_n = 0$ for $n \ne 10$

• @stat333: I updated to show the general approach – infinitylord Jul 15 '17 at 4:37
• @stat333 Yes, you would just integrate from $-L$ to $L$ instead, because that is the region that $f$ is defined. Though it's note worthy that if $f$ is an even function, this reduces back to the $0$ to $L$, and if $f$ is odd, the integral is $0$, so there is no solution with cosines. I don't know what you mean by the period of the problem. $\cos(n \pi x/L)$ is $2 L/n$, so each term has a different period (that is the nature of Fourier series). And yes, that is how you treat the case that it depends on $\sin$ – infinitylord Jul 15 '17 at 5:56
• if I have $u(x,t)=\sum sinnx(\alpha_n cos(2nt) + \beta_n sin(2nt)$ and the initial value conditions: $u(x,0)=sin(3x)-4sin(10x)$ and $\frac{\partial u}{\partial t}(x,0)=2sin(4x)+sin(6x)$ and $0<x<\pi$ how would it be then? for instance solving for $\alpha_n$ using the first condition, how would that work when it comes to writing up the formula for $\alpha_n$ ? I am able to see by inspection that $\alpha_3 =1$ and $\alpha_{10} = -4$ by comparing terms. – stat333 Jul 16 '17 at 3:56
• @stat333: You would write it as a piecewise function. Say $\alpha_3 = 1$, $\alpha_{10} = -4$, and $\alpha_n = 0$ if $n \ne 3, 10$. Writing up the general function would be the same. Plug in the initial conditions, multiply by the appropriate trig function, integrate to isolate the coefficient – infinitylord Jul 17 '17 at 1:56