5
5
"""
6
6
Description
7
7
-----------
8
- when a capacitor is connected with a potential source(AC or DC). It is starts to charge
8
+ When a capacitor is connected with a potential source (AC or DC). It starts to charge
9
9
at a general speed but when a resistor is connected in the circuit with in series to
10
10
a capacitor then the capacitor charges slowly means it will take more time than usual.
11
11
while the capacitor is being charged, the voltage is in exponential function with time.
@@ -26,30 +26,25 @@ def charging_capacitor(
26
26
time_sec : float , # time in seconds after charging initiation of capacitor.
27
27
) -> float :
28
28
"""
29
- find voltage of capacitor at any nth second after the initiation of it's charging.
30
-
31
- Parameters
32
- ----------
33
- source_voltage : float
34
- it is going to multiply with rest of the function.
35
- resistance : float
36
- it is using in RC function.
37
- capacitance : float
38
- it is multiplying with resistance_ohms to yield output.
39
- time_sec : float
40
- it is dividing by RC.To find the voltage at nth second.
29
+ Find capacitor voltage at any nth second after initiating its charging.
41
30
42
31
Examples
43
32
--------
33
+ >>> charging_capacitor(source_voltage=.2,resistance=.9,capacitance=8.4,time_sec=.5)
34
+ 0.013
35
+
36
+ >>> charging_capacitor(source_voltage=2.2,resistance=3.5,capacitance=2.4,time_sec=9)
37
+ 1.446
38
+
44
39
>>> charging_capacitor(source_voltage=15,resistance=200,capacitance=20,time_sec=2)
45
40
0.007
46
41
47
- >>> charging_capacitor(source_voltage=0,resistance=1000 ,capacitance=30,time_sec=3)
42
+ >>> charging_capacitor(source_voltage=0,resistance=10.0 ,capacitance=. 30,time_sec=3)
48
43
Traceback (most recent call last):
49
44
...
50
45
ValueError: source voltage cannot be zero.
51
46
52
- >>> charging_capacitor(20,2000,30*pow(10,-5),4)
47
+ >>> charging_capacitor(20, 2000, 30*pow(10,-5), 4)
53
48
19.975
54
49
55
50
>>> charging_capacitor(source_voltage=20,resistance=-2000,capacitance=30,time_sec=4)
@@ -83,20 +78,28 @@ def charging_capacitor(
83
78
raise ValueError ("source voltage cannot be negative." )
84
79
elif source_voltage == 0 :
85
80
raise ValueError ("source voltage cannot be zero." )
81
+ else :
82
+ return 0
83
+
86
84
elif resistance <= 0 :
87
85
if resistance < 0 :
88
86
raise ValueError ("Resistance cannot be negative." )
89
87
elif resistance == 0 :
90
88
raise ValueError ("Resistance cannot be zero." )
89
+ else :
90
+ return 0
91
+
91
92
elif capacitance <= 0 :
92
93
if capacitance < 0 :
93
94
raise ValueError ("Capacitance cannot be negative." )
94
95
elif capacitance == 0 :
95
96
raise ValueError ("Capacitance cannot be zero." )
97
+ else :
98
+ return 0
99
+
96
100
else :
97
101
return round (
98
- source_voltage * (1 - exp (- time_sec / (resistance * capacitance ))),
99
- 3 ,
102
+ source_voltage * (1 - exp (- time_sec / (resistance * capacitance ))), 3
100
103
)
101
104
102
105
0 commit comments