Solve $u_{xx}+u_{yy}=y$ given initial conditions. 
Solve the PDE
$$u_{xx}+u_{yy}=y,\quad 0<x<2, \quad 0 < y < 1, \\ u(x,0)=0, \quad
 u(x,1)=0, \\ u(0,y)=y-y^3, \quad u(2,y)=0.$$

Attempt: So we have that the complete solution to this inhomogeneous PDE is given by $u(x,y)=u_p+u_h.$ Let's treat $u_p$ first. Since the RHS is independent of $x$ we can set $u_p=f(y),$ thus we obtain the ODE
$$f''(y)-y=0, \quad f(0)=f(1)=0.\tag{1}$$
The solution is given by $f(y)=\frac{y^2}{6}+ax+b$ and using the conditions we have that $u_p=f(y)=\frac{y^2+y}{6}.$ Now for $u_h$ we need to consider the homogeneous case. By separation of variables we set $u_h=X(x)\cdot Y(y)$ and plugging this into our PDE we get
$$X''(x)Y(y)=-X(x)Y''(y)\Leftrightarrow\frac{X''(x)}{X(x)}=-\frac{Y''(y)}{Y(y)}=\lambda.\tag{2}$$
At this point we need to decide whether we should start by computing $X$ or $Y$. Given that the initial conditions for $Y$ are simpler, we start with $Y$. We have that
$$-\frac{Y''(y)}{Y(y)}=\lambda\Leftrightarrow Y''(y)+\lambda Y(y)=0.\tag3$$
This is a second order ODE whose solution basis varies depending on the value of $\lambda$ so we need to split this up in 3 cases as follows:


*

*$\lambda=0:$ Then we have that $Y''(y)=0\implies Y(y)=ay+b$ and based on the initial values we get that $a=b=0$ and thus this is a zero solution which we are not interested in.

*$\lambda<0:$ So $Y''(y)-|\lambda|Y(y)=0$ thus 
$$Y(y)=a\cosh(\sqrt{\lambda}y)+b\sinh(\sqrt{\lambda}y),$$
but here we also get the zero solution if we plug in the initial values since this forces $a=b=0.$

*$\lambda>0:$ Gives $$Y(y)=a\sin(\sqrt{\lambda}y)+b\cos(\sqrt{\lambda}y),$$
and using the initial values we get that $Y(0)=0\ \implies b=0$ and $Y(1)=0 \implies a\sin(\sqrt{\lambda})=0$ and we want $a\neq0$ thus $\lambda=\pi^2k^2, \ k\in\mathbb{N}.$ Thus $Y(y)=a\sin(\pi k y).$
Now we can solve for the partner function $X(x).$ By $(2)$ and since we now also have a $k$-dependence we have that
$$X_k''(x)=\pi^2k^2X_k(x)\implies X_k(x)=a_k\cosh(\pi k x)+b_k\sinh(\pi k x),\tag4$$

Now I wonder, when should I use the other two initial conditions? If I use $u(2,y)=0$ now I get that $a_k=-\frac{b_k\sinh(2 \pi k)}{\cosh(2\pi k)}$ and using $u(0,y)=y-y^3$ gives $a_k=y-y^3.$
What is happening?
 A: The subscripts will get confusing later, so let's rename the variables to $u(x,y) = w(y) + v(x,y)$ where $w$ is the particular solution and $v$ is the homogeneous solution. $w$ needs to satisfy
$$ w''(y) = y, \quad w(0) = w(1) = 0 $$
Solving this gives $w(y) = \frac{1}{6}(y^3-y)$. Subtracting this from $u$ gives
\begin{cases} 
v_{xx} + v_{yy} = 0 \\ 
v(x,0) = v(x,1) = 0 \\ 
v(0,y) = u(0,y) - w(y) = \frac76(y-y^3) \\ 
v(2,y) = u(2,y) - w(y) = \frac16(y-y^3) 
\end{cases}
You got the right solution for $Y_n(y)$, however the rest isn't so simple. By linearity, all solutions of the form $X_n(x)Y_n(y)$ will satisfy the equation, therefore the general solution will be a linear combination of them
$$ u(x,y) = \sum_{n} X_n(x) Y_n(y) = \sum_{n=1}^\infty X_n(x) \sin(n\pi y) $$
Before we go on, let's pick a form for $X_n(x)$ in the calculations. You have several options here
\begin{align} 
X_n(x) &= A_ne^{n\pi x} + B_ne^{-n\pi x} \\
X_n(x) &= A_n\cosh(n\pi x) + B_n\sinh(n\pi x)
\end{align}
Note that $\sinh(n\pi x)$ vanishes on $x=0$, one of the boundaries given. If the other linearly-independent solution vanishes on $x=2$, the final calculations will be a lot easier. Let's try
$$ X_n(x) = A_n\sinh(\pi(2-x)) + B_n\sinh(\pi x) $$
This works since the shifted $\sinh$ function is a linear combination of $\sinh$ and $\cosh$. S0 we have
$$ u(x,y) = \sum_{n=1}^\infty  \big[A_n\sinh(n\pi(2-x)) + B_n\sinh(n\pi x)\big]\sin(n\pi y) $$
The final boundary conditions give
\begin{align}
u(0,y) &= \sum_{n=1}^\infty A_n\sinh(2n\pi)\sin(n\pi y) = \frac76(y-y^3) \\
u(2,y) &= \sum_{n=1}^\infty B_n\sinh(2n\pi)\sin(n\pi y) = \frac16(y-y^3)
\end{align}
Decompose the above boundary functions into their respective Fourier sine series to find expressions for $A_n$ and $B_n$
