Calculation of capacitor voltage and current