Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def solve(Vin=None, Vout=None, R1=None, R2=None, RL=None):
- """
- Calculation of a voltage divider with load.
- >>> solve(24, 10, 500, RL=390)
- 4239.130434782609
- Reference: http://www.sengpielaudio.com/Rechner-spannungsteiler.htm
- """
- missing = [key for key, value in locals().items() if value is None]
- if len(missing) != 1:
- raise TypeError("One Value must be None")
- missing = missing[0]
- if missing == "Vin":
- return Vout * (R1 * R2 + R1 * RL + R2 * RL) / (R2 * RL)
- elif missing == "Vout":
- return Vin * R2 * RL / (R1 * R2 + R1 * RL + R2 * RL)
- elif missing == "R1":
- return ((Vin - Vout) / Vout) * R2 * RL / (R2 + RL)
- elif missing == "R2":
- return Vout * R1 * RL / (RL * Vin - Vout * R1 - Vout * RL)
- elif missing == "RL":
- return Vout * R1 * R2 / (R2 * Vin - Vout * R1 - Vout * R2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement