Writing the quotient of solutions of linear ODEs as the solution of a nonlinear ODE Let $A(x)$ and $B(x)$ be solutions to homogeneous linear ODEs with polynomial coefficients, i.e., $A(x)$ satisfies
$$p_KA^{(K)} + p_{K-1}A^{(K-1)} + \cdots + p_1A' + p_0A=0$$
and $B(x)$ satisfies
$$q_LB^{(L)} + q_{L-1}B^{(L-1)} + \cdots + q_1B' + q_0B = 0,$$
for polynomials $\{p_i(x)\}$ and $\{q_i(x)\}$.
Suppose $B$ is non-vanishing in a neighborhood of zero and define $F(x) = \frac{A(x)}{B(x)}$. I'd like to find an ODE with polynomial coefficients (in terms of the $p_i$ and $q_i$) that $F(x)$ satisfies.  In most cases, it will necessarily be nonlinear. Because I won't know $A(x)$ and $B(x)$ a priori, the ODE must be only in terms of $F$, $\{p_i\}$, and $\{q_i\}$. I'm treating the functions as generating functions and so I'm only concerned with formal power series solutions and not with actual convergence.

In the case where $K=1$ and $L=1$, one can proceed as follows. Suppose
$$p_1A' + p_0A=0\qquad\text{and}\qquad q_1B' + q_0B=0.$$
Then
$$A' = -\frac{p_0}{p_1}A\qquad\text{and}\qquad B' = -\frac{q_0}{q_1}B.$$
Now,
$$F' = \frac{A'B - AB'}{B^2} = \frac{-\frac{p_0}{p_1}AB + \frac{q_0}{q_1}AB}{B^2} = \left(-\frac{p_0}{p_1}+\frac{q_0}{q_1}\right)\frac{A}{B} = \left(-\frac{p_0}{p_1}+\frac{q_0}{q_1}\right)F$$
and so the desired ODE is
$$F' - \left(\frac{p_0}{p_1} - \frac{q_0}{q_1}\right)F = 0.$$
(It just happens to be linear in this simple case.)

In the case where $A(x)=1$ (and so $F(x) =\frac{1}{B(x)}$), the same technique works by using derivatives of $F$. However, in the general I encounter terms like $\frac{A'}{B}$ that I do not know how to write in terms of $F$ and its derivatives. Even a solution that works for $K=L=2$ would be enlightening!
 A: This is probably not the kind of answer you were hoping for, I'm just going to argue (somewhat informally, at that) that there will be such an ODE, without giving one explicitly. Note also that I only want an ODE that is solved by $F=A/B$ whenever $A$, $B$ solve their linear equations; the ODE can have other solutions (as discussed in the comments to the OP).
Clearly a necessary condition for the existence of an ODE of order $n$,
$$
y^{(n)}(x) = g(x; y,y',\ldots , y^{(n-1)})
$$
that is solved by $y=A/B$ for any choice of $A,B$, $B\not=0$ locally, is that whenever
$$
\frac{d^j}{dx^j} \frac{A_1(x)}{B_1(x)} = \frac{d^j}{dx^j} \frac{A_2(x)}{B_2(x)} \quad\quad j=0,1,\ldots ,n-1
$$
at some point $x=x_0$, then $A_1/B_1\equiv A_2/B_2$.
Conversely, if this holds, then the map
$$
C\mapsto (F(x,C),F'(x,C),\ldots , F^{(n-1)}(x,C)) \quad\quad\quad\quad (1)
$$
is injective for any fixed $x$. Here, I write $F=A/B$ and $C=(C_1,\ldots ,C_{K+L})$ for the $K+L$ constants from the general solutions of the linear ODEs. Thus, since any $F=A/B$ is completely determined by these constants, we can use the inverse map and express
$$
F^{(n)} = g(x; F(x,C),F'(x,C), \ldots , F^{(n-1)}(x,C)) ,\quad\quad\quad\quad (2)
$$
and this is the desired ODE. Observe that the process of going from $C$ to $F^{(j)}(x,C)$ can in principle be implemented by solving the linear ODEs, so this depends on the $p_k,q_k$ and nothing else, as required.
So I must now find an $n$ that does make (1) injective. This will certainly be possible at a fixed $x$, for some $n=n(x)$ because the solutions to the linear ODEs are real analytic in $x$. Then (2) will hold on at least an interval containing $x$, by real analyticity again (I'm being extremely sloppy here, an explicit argument would have to address quite a few missing details).
