How to compute the charge as a function of time in a simple $CL$ circuit?

I am trying to compute $q(t)$ in a series circuit consisting of a capacitor of plate charges $q_0$ and $-q_0$ and an inductor. The switch is closed at time $t=0$.

By Kirchoff's Law, $$\frac{q}{C}+L\frac{dI}{dt}=0.$$ There is a conservation of charge in this circuit, so $I=\dot{q}$, which gives us the differential equation $$\ddot{q}+\frac{1}{LC}q=0.$$ I recognise that this is the equation of a harmonic oscillator with angular frequency $\frac{1}{\sqrt{LC}}$, so $$\ddot{q}+\omega^2 q=0.$$ To solve this I construct a characteristic equation $$\lambda^2+\omega^2=0 \implies \lambda=\pm i\omega$$ and taking only the positive root gives the solution $q(t)$ as $$q(t)=A\cos{\omega t}+Bi\sin{\omega t}.$$ The total initial charge in the circuit is from the capacitor and is given by $q(0)=CV$, so we get $A\cos{\omega t}=CV \implies A=CV.$ Then $$q(t)=CV\cos(\omega t)+Bi\sin(\omega t).$$ I know that the answer should not have the imaginary term in it, but how to I eliminate it or show that B=0?

• This is a second order differential equation, so it's only well defined if you have two boundary conditions. You listed one: $q(0)=CV$, but there must be another. Commented Dec 18, 2017 at 21:20
• Hint: What is the current at time $t=0$?, or, more explicitly, $I(0)=\dot{q}(0)$.
– jim
Commented Jun 28, 2018 at 8:53

Recognize the initial condition: at t=0, no current is flowing. That means that the charge is a maximum at t=0, and that means that B=0. For a different initial condition, the equation just means there is a phase shift - that is, you could write $\cos\omega t + \phi$ instead of introducing a complex amplitude.
When we use complex numbers for solving harmonic equations, it is really just because it usually makes the math easier (more so if you use $Ae^{i\omega t}$ notation with $A$ a complex number): the actual amplitude at a given moment in time is the real part of the expression.
You had no right to discard the negative root! And including it gets you out of trouble. The general solution of $$\ddot q +\omega^2 q=0$$ is $$q= (C+iD) e^{i\omega t}+\ (E+iF) e^{-i\omega t}.$$ $$q$$ will be real if (and only if) $$(E+iF)$$ is the complex conjugate of $$(C+iD)$$, that is $$q= (C+iD) e^{i\omega t}+\ (C-iD) e^{-i\omega t}.$$ Putting $$e^{±i\omega t}=\cos \omega t ± i\sin \omega t$$ and multiplying out we find
$$q=q_1 \cos \omega t + q_2 \sin \omega t \ \ \ \ \text{(having put q_1=2C, q_2=-2D)}$$ Of course you could reach this result without using complex numbers in the first place. I've continued your use of them just to get you back (I hope) on track.
Your next step is, of course, to show that $$q_2 =0$$. This has nothing to do with complex numbers.