Solve $\frac{dx}{dt}=\frac{at-\cos{x}}{at^2\tan{x}+t}$ Solve $\begin{align*}\frac{dx}{dt}=\frac{at-\cos{x}}{at^2\tan{x}+t}\end{align*}\\\\
$
Am I justified in doing the following substitution? If not, can a closed-form solution be found?
Let $t=r\cos{x}$ and $dt=-r\sin{x}dx$
$\begin{align}
\frac{dx}{dt}&=\frac{(ar-1)\cos{x}}{ar^2\cos^2{x}\tan{x}+r\cos{x}}\\\\
\frac{dx}{dt}&=\frac{(ar-1)\cos{x}}{(ar\sin{x}+1)r\cos{x}}\\\\
dx&=-\frac{(ar-1)}{(ar\sin{x}+1)r}r\sin{x}dx\\\\
1&=-\frac{(ar-1)\sin{x}}{(ar\sin{x}+1)}\\\\
ar\sin{x}+1&=-(ar-1)\sin{x}\\\\
1&=(1-2ar)\sin{x}\end{align}$
Therefore,
$\begin{align}
1&=-(1-2ar)\frac{dt}{rdx}\\\\
\int{rdx}&=\int(2ar-1){dt}\\\\
x&=(2a-\frac{1}{r})t+c
\end{align}$
EDIT:
Here is some background on the above differential equation.
The following equations describe the requirements of a curve $f$ which elastically reflects particles in a desired fashion, the details of which I will not cover.
$\begin{equation}f(x,t)=t \tan{x}+\frac{a}{2}t^2 \sec^2{x}+h, \ \ \ \ \ 0<x<\pi \\\\
\frac{\partial f(x,t)}{\partial t}=\tan{\left(\frac{x}{2}-\frac{\pi}{4}\right)}
\end{equation}$
where $x$ is t-dependent. We can differentiate the first equation above with respect to t, taking care to evaluate the derivative of $x$, as well.
\begin{align*}\frac{\partial f\left(x, t\right)}{\partial t}&=\tan{x}+t\sec^2{x}\frac{dx}{dt}+at\sec^2{x}+at^2\tan{x}\sec^2{x}\frac{dx}{dt}\\\\
\tan{\left(\frac{x}{2}-\frac{\pi}{4}\right)}&=\tan{x}+\left[\left(t+a t^2\tan{x}\right)\frac{d x}{dt}+at\right]\sec^2{x}\\\\
\tan{x}-\sec{x}&=\tan{x}+\left[\left(t+a t^2\tan{x}\right)\frac{d x}{dt}+at\right]\sec^2{x}\\\\
\frac{dx}{dt}&=\frac{at-\cos{x}}{at^2\tan{x}+t}\\\\
\end{align*}
 A: $$\frac{dx}{dt}=\frac{at-\cos{x}}{at^2\tan{x}+t}$$
As you know, the ODEs not issued from scholar exercises are rarely solvable in terms of standard functions. 
The solutions of some ODEs frequently encontered are now expressed on closed form because special functions were especially defined and standardized just for this use. 
It seems that the solutions of your ODE cannot be expressed on closed form with the standard special functions presently available.
If you need to present your numerical results on a more theoretical aspect, on the form of a mathematic formula, I don't see other way than to create a new special function. Of course this special function will be a non-standard special function.  
Citation from https://fr.scribd.com/doc/34977341/Sophomore-s-Dream-Function , p.3 : 
<< A special function has to acquire a background of property, descriptions,
formulas and derivations as extended as possible. So, it will be preferable to simply refer to a particular part of the background, instead of searching and redoing a development by ourselves. Before becoming a referenced special function, its name has to be spread in the literature in order to become familiar. More importantly, the function should be useful in a
branch of mathematics or physics. >>
To make the study and description more concise and recognizable, chose a name (for example "MDF" : the Master Drifter's Function) and change of symbol :
$$\begin{cases} X=at \\ MDF(X)=x \end{cases} \quad\to\quad 
\frac{d}{dX}MDF=\frac{X-\cos(MDF)}{X^2\tan(MDF)+X} $$ 
Gives a description of the new function $MDF(X)$ : properties, behaviour, table of numerical values, etc. coming from numerical solving of the ODE just above.
The closed form of the solution of the initial ODE will be :
$$x(t)=MDF(at)$$
In fact, this is valid only for a given initial condition (or boundary condition). To give more extent to the new function $MDF(p\:;\:X)$, a parameter should to be introduced and numerical calculus done for various initial conditions, together with the relationship beteween $p$ and the initial condition. So that, the general solution of the initial ODE would be :
$$x(t)=MDF(p\:;\: at)$$
with any constant $p$ if the initial condition is not defined, or with a specific value of $p$ according to the initial condition if known.
