Using integration to find the population $x$ after a time $t$ years. Having a problem with getting a negative log input. I'm a little bit confused by a question I came across. It says:
If there were no emigration the population $x$ of a county would increase at a rate of $2.5 \%$ per annum.
By emigration a county loses a population at a constant rate of $n$ people.
When $t$ is in years then $\tfrac{dx}{dt}=\tfrac{x}{40}-n$
$i)$ Find $x$ in terms of $n,P,$ and $t$.
$ii)$ If $n=800,$ $P=30,000, $   and $ x=29734$, then what is $t$?
Here's what I thought you'd do:
$\tfrac{dx}{dt}=\tfrac{x}{40}-n=\tfrac{x}{40}-\tfrac{40n}{40}=\tfrac{x-40n}{40}$
Therefore
$\tfrac{40dx}{dt}=x-40n \Rightarrow \tfrac{dx}{x-40n}=\tfrac{dt}{40}$
Integrating both sides we get, for the left hand side :
$\int \tfrac{dx}{x-40n}=\ln(x-40n)+C_1$
Right hand side: $\int \tfrac{dt}{40}=\tfrac{t}{40}+C_2$
Combing these equations we get :
$\ln(x-40n)=\tfrac{t}{40}+C_3$  where $C_3=P$
Exponentiating both sides yields
$x-40n=e^{\tfrac{t}{40}+P}=Pe^{\tfrac{t}{40}}$
Therefore
$x=e^{\tfrac{t}{40}+P}+40n$
But then my problem is noticed when we arrive at part two.
Inputting that data into the formula I obtained will result in having to calculate a negative log input to find $t$, but of course those are undefined. Where have I gone wrong?
 A: Now that I've had time to look at this carefully...
(so I withdrew my earlier comments)
The differential equation can be treated as separable:
$$ \frac{dx}{x-40n} \ \ = \ \frac{dt}{40} \ \ , $$
but now you're going to see why we always said in first-semester calculus that the integral is
$$ \ln |x \ - \ 40n| \ \ = \ \ \frac{t}{40} \ + \ C \ \ . $$
As you learned back in algebra, an equation with an absolute-value term generally means we need to consider two cases:
If $ \ P > 40n \ \ , $ then $ \ |x - 40n| \ = \ x - 40n \ \ $ and we can evaluate the integration constant at $ \ t = 0 \ $ as
$$ \ln \ (P \ - \ 40n) \ \ = \ \ \frac{0}{40} \ + \ \ln \ (P \ - \ 40n) \ \ \Rightarrow \ \ C \ = \ \ln \ (P \ - \ 40n) $$
and the population function becomes
$$ x \ - \ 40n \ \ = \ \ (P \ - \ 40n)·e^{t/40} \ \ \Rightarrow \ \ x(t) \ = \ (P \ - \ 40n)·e^{t/40} \ + \ 40·n \ \ , $$
as you were finding.
Notice in the differential equation that $ \ \frac{dx}{dt} \ = \ \frac{x}{40} \ - \  n \ \ = \ \ 0 \ \ $ means that the population remains constant if $ \ \frac{x}{40} \ = \ n \ \Rightarrow \ x \ = \ 40n \ \ . $  So if the population starts at $ \ P \ = \ 40n \ \ , $ the emigration exactly balances the population growth, so the population never changes.  This is an equilibrium value for the population, which divides the behavior of the population in time.  What you worked out is the case where the initial population is above that equilibrium value.
However, the conditions you are given for your problem represent the case where the initial population is less than the equilibrium value $ \ ( \ P < 40n \ ) \ . $  That will have a rather different behavior.  We must use the other case for the absolute-value term, $ \ |x - 40n| \ = \ -(x - 40n) \ \ : $
$$ \ln \ (40n - x) \ \ = \ \ \frac{t}{40} \ + \ C \ \ \Rightarrow \ \    \ln \ (40n \ - \ P) \ \ = \ \ \frac{0}{40} \ + \ \ln  \ (40n \ - \ P) $$ $$ \Rightarrow \ \ C \ = \ \ln \ (40n \ - \ P) $$
and the population function becomes
$$ 40n \ - \ x \ \ = \ \ (40n \ - \ P)·e^{t/40} \ \ \Rightarrow \ \ x(t) \ = \ 40n \ - \ (40n \ - \ P)·e^{t/40}  \ \ . $$
For the specified conditions, you would then work with
$$ x(t) \ = \ 40·800 \ - \ (40·800 \ - \ 30000)·e^{t/40} \ \ = \ \ 32000 \ - \ 2000·e^{t/40}  \ \ . $$
What we have is a population which will eventually fall to zero because population growth is gradually overwhelmed by emigration.  (The earlier case is one in which population grows without limit because emigration is never enough of a "drain" on the population.)
[Sorry about the earlier confusion.]
ADDENDUM -- In regard to one of the comments I had made (and deleted), this equation can also be solved by use of an "integrating factor".  If we write it as  $ \ \frac{dx}{dt} \ - \ \frac{1}{40}·x \ = \ -n \ \ , $ we will have the integrating factor $ \ e^{-t/40} \ \ $ and the population function found by that method is
$$ x(t) \ \ = \ \ 40n \ + \ (P \ - \ 40n) · e^{t/40} \ \ . $$
The advantage of using this approach to solving the differential equation is that it avoids the pitfall of the absolute-value in the logarithmic term we had above.  This version of the population function can be used for any of the initial conditions.
