Find inductor current at any nth second after initiating its charging. Examples -------- >>> charging_inductor(source_voltage=5.8,resistance=1.5,inductance=2.3,time=2) 2.817 >>> charging_inductor(source_voltage=8,resistance=5,inductance=3,time=2) 1.543 >>> chargin
(
source_voltage: float, # source_voltage should be in volts.
resistance: float, # resistance should be in ohms.
inductance: float, # inductance should be in henrys.
time: float, # time should in seconds.
)
| 30 | |
| 31 | |
| 32 | def charging_inductor( |
| 33 | source_voltage: float, # source_voltage should be in volts. |
| 34 | resistance: float, # resistance should be in ohms. |
| 35 | inductance: float, # inductance should be in henrys. |
| 36 | time: float, # time should in seconds. |
| 37 | ) -> float: |
| 38 | """ |
| 39 | Find inductor current at any nth second after initiating its charging. |
| 40 | |
| 41 | Examples |
| 42 | -------- |
| 43 | >>> charging_inductor(source_voltage=5.8,resistance=1.5,inductance=2.3,time=2) |
| 44 | 2.817 |
| 45 | |
| 46 | >>> charging_inductor(source_voltage=8,resistance=5,inductance=3,time=2) |
| 47 | 1.543 |
| 48 | |
| 49 | >>> charging_inductor(source_voltage=8,resistance=5*pow(10,2),inductance=3,time=2) |
| 50 | 0.016 |
| 51 | |
| 52 | >>> charging_inductor(source_voltage=-8,resistance=100,inductance=15,time=12) |
| 53 | Traceback (most recent call last): |
| 54 | ... |
| 55 | ValueError: Source voltage must be positive. |
| 56 | |
| 57 | >>> charging_inductor(source_voltage=80,resistance=-15,inductance=100,time=5) |
| 58 | Traceback (most recent call last): |
| 59 | ... |
| 60 | ValueError: Resistance must be positive. |
| 61 | |
| 62 | >>> charging_inductor(source_voltage=12,resistance=200,inductance=-20,time=5) |
| 63 | Traceback (most recent call last): |
| 64 | ... |
| 65 | ValueError: Inductance must be positive. |
| 66 | |
| 67 | >>> charging_inductor(source_voltage=0,resistance=200,inductance=20,time=5) |
| 68 | Traceback (most recent call last): |
| 69 | ... |
| 70 | ValueError: Source voltage must be positive. |
| 71 | |
| 72 | >>> charging_inductor(source_voltage=10,resistance=0,inductance=20,time=5) |
| 73 | Traceback (most recent call last): |
| 74 | ... |
| 75 | ValueError: Resistance must be positive. |
| 76 | |
| 77 | >>> charging_inductor(source_voltage=15, resistance=25, inductance=0, time=5) |
| 78 | Traceback (most recent call last): |
| 79 | ... |
| 80 | ValueError: Inductance must be positive. |
| 81 | """ |
| 82 | |
| 83 | if source_voltage <= 0: |
| 84 | raise ValueError("Source voltage must be positive.") |
| 85 | if resistance <= 0: |
| 86 | raise ValueError("Resistance must be positive.") |
| 87 | if inductance <= 0: |
| 88 | raise ValueError("Inductance must be positive.") |
| 89 | return round( |
nothing calls this directly
no outgoing calls
no test coverage detected