# Galerkin method for heat equation

I'm working out the Galerkin method for the heat equation $$\frac{\partial u}{\partial t} - \frac{\partial^2 u}{\partial x^2} = 0$$ subject to $$u(0,t)=0,u_x(1,t)=v(t)$$.

I want to use a Fourier basis to represent the solution, i.e. $$u(x,t) = \sum_{j=1}^n c_j(t) \phi_j(x)$$ where $$\phi_j(x) = \sin j\pi x$$.

If I try to formulate the weak form of this PDE using the basis functions above, the effect of the boundary condition $$v(t)$$ goes away, which is strange.

This is because if I compute $$\int_0^1 \frac{\partial^2 u}{\partial x^2} \phi \,dx$$ using integration by parts, I get $$u_x(1,t)\phi(1) - u_x(0,t)\phi(0) - \int_0^1 \frac{\partial u}{\partial x} \frac{\partial \phi}{\partial x}\,dx$$.

However, $$\phi(1)=0$$! Did I commit a mistake? What would be the proper way of doing this?

• I am not an expert of Galerkin method, but aren't you already enforcing $u(1,t) = 0$ because of your choice of trial space? I don't think you can enforce $u(0,t) = 0$, $u(1,t) = 0$ and $u_x(1,t) = v(t)$ at the same time but I might be wrong. May 1 '20 at 21:01
• @QuantumApple has this right: If you write your solution as $u(x,t)=\sum_j c_j(t) \phi_j(x)$ where all of the $\phi_j$ are zero at $x=1$, then necessarily $u(1,t)=0$. You simply can't represent a nonzero $v(t)$ by adding up zeros. If you want a $u$ that's nonzero at $x=1$, then you will also have throw a few functions into your basis that are nonzero there. May 1 '20 at 21:55
• Thanks for the replies. But my boundary condition at $x=1$ is not dirichlet, it's neumann. It's $u_x(1,t) = v(t)$. Just because $u(1,t)=0$ doesn't mean $u_x(1,t) = 0$, right? May 1 '20 at 22:25
• @QuantumApple. Well, $sin \pi x$ is a function that is 0 at $x=1$ but has a non-zero derivative there/ May 1 '20 at 22:41
• @user1237300 This is true, but I think that you cannot enforce 3 BC at the same time in 1D. This is simply not a mathematically well-defined problem. Another way to phrase it is that the real solution $u(x,t)$ is probably $\neq 0$ at $x = 1$. But your choice of trial functions will make it so that your solution will be $0$ there. So even if you tried somehow to enforce $u_x(1,t) = v(t)$ manually, my guess is that you would not converge to the right solution anyway (because it is a priori $\neq 0$ at $x=1$). May 1 '20 at 23:03

• Transform your problem from one with inhomogeneous BC to homogeneous BC. This is done by substracting any function $$B(x,t)$$ with the right inhomogeneous BC from $$u(x,t)$$ to create a new function $$h(x,t) = u(x,t) - B(x,t)$$. For instance, take $$B(x,t) = \frac{2v(t)\sin(\pi x/2)}{\pi}$$. Your problem becomes $$\frac{\partial h}{\partial t} - \frac{\partial^2 h}{\partial x^2} + \frac{\partial B}{\partial t} - \frac{\partial^2 B}{\partial x^2} = 0$$, with BC $$h(0,t) = 0$$ and $$h_x(1,t) = 0$$.
• Choose the right basis functions (that satisfy the correct BC). Here for instance, you can take $$\phi_j(x) = \sin((2j+1)\pi x/2)$$. Write $$h_j(x,t_n) = \sum_j c_j(t_n) \phi_j(x)$$.
• If you take your space test to be equal to your trial space, enforce the following condition $$\int_0^1 \left( \frac{\partial h}{\partial t} - \frac{\partial^2 h}{\partial x^2} + \frac{\partial B}{\partial t} - \frac{\partial^2 B}{\partial x^2} \right) \phi_j(x,t) = 0, \quad \forall j, t_n$$
As for wether or not the $$\phi_j$$'s form an orthonormal basis of $$L^2[0,1]$$ (for the scalar product $$\left\langle f, g \right\rangle = \int_0^1 f(x) g(x) dx$$) when $$j$$ spans $$\mathbb{N}$$, again I am not an expert but I believe they do, since they are the solutions to the following Sturm-Liouville problem:
$$\frac{d^2 \phi}{dx^2} = -E \phi; \quad \phi(0) = 0; \quad \phi'(1) = 0.$$