Exercise: first-order linear differential equation This is a first-order linear differential equation:
$$y' = -ky + p$$
where $k$ and $p$ are constant. Based on my calculations, the solution is
$$y(x) = y(0) \cdot \exp^{-kx} + \; \dfrac{p}{k}$$
while my teacher's file says
$$y(x) = \dfrac{p}{k} + \left[y(0) - \dfrac{p}{k} \right] \exp^{-kx}$$
Which one is the right one?
Thank you in advance
 A: The general solution is given by $$y(x)=\frac{p}{k}+Ce^{kx}$$ and now you will $$y(0)=\frac{p}{k}+C$$ to compute $$C$$
A: The solution given by your teacher is the right one. Assuming that the intial condition is given by $y(0)=y_0$ we get the following
\begin{align}
y'&=-ky+p\\
y'&=-k\left(y-\frac pk\right)\\
\frac{y'}{y-\frac pk}&=-k\\
\int \frac{\mathrm dy}{y-\frac pk}&=-k\int\mathrm dx\\
\log\left(y-\frac pk\right)&=-kx+c\\
y-\frac pk&=ce^{-kx}\\
\end{align}

$$\therefore~y(x)~=~ce^{-kx}+\frac pk$$

Determining the constant $c$ by using $y(0)=y_0$ we get
$$y(0)=c+\frac pk=y_0\Rightarrow~c=y_0-\frac pk$$

$$\therefore~y(x)=\frac pk+\left[y_0-\frac pk\right]e^{-kx}$$

I cannot really tell where you went wrong but it is easy to check that your solution does not fulfill the initial condition since
$$y(x)=y_0e^{-kx}+\frac pk\Rightarrow y(0)=y_0+\frac pk\color{red}\neq y_0$$
A: Firstly, this is first-order.
We let $$y'+ky=p$$
Then use an integrating factor:
$$IF=e^{\int k dx}=e^{kx}$$
Then the trick:
$$y\cdot IF =\int{IF\cdot RHS \ dx}$$
$$\to ye^{kx}=\int{pe^{kx}\ dx}$$
$$\to y=\frac pk +Ce^{-kx}$$
You appear correct therefore, unless the initial condition changes something.
