I want to solve the given problem:
\begin{equation} u_t-u_{xx}=2 \ \ \ \ \ 0<x<1, t>0 \\ u(0,t)=0, \ \ u_x(1,t)=1, \ \ \ t>0\\ u(x,0)=-x^2, \ \ \ \ 0<x<1 \end{equation}
but I am not sure I have done it correctly. This is what I did:
Step 1. Homogenize, by solving the stationary problem $u_t=0$:
\begin{equation} -u_{xx}=2 \rightarrow u(x)-x^2+Cx+D \\ I.C. give \rightarrow u(x)=-x^2+3x \end{equation}
The homogenized PDE is now:
\begin{equation} u_t-u_{xx}=0 \ \ \ \ \ 0<x<1, t>0 \\ u(0,t)=0, \ \ u_x(1,t)=1, \ \ \ t>0\\ u(x,0)=-x^2+x^2-3x \rightarrow u(x,0)=-3x, \ \ \ \ 0<x<1 \end{equation}
Step 2. Solve the homogenous PDE.
Since we have mixed conditions, we need to look for a linear combination of $u(x)=A\sin\lambda x+B\cos\lambda x$ which satisfies the I.C.
We get:
\begin{equation} u(x)=A\sin\lambda x+ B\cos\lambda x \rightarrow \ \ IC: u(0)=0 \rightarrow u(x)=A\sin\lambda x\\ u(x)=A\sin\lambda x, \rightarrow IC2: u'(1)=1,\ \ \ u'(x)= \lambda A\cos\lambda x \rightarrow 1=\lambda A\cos\lambda \rightarrow A=\frac{1}{\lambda\cos\lambda}\\ u(x)=\frac{1}{\lambda\cos\lambda}\sin\lambda x \end{equation}
So now we have a first candidate of the function
\begin{equation} u(x,t)=\frac{\sin\lambda x}{\lambda\cos\lambda}u(t) \end{equation}
We find out u(t) by plugging this in the PDE, where each of the following is:
\begin{equation} u(x,t)=\frac{\sin\lambda x}{\lambda\cos\lambda}u(t)\\ u_{xx}(x,t)=-\frac{\lambda^2\sin\lambda x}{\lambda\cos\lambda}u(t)\\ u_t(x,t)=\frac{\sin\lambda x}{\lambda\cos\lambda}u_t \end{equation}
By inserting eacah part in the homogenized PDE we get:
\begin{equation} \frac{\sin\lambda x}{\lambda\cos\lambda}u_t+\frac{\lambda^2\sin\lambda x}{\lambda\cos\lambda}u(t)=0\\ u(t)=C_ne^{-\lambda^2t} \end{equation}
Step 3. Find the coefficients
So since we now have the full form of $u(x,t)$, we can use the third IC for the homogenized problem, $u(x,0)=-3x$ and use the Fourier series method to find the coefficient:
\begin{equation} u(x,0)=-3x=\sum_{n=1}^\infty\frac{C_n}{\lambda\cos\lambda}\sin\lambda xe^0 \end{equation}
This coefficient we find by using the Fourier series form for $\beta_n=\frac{2}{L}\int_0^Lu(x,0)\sin\lambda xdx$. Here we have both $u(x,0)=-3x$ and $L=1$ so we obtain that $\frac{C_n}{\lambda\cos\lambda}=\beta_n$: This is the famous "Fourier trick" used to find the coefficients of the heat, Laplace and wave equations. So this "trick" gives:
\begin{equation} \frac{C_n}{\lambda\cos\lambda}=2\int_0^1(-3x)\sin\lambda xdx \end{equation}
Solving the L.H.S we get $-\frac{\cos\lambda}{\lambda}$, so the equation becomes
\begin{equation} \frac{C_n}{\lambda\cos\lambda}=-\frac{\cos\lambda}{\lambda} \end{equation}
Hence,
$C_n=-\cos^2\lambda$
Since the system was inhomogenous, we need to add the function $u(x,0)=-3x$
This gives the final form of $u(x,t)$
\begin{equation} u(x,t)=-3x+\sum_{n=1}^\infty\frac{\cos\lambda}{\lambda}\sin\lambda x e^{-\lambda^2 t} \end{equation}
But I am not sure about the last step, to add the function $u(x,0)=-3x$. Is it right to do, or not?
Thanks
The right answer is to add
$u(x)=-x^2+3x$ to the solution of the homogeneous problem.
That is
\begin{equation} u(x,t)=\bigg[\sum_{n=1}^\infty\frac{\cos n\pi} {n\pi}\sin n\pi x e^{-(n\pi)^2 t}\bigg]-x^2+3x) \end{equation}
which gives
\begin{equation} u(x,t)=-x^2+3x+\bigg[\sum_{n=1}^\infty\frac{\cos n\pi}{n\pi}\sin n\pi x e^{-(n\pi)^2 t}\bigg] \end{equation}
This satisfies the non-homogeneous solution, giving, when inserted in the PDE with $n=1$
\begin{equation} \frac{d}{dt}\bigg[-x^2+3x+e^{-(n\pi)^2 t} \cos n\pi \frac{\sin n\pi x}{n\pi}\bigg]-\frac{d^2}{dx^2}\bigg[-x^2+3x+e^{-(n\pi)^2t} \cos n\pi\frac{\sin n\pi x}{n\pi}\bigg]=2\\ -e^{-(n\pi)^2 t} n\pi \cos n\pi \sin n\pi x - \bigg[-e^{-(n\pi)^2 t } n\pi \cos n\pi \sin n\pi x-2\bigg]=2\\ 2=2 \end{equation}