Existence of a second order linear differential equation I have stumbled upon this problem in my differential equations homework:
Does there exist a second order linear homogeneous differential equation of the form $$y''+ p(x)y' + q(x)y= 0$$ such that $ p(x) $ and $ q(x) $ are continuous on the entire real line that has both $ f(x) = \cos(x) $ and $ g(x) = e^{x^2} $ as solutions? 
I have the general solution of $ y = c_1\cos(x) + c_2e^x $ and the $ y' $ and $ y'' $ of this function. I am guessing I need to combine the $ y, y', $ and $ y'' $ but I am having trouble canceling out the resulting constants. Any suggested paths or methods?
 A: Set $y_1=f$, $y_2=g$.
You want
$$\begin{bmatrix}q(x)\\p(x)\\1\end{bmatrix}^\top
\begin{bmatrix}y_i(x)\\y_i'(x)\\y_i''(x)\end{bmatrix} = 0
\qquad\text{for}\ i\in\{1,2\}$$
So you look for a vector $[q(x),p(x),1]$ whose dot product with two given vectors is zero. Well, that is what the cross product is for:
Setting
$$\begin{bmatrix}w(x)\\v(x)\\u(x)\end{bmatrix}
= \begin{bmatrix}y_1(x)\\y_1'(x)\\y_1''(x)\end{bmatrix}\times
\begin{bmatrix}y_2(x)\\y_2'(x)\\y_2''(x)\end{bmatrix}$$
Gives you functions $w,v,u$ such that
$$u(x)\,y_i''(x) + v(x)\,y_i'(x) + w(x)\,y_i(x) = 0
\qquad\text{for}\ i\in\{1,2\}$$
and dividing by $u(x)$ should give you
$$\begin{align}
    p(x) &= \frac{v(x)}{u(x)}
&   q(x) &= \frac{w(x)}{u(x)}
\end{align}$$
The catch is that $u(x)$ may be zero for some $x$ and that $p$ or $q$ might have
some non-removable singularities there. That would violate the requirement
that $p,q$ be continuous on the entire real line.
Indeed, in the given case, there are infinitely many $x_k$ such that $u(x_k)=0$
(left as an exercise). That implies
$$\begin{bmatrix}y_1(x_k)\\y_1'(x_k)\end{bmatrix}
= \lambda_k\begin{bmatrix}y_2(x_k)\\y_2'(x_k)\end{bmatrix}
\qquad \lambda_k = \frac{y_1(x_k)}{y_2(x_k)}$$
(using the fact that $y_2(x)=g(x)=\exp(x^2)$ is nonzero everywhere)
and therefore, if the ODE were to hold at $x_k$ with continuous $p$ and $q$,
we would have
$$\begin{gather}
    p(x_k)\,y_1'(x_k) + q(x_k)\,y_1(x_k)
    = \lambda_k\left(p(x_k)\,y_2'(x_k) + q(x_k)\,y_2(x_k)\right)
\\\therefore\quad
    y_1''(x_k) = \lambda_k y_2''(x_k)
\end{gather}$$
and altogether
$$\begin{bmatrix}y_1(x_k)\\y_1'(x_k)\\y_1''(x_k)\end{bmatrix}
= \lambda_k\begin{bmatrix}y_2(x_k)\\y_2'(x_k)\\y_2''(x_k)\end{bmatrix}$$
But then the cross product would be a triple of zeros.
In other words, whenever $u(x_k) = 0$, you also need $v(x_k)=0$ and $w(x_k)=0$,
otherwise the ODE cannot be fulfilled with continuous $p$ and $q$
at those $x_k$.
I leave it to you to check those conditions.
Hint: Checking $x=0$ is easy.
A: Simply put $f(x)$ and $g(x)$ into the equation to get
$$-\cos x-p\sin x+q\cos x=0\\
(2+4x^2)e^{x^2}+2xe^{x^2}p+e^{x^2}q=0$$
Therefore
$$\frac{q-1}p=\tan x\\
2+4x^2+2xp+q=0$$
And you can find $p,q$ by solving these two nonlinear equations.
