Ohm's Law Calculator
Calculate voltage, current, resistance, and power using Ohm's Law. Fundamental electrical engineering equation. V=IR, P=VI. Essential for circuit analysis.
Visualization
Interactive visualization for Ohm's Law Calculator
Ohm's Law:
- • V = IR
- • I = V/R
Interactive visualization with step-by-step execution
Implementation
1class OhmsLaw {
2 calculateVoltage(current: number, resistance: number): number {
3 return current * resistance;
4 }
5
6 calculateCurrent(voltage: number, resistance: number): number {
7 if (resistance === 0) throw new Error('Resistance cannot be zero');
8 return voltage / resistance;
9 }
10
11 calculateResistance(voltage: number, current: number): number {
12 if (current === 0) throw new Error('Current cannot be zero');
13 return voltage / current;
14 }
15
16 calculatePowerVI(voltage: number, current: number): number {
17 return voltage * current;
18 }
19
20 calculatePowerIR(current: number, resistance: number): number {
21 return current * current * resistance;
22 }
23
24 calculatePowerVR(voltage: number, resistance: number): number {
25 if (resistance === 0) throw new Error('Resistance cannot be zero');
26 return (voltage * voltage) / resistance;
27 }
28
29 // Series resistance
30 calculateSeriesResistance(resistances: number[]): number {
31 return resistances.reduce((sum, r) => sum + r, 0);
32 }
33
34 // Parallel resistance
35 calculateParallelResistance(resistances: number[]): number {
36 const reciprocalSum = resistances.reduce((sum, r) => sum + 1/r, 0);
37 return 1 / reciprocalSum;
38 }
39}Deep Dive
Theoretical Foundation
Ohm's Law: V = I×R (Voltage = Current × Resistance). Power: P = V×I = I²×R = V²/R. Voltage in Volts, Current in Amperes, Resistance in Ohms, Power in Watts. Describes relationship in linear circuits.
Complexity
Time
O(1) for basic, O(n) for series/parallel
O(1) for basic, O(n) for series/parallel
O(1) for basic, O(n) for series/parallel
Space
O(1)
Applications
Industry Use
Electrical circuit design and analysis
Power system calculations
Electronic component selection
Electrical safety and code compliance
Battery life and capacity calculations
Heating element design
LED driver circuits
Electrical troubleshooting and repair
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¹.