# Problem with satisfying Boundary conditions for 1D heat PDE

I have the following pde and boundary conditions I am trying to solve by separation of variables. I am doing something wrong with my formulation because my boundaries are incorrect when I plot my solution.

The Problem

$$u$$ is a function of space ($$x$$) and time ($$t$$).

$$\frac{\partial u}{\partial t} = k \frac{\partial^2 u}{\partial x^2}$$ $$s.t.$$ $$u(0,t) = f(t)$$ $$\frac{\partial}{\partial x}u(L,t) = 0$$ $$u(x,0) = C = constant$$

My Attempt

Using separation of variables, I arrive at:

$$u(x,t) = Ae^{-\lambda Kt}\cdot(c_1\cos(\sqrt{\lambda}x)+c_2\sin(\sqrt{\lambda}x))$$

Now satisfying the first boundary condition: $$u(0,t) = Ae^{-\lambda Kt}\cdot(c_1\cos(0)+c_2\sin(0))= Ae^{-\lambda Kt}\cdot c_1 = f(t)$$

$$c_1 = \frac{f(t)}{Ae^{-\lambda Kt}}$$

Now the second BC:

$$\frac{\partial}{\partial x}u(L,t) = Ae^{-\lambda Kt}\cdot \sqrt{\lambda}(-c_1\sin(\sqrt{\lambda}L)+c_2\cos(\sqrt{\lambda}L)) = 0$$

This is satisfied only when $$-c_1\sin(\sqrt{\lambda}L)+c_2\cos(\sqrt{\lambda}L) = 0$$

$$c_2 = \frac{f(t)}{Ae^{-\lambda Kt}}\tan(\sqrt{\lambda}L)$$

Final boundary condition:

$$u(x,0) = c_1\cos(\sqrt{\lambda}x)+c_2\sin(\sqrt{\lambda}x) = \frac{f(t)}{Ae^{-\lambda Kt}}\cos(\sqrt{\lambda}x)+\frac{f(t)}{Ae^{-\lambda Kt}}\tan(\sqrt{\lambda}L)\sin(\sqrt{\lambda}x)= C$$

$$\frac{f(t)}{Ae^{-\lambda Kt}}(\cos(\sqrt{\lambda}x)+\tan(\sqrt{\lambda}L)\sin(\sqrt{\lambda}x)) = C$$ $$A = \frac{f(t)}{Ce^{-\lambda Kt}}(\cos(\sqrt{\lambda}x)+\tan(\sqrt{\lambda}L)\sin(\sqrt{\lambda}x))$$

I am pretty stuck up to here. For one, I do not know what the eigenvalue $$\lambda$$ sould be ($$= \frac{n\pi}{L}$$?) and I do not know how if I did this right. If so, I would start by computing $$A$$ because it appears that $$c_1$$ and $$c_2$$ depend on $$A$$. Thanks in advance for any advice.

I've noticed two mistakes. First one is that you have three constants, $$A$$, $$c_1$$, and $$c_2$$, plus $$\lambda$$, and only three boundary conditions. When you multiply two constants (say $$Ac_1$$) you get a new constant. Let's call this $$C_1$$. Then your general solution is $$u(x,t) = e^{-\lambda Kt}\cdot(C_1\cos(\sqrt{\lambda}x)+C_2\sin(\sqrt{\lambda}x))$$ Now using the three equations for boundary conditions you can get $$C_1$$, $$C_2$$, and $$\lambda$$.
Also, I've noticed that for the final boundary condition you used $$t=0$$, but you still have $$t$$ in your equation. You should not repeat the same mistake after you solved your first issue.
The point is that $$u(x,t) = Ae^{-\lambda Kt}\cdot(c_1cos(\sqrt{\lambda}x)+c_2sin(\sqrt{\lambda}x))$$ is a solution if and only if $$A$$, $$c_1$$ and $$c_2$$ are constant. When you impose that $$u(0,t) = f(t)$$ you find a $$c_1$$ which depends on t and this is not possible. If $$c_1$$ depends on t,$$u(x,t) = Ae^{-\lambda Kt}\cdot(c_1cos(\sqrt{\lambda}x)+c_2sin(\sqrt{\lambda}x))$$ is not a solution of your differential equation. You should look at a solution in the form
$$u(x,t)=c_1(x) e^{t/k} (c_2(t) e^{x \sqrt{k}}+c_3(t) e^{-x \sqrt{k}})$$.