MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / resonant_frequency

Function resonant_frequency

electronics/resonant_frequency.py:16–44  ·  view source on GitHub ↗

This function can calculate the resonant frequency of LC circuit, for the given value of inductance and capacitnace. Examples are given below: >>> resonant_frequency(inductance=10, capacitance=5) ('Resonant frequency', 0.022507907903927652) >>> resonant_frequency(inductance

(inductance: float, capacitance: float)

Source from the content-addressed store, hash-verified

14
15
16def resonant_frequency(inductance: float, capacitance: float) -> tuple:
17 """
18 This function can calculate the resonant frequency of LC circuit,
19 for the given value of inductance and capacitnace.
20
21 Examples are given below:
22 >>> resonant_frequency(inductance=10, capacitance=5)
23 ('Resonant frequency', 0.022507907903927652)
24 >>> resonant_frequency(inductance=0, capacitance=5)
25 Traceback (most recent call last):
26 ...
27 ValueError: Inductance cannot be 0 or negative
28 >>> resonant_frequency(inductance=10, capacitance=0)
29 Traceback (most recent call last):
30 ...
31 ValueError: Capacitance cannot be 0 or negative
32 """
33
34 if inductance <= 0:
35 raise ValueError("Inductance cannot be 0 or negative")
36
37 elif capacitance <= 0:
38 raise ValueError("Capacitance cannot be 0 or negative")
39
40 else:
41 return (
42 "Resonant frequency",
43 float(1 / (2 * pi * (sqrt(inductance * capacitance)))),
44 )
45
46
47if __name__ == "__main__":

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected