Capacitor Charging/Discharging Calculator
Calculate voltage and current during capacitor charging/discharging. RC circuit time constant τ=RC. Exponential curves. Essential for timing circuits, filters, energy storage.
Visualization
Interactive visualization for Capacitor Charging/Discharging Calculator
Time Constant τ: 1.000 s
Capacitor RC:
- • τ = RC
- • V(t) = V₀(1-e^(-t/τ))
Interactive visualization with step-by-step execution
Implementation
1class CapacitorRC {
2 calculateTimeConstant(resistance: number, capacitance: number): number {
3 return resistance * capacitance;
4 }
5
6 chargingVoltage(V0: number, t: number, R: number, C: number): number {
7 const tau = R * C;
8 return V0 * (1 - Math.exp(-t / tau));
9 }
10
11 dischargingVoltage(V0: number, t: number, R: number, C: number): number {
12 const tau = R * C;
13 return V0 * Math.exp(-t / tau);
14 }
15
16 current(V: number, R: number, t: number, C: number): number {
17 const tau = R * C;
18 return (V / R) * Math.exp(-t / tau);
19 }
20
21 storedEnergy(C: number, V: number): number {
22 return 0.5 * C * V * V;
23 }
24
25 timeToVoltage(targetV: number, V0: number, R: number, C: number, charging: boolean): number {
26 const tau = R * C;
27 if (charging) {
28 return -tau * Math.log(1 - targetV / V0);
29 } else {
30 return -tau * Math.log(targetV / V0);
31 }
32 }
33
34 percentCharged(t: number, tau: number): number {
35 return (1 - Math.exp(-t / tau)) * 100;
36 }
37
38 generateChargeCurve(V0: number, R: number, C: number, steps: number): Array<{t: number; V: number; I: number}> {
39 const tau = R * C;
40 const curve: Array<{t: number; V: number; I: number}> = [];
41 const maxTime = 5 * tau;
42
43 for (let i = 0; i <= steps; i++) {
44 const t = (i / steps) * maxTime;
45 const V = this.chargingVoltage(V0, t, R, C);
46 const I = this.current(V0, R, t, C);
47 curve.push({ t, V, I });
48 }
49
50 return curve;
51 }
52}Deep Dive
Theoretical Foundation
Charging: V(t) = V₀(1 - e^(-t/τ)). Discharging: V(t) = V₀×e^(-t/τ). Time constant τ = R×C. After 5τ, considered fully charged/discharged (99%). Current: I(t) = (V₀/R)×e^(-t/τ). Energy: E = 0.5×C×V².
Complexity
Time
O(1) for single point, O(n) for curve
O(1) for single point, O(n) for curve
O(1) for single point, O(n) for curve
Space
O(1) single, O(n) curve
Applications
Industry Use
Timer circuits in microcontrollers
RC oscillators and clock generators
Power supply filtering and smoothing
Audio crossover networks
Camera flash charging circuits
Automotive ignition systems
Delay circuits in digital systems
Energy storage in renewable energy systems
Use Cases
Related Algorithms
GCD (Euclidean Algorithm)
Compute the Greatest Common Divisor (GCD) of two integers using the Euclidean algorithm. Dating back to around 300 BC and appearing in Euclid's Elements, it's one of the oldest algorithms still in common use. The algorithm is based on the principle that GCD(a,b) = GCD(b, a mod b) and is remarkably efficient with O(log min(a,b)) time complexity. The GCD is the largest positive integer that divides both numbers without remainder.
LCM (Least Common Multiple)
Calculate the Least Common Multiple (LCM) of two integers - the smallest positive integer that is divisible by both numbers. The LCM is intimately related to the GCD through the formula: LCM(a,b) = |a×b| / GCD(a,b). This relationship allows us to compute LCM efficiently using the Euclidean algorithm for GCD, achieving O(log min(a,b)) time complexity instead of naive factorization methods.
Sieve of Eratosthenes
Ancient and highly efficient algorithm to find all prime numbers up to a given limit n. Invented by Greek mathematician Eratosthenes of Cyrene (276-194 BC), this sieve method systematically eliminates multiples of primes, leaving only primes in the array. With O(n log log n) time complexity, it remains one of the most practical algorithms for generating large lists of primes, vastly superior to trial division which runs in O(n² / log n) time.
Prime Factorization
Decompose a positive integer into its unique prime factor representation. Every integer greater than 1 can be expressed as a product of prime numbers in exactly one way (Fundamental Theorem of Arithmetic). This algorithm uses trial division optimized to check only up to √n, as any composite number must have a prime factor ≤ √n. Returns a map of prime factors to their powers, e.g., 360 = 2³ × 3² × 5¹.