# Linear ordinary differential equation.

## Homework Statement

##\dfrac{dy}{dx} + y = f(x)##

##f(x) = \begin{cases} 2 \qquad x \in [0, 1) \\ 0 \qquad x \ge 1 \end{cases}##

##y(0) = 0##

## The Attempt at a Solution

Integrating factor is ##e^x##

##e^x\dfrac{dy}{dx} + e^x y = e^x f(x)##

##\displaystyle ye^x = \int e^x f(x) dx = \begin{cases} \int 2e^x dx = 2e^x + C \qquad x \in [0, 1) \\ \int 0 dx = C^\prime \qquad x \ge 1 \end{cases}##

Solving for inital value,

##ye^x = \begin{cases} 2(e^x - 1) \qquad x \in [0, 1) \\ 0 \qquad x \ge 1 \end{cases}##

The answer is ##ye^x = \begin{cases} 2(e^x - 1) \qquad x \in [0, 1) \\ 2(e - 1) \qquad x \ge 1 \end{cases}##
, which is way off.

I think the fault is in my answer this time but I can't point it :(.

Homework Helper
Gold Member
2020 Award
From your first solution ## y(1)=2(1-e^{-1} ) ##. (We're going to assume that ## y ## is continuous at ## x=1 ##). From the second solution ## y \, e^x=C' ## . But ## C'=y(1) e^1 ##. Thereby ## y e^x=2(e-1) ## for ## x>1 ##.

Buffu
epenguin
Homework Helper
Gold Member
Finding in integration factor seems over-engineering. You could just as well treated as two differential equations, both very simple:

y' = -y and y' = - ( y - 2 ) .

The arbitrary constant for the solution of the second is in principle arbitrary, but it would be natural to treat it as given by a requirement of continuity as already mentioned.

Buffu
Homework Helper
Gold Member
2020 Award
One question/comment for @Buffu is how do you know that the homogeneous solution ## y=A \, e^{-x} ## doesn't play a role in the solution? That is apparently an underlying assumption in the problem (that you ignore any homogeneous solution), but it is always good practice to consider the possibility of a homogeneous solution. ## \\ ## Editing: In the solution for ## x>1 ##, the solution is in fact the homogeneous solution. Also, for ## 0<x<1 ##, the integrating factor method you used actually generated a homogeneous solution. ## \\ ## Let me offer an alternative solution to the differential equation above: For ## 0<x<1 ##, ## y_p=2 ## and the homogeneous solution is ## y_h=A \, e^{-x} ##, so that for ## 0<x<1 ## , ## y=2+A \, e^{-x} ## for some ## A ## . ## \\ ## For ## x>1 ##, ## y_p=0 ##, and ## y_h=B \, e^{-x} ##, so that ## y=B \, e^{-x} ## for some ## B ##. ## \\ ## The constants ## A ## and ## B ## are easily found.

Last edited:
Homework Helper
Gold Member
2020 Award
@Buffu I edited my comments in post #4, because I see your solution, using an integrating factor, actually resulted in generating the necessary homogeneous solution. There is, as @epenguin pointed out, a simple solution that doesn't require an integrating factor. Please see my edited post #4.

Last edited:
Yes I see what mistake I made.
Thank you.

For the integrating factor, I did not see that DE here is a simple separable because I overlooked the condition on ##f(x)##. I thought, let me reduce the equation first then I will care about ##f(x)##.