Find a continuous solution to dy/dx + y = f(x) 
Find a continuous solution satisfying:
  $$
\frac{dy}{dx} +y= f(x)
$$
  Where
  $$ 
f(x) =  \begin{cases} 1  &\text{ for } 0 < x < 1, \\
0 & \text{ for } x > 1 \end{cases} 
$$ 
  with the initial condition $y(0)=0$. 

I'm not sure what the best way to approach this question is. 
I thought I could solve it using Fourier series which gave me the particular solution of:
$$f(x) = -\frac12 + \sum_{n=1}^{\infty}\left[-\frac{1}{n\pi} + \frac{1}{n\pi} (-1)^n \right] \sin (n\pi x) $$
Then I found the complementary function $y = e^{-x}$
Is this correct?
If so, I'm not sure what the full general solution would be, or if this is even a 'continuous solution'.
 A: The function $f$ is not periodic, thus the Fourier series will not help. Perhaps you know the Laplace transform?
The easiest path is to take the homogeneous solution and apply the integrating factor resp. the variation of constants approach. Then
$$
(e^xy(x))'=e^xf(x)
$$
which now can be easily integrated over $(0,1)$ and $(1,\infty)$ with adaptation of the integrating factor to get the pieces together to a continuous function $y$.
$$
y(x)=\begin{cases}
1-e^{-x}&0<x<1,\\
1-e^{-1}&x=1,\\
(e-1)e^{-x}&x>1.
\end{cases}
$$
A: This would be more easily solved by the Laplace transform. It can be used to find solutions to various ODEs where not every element is necessarily continuous (the functions just have to be piecewise functions).
Using the Heaviside function
$$H(x-x_0)= \begin{cases} 0, \quad x<x_0 \\ 1, \quad x > x_0 \end{cases} $$
Write your $f(x)$ in terms of it. Then, the solution comes from the application of the Laplace transform.
Hint: 
Use the fact that
$$\mathcal{L}\{H(x-x_0)\} = \frac{e^{-x_0s}}{s}$$
Where $\mathcal{L}$ is the Laplace transform of $f$.
A: Solve the ODE for a) $0<x<1$ and for b) $1<x$.
For a) $$y'+y=1 \implies y(x)=c_1\exp(-x)+1$$
Using the initial condition you will obtain:
$$y(x)=1-\exp(-x).$$
For $x=1$ we will have $y(1)=1-\exp(-1)$ which we will use as initial condition for the second equation.
For b) $$y'+y=0 \implies y(x)=c_2\exp(-x)$$ 
using the initial condition $y(1)=1-\exp(-1)=c_2\exp(-1) \implies c_2=\exp(1)-1$.
Hence, the solution for the case b) is given by:
$$y(x)=\left[\exp(1)-1 \right]\exp(-x).$$
The complete solution is given by:
$$y(x) = \begin{cases}
1-\exp(-x) & \text{ for } 0 < x \leq 1\\
\left[\exp(1)-1 \right]\exp(-x)& \text{ for } 1 < x.\\
\end{cases}$$
Remark. Note that the solution is not differentiable at $x=1$ but continuous.
A: $f(x)$ is pretty simple, so we can just solve it piecewise. The homogeneous solution has the form $y=ce^{-x}$ and the particular solution is a constant, so we have a general solution
$$ y(x) = \left\{ \begin{matrix} 1 + c_1e^{-x}, && 0<x<1 \\ c_2 e^{-x}, && x > 1 \end{matrix} \right. $$
The initial contidion $y(0) = 0$ gives $c_1= -1$
The continuity condition $y(1) = 1-e^{-1}$ gives $c_2 = e-1$
