Solution to $y′=x+y,\, y(0)=1$ I am trying to learn numerical method for differentials. It is key for me to understand this stuff right now, but I've come across an obstacle.
The books I read about these all seem to often say 'exact solution is easily found to be' in more or less the same way. I clearly have an issue with this, because I do not know any practical method, or even the name of the method I am suppose to learn, to find this sort of solution 'easily' or sometimes at all.

We shall illustrate our methods by applying them to the simple problem
$y′=x+y, y(0)=1, (3)$ which we call our benchmark problem. This
differential equation in $(3)$ is clearly linear, and the exact solution
is easily found to be $y=2e^x − x − 1$.

I look at this, and I don't understand. I guess I can say I covered one of these ideas which is that $y'=y, y(0) = 1$ because it is glearingly obvious that the only thing that differentiates to itself is $e^x$.
Now, $y' = x+y$, how would I approach that? What is the method behind the solution to get there? I tried to look at the solution instead, but $y'$ of the solution for me is $2e^x - 1$.
This must be something really trivial, but I just don't get it.
 A: This is trivial... when you know the theory of differential equations. I will lead you to a solution by an ad-hoc trial and error process.
You correctly observe that $(e^x)'=e^x$. If we plug this tentative solution in the equation, we have
$$e^x\color{red}=x+e^x$$ which is not what we want because of the term $x$. So let us try $y=e^x-x$, and we get
$$e^x-1\color{red}=e^x.$$ Then to get rid of the $1$, $y=e^x-x-1$, and
$$e^x-1=e^x-1.$$
But we are not done yet, because of the condition $y(0)=1$, while our solution says $y(0)=0$. But recall that $(e^x)'=e^x$, so that we can freely add terms $e^x$ without violating the equation. As we are off by one unit and $e^0=1$, the fix is
$$y=e^x+e^x-x-1.$$

The real way would be:

*

*characterize the equation as first order linear with constant coefficients.


*solve the "homogeneous" part of the equation, $y'-y=0$, giving $y=ce^x$ for some $c$;


*find any solution of the initial equation, $y'-y=x$. As the RHS is a linear polynomial, we can try a linear polynomial, let $ax+b$. Then $a-ax-b=x$ yields $y=-x-1$.


*combine these two solutions $y=ce^x-x-1$ and solve for $c$ after plugging the condition $y(0)=1$, which gives $c=2$.
A: I solve
$y' = y + x, \; y(0) = 1 \tag 1$
in another "real way", as follows: write the equation as
$y' - y  = x; \tag 2$
make the clever observation that
$(e^{-x}y)' = -e^{-x}y + e^{-x}y'$
$= e^{-x}y' - e^{-x}y = e^{-x}(y' - y); \tag 3$
in light of (2) this becomes
$(e^{-x}y)' = xe^{-x}; \tag 4$
integrate 'twixt $0$ and any value of $x$:
$e^{-x}y(x) - y(0) = \displaystyle \int_0^x (e^{-u}y(u))'  \; du = \int_0^x ue^{-u} \; du; \tag 5$
the right-hand integral may be integrated by parts to yield
$\displaystyle \int_0^x ue^{-u} \; du = -(x + 1)e^{-x} + 1; \tag 6$
substituting this and the initial condition $y(0) = 1$ into (5):
$e^{-x}y(x) - 1 = -(x + 1)e^{-x} + 1, \tag 7$
or
$y(x) = 2e^x - x - 1. \tag 8$
Check:
from (8),
$y' = 2e^x - 1, \tag 9$
$y'- y = x, \tag{10}$
$y' = y + x, \tag{11}$
$y(0) = 1; \tag{12}$
(11) and (12) together are (1). $ \checkmark$
A: There is another way to solve $$y'=y+x$$ Let $y=z-x$ to make
$$z'-1=z\implies z'-z=1$$ Now, the homogeneous solution is $z=c e^{x}$. Use now the variation of parameter to get
$$c' \,e^{x}=1 \implies c'=e^{-x}\implies c=-e^{-x}+k\implies z=-1+ke^{x} $$ Back to $y$
$$y=-x-1+ke^{x}$$ and using the condition $k=2$
$$y=2e^{x}-x-1$$
