I am trying to find a closed form for the following integral:

$$\int_0^{k\pi}\left(y(x)+y''(x)\right)\sin xdx$$

And I know that $y(k\pi)=a$ and $k$ is a positive integer.


Well, let's suppose that $\text{y}''$ is continuous and $\text{y}\left(\text{n}\pi\right)=\alpha$, $\text{n}\in\mathbb{N}$ and:

$$\mathcal{I}_\text{n}:=\int_0^{\text{n}\pi}\left(\text{y}\left(x\right)+\text{y}''\left(x\right)\right)\sin\left(x\right)\space\text{d}x\tag1$$

Find a closed form for $(1)$.

First, we can split the integral:

$$\mathcal{I}_\text{n}=\int_0^{\text{n}\pi}\text{y}\left(x\right)\sin\left(x\right)\space\text{d}x+\underbrace{\int_0^{\text{n}\pi}\text{y}''\left(x\right)\sin\left(x\right)\space\text{d}x}_{:=\space\mathcal{E}_\text{n}}\tag2$$

We can use IBP on the second integral $\mathcal{E}_\text{n}$:

\begin{equation} \begin{split} \mathcal{E}_\text{n}&=\left[\text{y}'\left(x\right)\sin\left(x\right)\right]_0^{\text{n}\pi}-\int_0^{\text{n}\pi}\text{y}'\left(x\right)\cos\left(x\right)\space\text{d}x\\ \\ &=\left(\text{y}'\left(\text{n}\pi\right)\sin\left(\text{n}\pi\right)-\text{y}'\left(0\right)\sin\left(0\right)\right)-\int_0^{\text{n}\pi}\text{y}'\left(x\right)\cos\left(x\right)\space\text{d}x\\ \\ &=\left(\text{y}'\left(\text{n}\pi\right)\cdot0-\text{y}'\left(0\right)\cdot0\right)-\int_0^{\text{n}\pi}\text{y}'\left(x\right)\cos\left(x\right)\space\text{d}x\\ \\ &=\left(0-0\right)-\int_0^{\text{n}\pi}\text{y}'\left(x\right)\cos\left(x\right)\space\text{d}x\\ \\ &=-\int_0^{\text{n}\pi}\text{y}'\left(x\right)\cos\left(x\right)\space\text{d}x \end{split}\tag3 \end{equation}

We can use IBP again on $(3)$, this gives:

\begin{equation} \begin{split} \mathcal{E}_\text{n}&=-\left(\left[\text{y}\left(x\right)\cos\left(x\right)\right]_0^{\text{n}\pi}-\int_0^{\text{n}\pi}\text{y}\left(x\right)\left(-\sin\left(x\right)\right)\space\text{d}x\right)\\ \\ &=\left[\text{y}\left(x\right)\cos\left(x\right)\right]_{\text{n}\pi}^0-\int_0^{\text{n}\pi}\text{y}\left(x\right)\sin\left(x\right)\space\text{d}x\\ \\ &=\left(\text{y}\left(0\right)\cos\left(0\right)-\text{y}\left(\text{n}\pi\right)\cos\left(\text{n}\pi\right)\right)-\int_0^{\text{n}\pi}\text{y}\left(x\right)\sin\left(x\right)\space\text{d}x\\ \\ &=\left(\text{y}\left(0\right)\cdot1-\text{y}\left(\text{n}\pi\right)\cos\left(\text{n}\pi\right)\right)-\int_0^{\text{n}\pi}\text{y}\left(x\right)\sin\left(x\right)\space\text{d}x\\ \\ &=\begin{cases} \left(\text{y}\left(0\right)\cdot1-\text{y}\left(\text{n}\pi\right)\cdot1\right)-\int_0^{\text{n}\pi}\text{y}\left(x\right)\sin\left(x\right)\space\text{d}x&\space\text{when}\space\text{n}\space\text{is even}\\ \\ \left(\text{y}\left(0\right)\cdot1-\text{y}\left(\text{n}\pi\right)\cdot\left(-1\right)\right)-\int_0^{\text{n}\pi}\text{y}\left(x\right)\sin\left(x\right)\space\text{d}x&\space\text{when}\space\text{n}\space\text{is odd} \end{cases}\\ \\ &=\begin{cases} \text{y}\left(0\right)-\underbrace{\text{y}\left(\text{n}\pi\right)}_{=\space\alpha}-\int_0^{\text{n}\pi}\text{y}\left(x\right)\sin\left(x\right)\space\text{d}x&\space\text{when}\space\text{n}\space\text{is even}\\ \\ \text{y}\left(0\right)+\underbrace{\text{y}\left(\text{n}\pi\right)}_{=\space\alpha}-\int_0^{\text{n}\pi}\text{y}\left(x\right)\sin\left(x\right)\space\text{d}x&\space\text{when}\space\text{n}\space\text{is odd} \end{cases}\\ \\ &=\begin{cases} \text{y}\left(0\right)-\alpha-\int_0^{\text{n}\pi}\text{y}\left(x\right)\sin\left(x\right)\space\text{d}x&\space\text{when}\space\text{n}\space\text{is even}\\ \\ \text{y}\left(0\right)+\alpha-\int_0^{\text{n}\pi}\text{y}\left(x\right)\sin\left(x\right)\space\text{d}x&\space\text{when}\space\text{n}\space\text{is odd} \end{cases} \end{split}\tag4 \end{equation}

Combining $(2)$ and $(4)$, gives:

\begin{equation} \begin{split} \mathcal{I}_\text{n}&=\int_0^{\text{n}\pi}\text{y}\left(x\right)\sin\left(x\right)\space\text{d}x+\mathcal{E}_\text{n}\\ \\ &=\int_0^{\text{n}\pi}\text{y}\left(x\right)\sin\left(x\right)\space\text{d}x+\begin{cases} \text{y}\left(0\right)-\alpha-\int_0^{\text{n}\pi}\text{y}\left(x\right)\sin\left(x\right)\space\text{d}x&\space\text{when}\space\text{n}\space\text{is even}\\ \\ \text{y}\left(0\right)+\alpha-\int_0^{\text{n}\pi}\text{y}\left(x\right)\sin\left(x\right)\space\text{d}x&\space\text{when}\space\text{n}\space\text{is odd} \end{cases}\\ \\ &=\begin{cases} \text{y}\left(0\right)-\alpha&\space\text{when}\space\text{n}\space\text{is even}\\ \\ \text{y}\left(0\right)+\alpha&\space\text{when}\space\text{n}\space\text{is odd} \end{cases} \end{split}\tag5 \end{equation}

So, we end up with:

$$\mathcal{I}_\text{n}=\begin{cases} \text{y}\left(0\right)-\alpha&\space\text{when}\space\text{n}\space\text{is even}\\ \\ \text{y}\left(0\right)+\alpha&\space\text{when}\space\text{n}\space\text{is odd} \end{cases}\tag6$$