<s>[INST] Given $\int_0^x (x-t+1)g(t)\,\mathrm{d}t = x^4 + x^2,$ Find $g(x)$ (Stanford Math Tournament 2012 #7)
A differentiable function $g$ satisfies $$\int_0^x (x-t+1)g(t)\,\mathrm{d}t = x^4 + x^2,$$ Find $g(x) \, \forall x \geq 0.$
My attempt:
First distribute the integrand to get: $$\int_0^x (x-t)g(t)\,\mathrm{d}t + \int_0^x g(t)\,\mathrm{d}t = x^4 + x^2$$
Then differentiate both sides with respect to $x$ (keeping in mind the Fundamental Theorem of Calculus Part 2 and the Chain Rule).
LHS: $$\frac{\partial}{\partial x} \left[\int_0^x (x-t)g(t)\,\mathrm{d}t + \int_0^x g(t)\,\mathrm{d}t\right] = \frac{\partial}{\partial x} \left[x\cdot\int_0^x g(t)\,\mathrm{d}t - \int_0^x tg(t)\,\mathrm{d}t + \int_0^x g(t)\,\mathrm{d}t\right] = \left[1\cdot \int_0^x g(t)\,\mathrm{d}t + x\cdot g(x) - x\cdot g(x) + g(x)\right] = \int_0^x g(t)\,\mathrm{d}t + g(x)$$
RHS: $$\frac{\mathrm{d}}{\mathrm{d}x} (x^4 + x^2) = 4x^3 + 2x$$
$$\therefore \int_0^x g(t)\,\mathrm{d}t + g(x) = 4x^3 + 2x$$
Differentiating again gives us: $$g(x) + g'(x) = 12x^2 + 2$$.
Now $g(x)$ can be found using undetermined coefficients. If we let $g(x)$ be a third degree polynomial $ax^3 + bx^2 + cx + d$, then $$g(x) + g'(x) = \left(ax^3 + bx^2 + cx + d\right) + \left(3ax^2 + 2bx + c\right)$$ $$g(x) + g'(x) = ax^3 + (3a + b)x^2 + (2b + c)x + (c+d)$$ $$g(x) + g'(x) = 12x^2 + 2$$ $$\implies a = 0, 3a + b = 12, 2b + c = 0, c+d = 2$$ $$\implies b = 12, c = -24, d = 26$$ $$\implies g(x) = ax^3 + bx^2 + cx + d = \boxed{12x^2 -24 x + 26}.$$
But, the answer provided by Stanford was $\boxed{g(x) = 12x^2 - 24x + 26 - 26e^{-x}}.$ Differentiating this function, it is obvious that the exponential part of $g$ will cancel itself out when $g(x)$ is added to $g'(x)$. However, what am I missing that is needed to solve for the $-26x^{-x}$ part, and how do I do so rigorously (i.e. using methods that don't rely completely on  just intuition)?
Sorry for the huge wall of text. I appreciate any and all help :)
Thanks
A
 [/INST] You have the following ODE:$$g(x) + g'(x) = 12x^2 +2$$
We can find the following integrating factor
\begin{align} I &= e^{\int1dx} \\ &= e^{x}\end{align}
Now multiplying through by $I$ gives
$$e^xg(x) + e^xg'(x)=e^x(12x^2 +2)$$
Thus we have that
\begin{align}\frac{d}{dx}(e^xg(x)) &= e^x(12x^2 +2)\end{align}
Integrating both sides w.r.t $x$ gives
\begin{align} \int\bigg[\frac{d}{dx}(e^xg(x))\bigg]dx &= \int e^x(12x^2 +2)dx \\ \implies e^{x}g(x) &= \int 12x^2e^x dx + \int2e^x dx \\ &= 12e^x(x^2 - 2x +2) + 2e^x + C \\ &= e^x\bigg[ 12x^2 - 24 x + 24 +2\bigg] + C \\ &= e^x\bigg[ 12x^2 - 24 x + 26\bigg] + C \\ \implies g(x) &= 12x^2 - 24x + 26 + e^{-x}C\end{align}
</s>