Deriving the charge as a function of time in a discharging capacitor There is obviously something I have not understood well. In Kirchoff's second law, we take the potential difference of batteries and capacitors with the sign that we traverse it. So, let's assume that we decide to traverse the circuit below clockwise.

By the loop law, we have
$$-IR+\frac{q(t)}{C}=-\frac{dq}{dt}R+\frac{q(t)}{C}=0,$$
where $q(t)$ is the charge left in the capacitor as a function of time.
Solving the above equation, we find
$$q(t)=Qe^{\frac{t}{RC}},$$
where $Q$ the charge in the capacitor the moment it started discharging (assumed to be $t=0$). This solution is obviously wrong, as $q(t)$ needs to fall off exponentially, and not increase.  What am I doing wrong?
 A: For any instant $t$:
$$\frac{Q}{C} = RI$$
We want to relate the amount of charge that passes through the resistor to what happens at the plates of the capacitor. If, for a small interval $\delta t$ $$I = \frac{\delta q}{\delta t}$$  it corresponds to a loss of charge in the capacitor:$\delta q = -\delta Q$
So the correct differential equation is (when $\delta t$ go to $0$):
$$\frac{Q}{C} = R\frac{-dQ}{dt} = -R\frac{dQ}{dt}$$
A: If q(t) is defined as the charge left in the capacitor at time t, then the Kirchhoff's 2nd law across the loop is not written down correctly as there should be no relative minus sign between two terms. The source of this mistake is the inconsistency between two different conventions of circuits. In your case, given the polarity of your plates, the direction of the current is correct but as you want to pass through your capacitor, you are passing against the circuits' convention of current (which is form "+" polarity to "-" polarity inside the circuit element--capacitor in here.) In other words, you need to add a minus sign to compensate for opposing the normal convention just mentioned above. This means that your second term of the law will be also a negative. Once corrected, you will have a valid solution which would be what you expect. 
