Is the 50% loss of energy when charging a cap from a battery a set rule in stone?
So the voltage in such a capacitor is the integral of current over time (\$V=V_0 + 1/C * \int_0^TI dt\$).

Right away we see the problem.  The perfect voltage source will force a voltage of 12V across the capacitor.  Meanwhile, the ideal capacitor will force the voltage to be 0V, and start integrating the current that flows through it.  The voltage cannot be 0V and 12V simultaneously.

Battery resistance to the rescue!  The circuit has resistance.  In fact, a good chunk of it is the resistance of the battery.  So we really have a voltage source, a resistor, and a capacitor.







simulate this circuit &ndash; Schematic created using CircuitLab

This is more manageable.  When you throw the switch, the voltage across the capacitor is 0, the voltage across the resistor is 12V, and everything is sane.  At t=0, 100% of the power flows through the resistor. This means there's current flowing, and the capacitor can charge.  This increases the voltage of the capacitor according to the following equation:

$$ V = V_s(1 + e^\frac{-t}{RC})$$

where V_s is the source voltage (12V), t is time, R is the resistance (of the parasitic elements like the battery), and C is the capacitance of the capacitor.

Now we can find the current.  Since all the current flows through the resistor, and the resistor has \$(V_s - V)\$ volts across it, the current at any moment in time is \$\frac{V_s - V}{R}\$.

Now we can look at the power loss in the resistor: \$(V_s - V)^2/R\$.  Integrating this over time, we get
$$\int_0^T \frac{V_s - V_s(1 + e^\frac{-t}{RC}))^2}{R}dt$$
$$= \int_0^T \frac{V_s^2}{R}e^\frac{-t}{RC}dt$$
$$\left[\frac{1}{2}V_s^2Cexp(-2t/RC)\right]_0^T$$
$$\frac{1}{2}V_s^2Cexp(-2T/RC) - \frac{1}{2}V_s^2C$$

Now we're interested in "completely charged" which is what we get as T approaches infinity.  In this case, the first term drops out completely (because \$\lim_{x\to \infty}e^{-x} = 0\$).  The final energy lost across the resistor is \$\frac{1}{2}V_s^2C\$.

Now, when the capacitor is fully charged, It's stored energy is defined just by the instantaneous voltage across the capacitor.  \$\frac{1}{2}CV^2\$.  Note that when \$V = V_s\$ (i.e. fully charged), this energy stored in the capacitor is exactly equal to the energy lost by the resistor.

This shows that if you charge a capacitor with nothing but a real voltage source (i.e. battery), you must lose 50% of the energy (to heat).