Why is my macro to compute average power not equalling zero? Theory says
that the average power for a capacitor is zero.
Your macro calculates power based on current and voltage, which are slightly
out of sync since you are using an electrostatic element which solves for charge
and computes current by a numerical derivative over two time steps. Due to this
the current value is half a time step behind the voltage.
To investigate this possibility I modified your current array to be the
average of the values at t and t+1 as follows:
Current(iii) = (Current(iii) + Current(iii+1))/2
I then computed power by multiplying the current array by the voltage
array with *VOPER. The mean value of this calculation (calculated by VSCFUN)
is quite small as shown below.
It is also possible to produce the negative bias in the power with the apdl multiplication
of slightly out of phase sin and cos functions as shown below.