Finding the extrema of a functional (calculus of variations) I am trying to understand the basics of calculus of variations. To that effect I am trying to solve a problem stated as follows:
Find an extremal for $$I(y) = \int^1_0y'^2 - y^2 + 2xy dx$$
So I calculated:
\begin{align*}
\frac{\partial F}{\partial y'} &= 2y' \implies  \frac{d}{dx}\bigg(\frac{\partial F}{\partial y'}\bigg) = 2y'' \\
 \frac{\partial F}{\partial y} &= -2y + 2x
\end{align*}
Which gives the Euler equation $2y'' +2y - 2x = 0$ (I think, unless I messed up my math).
Ok now I need to try to find solutions to this differential equation, however, I only know how to solve linear second order DE's. The $x$ term is throwing me off and I am not sure how to solve this.
I know $y(x) = x$ is a solution by inspection, but inspection is a poor man's approach to solving DE's.
 A: As you found already a particular solution, by inspection or intuitive application of the method of undetermined coefficients, you only need the complementary solution of the homogeneous equation to get the general solution as sum of both.
You are looking for solutions satisfying the boundary conditions $y'(0)=  y'(1)=0$, as
$$\begin{align}
I(y+\varepsilon v) &= \int^1_0[y'^2+2εy'v' - y^2-2εyv + 2xy+2εxv+O(ε^2)]\, dx
\\
&=I(y)+2ε\bigl[y'v\bigr]_0^1+2ε\int^1_0[-y''-y+x]v\,dx+O(ε^2).
\end{align}$$
So to get the first-order terms to zero under free variation of $v$, the values of $y'$ at the boundary need to be zero.
A: Another Approach
$$
\begin{align}
\delta I(y)
&=\delta\int^1_0\left(y'^2-y^2+2xy\right)\mathrm{d}x\tag{1a}\\
&=\int^1_0\left(2y'(\delta y)'-2y\,\delta y+2x\,\delta y\right)\mathrm{d}x\tag{1b}\\
&=\int^1_0\left(-2y''\delta y-2y\,\delta y+2x\,\delta y\right)\mathrm{d}x\tag{1c}\\
&=-2\int^1_0\left(y''+y-x\right)\delta y\,\mathrm{d}x\tag{1d}
\end{align}
$$
Explanation:
$\text{(1a)}$: apply the definition of $I$
$\text{(1b)}$: take the first variation of the integral
$\phantom{\text{(1b):}}$ using equality of mixed partials, i.e. $\delta(y')=(\delta y)'$
$\text{(1c)}$: integration by parts (assuming $\delta y=0$ or $y'=0$ at $0$ and $1$)
$\text{(1d)}$: collect terms
To guarantee that $\delta I(y)=0$ for all $\delta y$, we need
$$
y''+y=x\tag2
$$
Which is the same equation as derived in the question.

Solving $\bf{(2)}$
In this case, noting that $y=x$ is a particular solution would probably be good enough. Then all one needs is the homogeneous solutions. In any case, we can solve $D^2+1$ by inverting $D-i$ and $D+i$:
Note that
$$
u=e^{-cx}\int e^{cx}f(x)\,\mathrm{d}x\implies(D+c)u=f\tag3
$$
Thus, we can invert $D+c$.
Applying $(3)$ twice, we get
$$
\begin{align}
(D-i)(D+i)y&=x\tag{4a}\\[3pt]
(D+i)y&=e^{ix}\int e^{-ix} x\,\mathrm{d}x\tag{4b}\\
&=1+ix+c_1e^{ix}\tag{4c}\\[3pt]
y&=e^{-ix}\int e^{ix}\left(1+ix+c_1e^{ix}\right)\,\mathrm{d}x\tag{4d}\\
&=x+\frac{c_1}{2i}e^{ix}+c_2e^{-ix}\tag{4e}
\end{align}
$$
Therefore, the solution to $(2)$ is
$$
y=x+a\sin(x)+b\cos(x)\tag5
$$
where $a$ and $b$ depend on the initial conditions.
This gives enough freedom to set $y(0)$ and $y(1)$. For example, the extremal function for $y(0)=y(1)=0$ is
$$
y=x-\frac{\sin(x)}{\sin(1)}\tag6
$$
Which gives the minimal $I(y)=\cot(1)-\frac23$.
