I am trying to solve the following ODE numerically-
$\frac{dn}{dt} = \frac{1-n}{T_A} - \frac{|u(t)|^2}{\omega_a}n$
with the condition
$n(-T_R/2) = 0$
$T_R, T_A$ and $\omega_0$ are constants
I have usually used a standard template to solve such DEs on MATLAB when the condition defines the value of the function at zero. How do I solve this particular equation? I would also love to know if this equation can be solved analytically, and if so, how?
You may introduce another integration variable, $s$ which is related to $t$ as $s = t + \frac{T_R}{2}$.
Your problem changes to $$ \frac{dn}{ds} = \frac{1-n(s)}{T_A} - \frac{|u(s - T_R / 2)|^2}{\omega_A} n(s)\\ n(s=0) = n\left(t = -\frac{T_R}{2}\right) = 0. $$ which is the standard form for integrating on $s \in \left[0, T_0 + \frac{T_R}{2}\right]$ interval.
If your ODE solver cannot integrate backwards in time (for the interval $s \in \left[-T_0 + \frac{T_R}{2}, 0\right]$ you may use the same trick. Introduce another integration variable $r = -s = -t - \frac{T_R}{2}$. Then $$ \frac{dn}{dr} = - \frac{dn}{dt} = -\frac{1 - n(r)}{T_A} + \frac{|u(r - T_R / 2)|^2}{\omega_A} n(r)\\ n(r = 0) = n\left(t = -\frac{T_R}{2}\right) = 0. $$ For this case the integration domain will be $r \in \left[0, T_0 - \frac{T_R}{2}\right]$