# Solving 1D Poisson equation using Green's function

I have been trying to solve the following equation via Green's functions: $$\frac{\mathrm{d}^2u}{\mathrm{d}x} = \begin{cases} 1, x < \frac{1}{2} \\ 0, x > \frac{1}{2} \end{cases}$$ with boundary conditions $$u(0) = u(1) = 0$$. The Green's function for this case is given by $$G(x, y) = \begin{cases} x(y-1), x \leq y \\ y(x-1), x \geq y \end{cases}$$

I understand that the solution is given by $$u(x) = \int_0^1 G(x, y)f(y)\,\mathrm{d}y$$ and have tried to subdivide the integral to be able to integrate it: \begin{align} u(x) &= \int_0^x G(x, y)f(y)\,\mathrm{d}y + \int_x^{1/2} G(x, y)f(y)\,\mathrm{d}y + \int_{1/2}^1 G(x, y)f(y) \,\mathrm{d}y \\ &= \int_0^x x(y-1)\,\mathrm{d}y + \int_x^{1/2} y(x-1)\,\mathrm{d}y + \int_{1/2}^1 0 \,\mathrm{d}y \\ &= -\frac{x^2}{2}+\frac{x}{8} - \frac{1}{8} \end{align}

which, while close, is still off by a factor of $$-1$$. Is there something wrong with the method? I am not certain about how to subdivide the interval. Any help would be appreciated. Thank you!

You have substituted the wrong branch of the Green's function on the integral. Note that when you are integrating $$y$$ from $$0$$ to $$x$$, $$y\leq x$$ (so $$x\geq y)$$, so you should use $$y(x-1)$$ when integrating. So: $$u(x)=\int_0^xy(x-1)dy+\int_x^\frac{1}{2}x(y-1)dy=\frac{x^2}{2}-\frac{3x}{8}$$ Note that the second derivative of this is 1 and u satisfies only the first boundary condition. This happens because you should consider the cases $$y>\frac{1}{2}$$ and $$y<\frac{1}{2}$$ separately because we don't know the exact value of y (don't know how rigorous this claim is).

The $$u(x)$$ you have calculated works when $$y<1/2$$, but if we consider the other case: $$u(x)=\int_0^\frac{1}{2}y(x-1)dy+\int_\frac{1}{2}^x0dy+\int_x^10dy=\frac{1}{8}(1-x)$$ This satisfies the conditions that the other $$u$$ couldn't. So: $$u(x)=\begin{cases} \frac{x^2}{2}-\frac{3x}{8} & x<\frac{1}{2} \\ \frac{1}{8}(1-x) & x>\frac{1}{2} \end{cases}$$ Hope this helped.