Similarities between capacitors and batteries