# 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

• Could you maybe add the initial condition? Without one cannot really determine which solution is the right one. – mrtaurho Jan 19 '19 at 19:38
• When $x=0$ your equation reads $y(0)=y(0)+p/k$ – user121049 Jan 19 '19 at 19:39
• my teacher's file says "for $x \in [0,X]$", so I think the initial condition is $y(0) = 0$ – user3204810 Jan 19 '19 at 19:43
• Both are right but in your solution the constant is not $y(0)$ – Dylan Jan 20 '19 at 6:37

## 3 Answers

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$$

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$$

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.

• I corrected. Sorry for the mistake – user3204810 Jan 19 '19 at 19:56