From 921e93f771bb7472251c292dbf573b11245ee541 Mon Sep 17 00:00:00 2001 From: Andrea Piombo Date: Tue, 14 Mar 2023 13:02:18 +0100 Subject: [PATCH] Create resistance.py Calculate the resistance of a circular conductor based on the geometry of the wire and the ambient temperature and return the value --- Electronics_Algorithms/resistance.py | 69 ++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 Electronics_Algorithms/resistance.py diff --git a/Electronics_Algorithms/resistance.py b/Electronics_Algorithms/resistance.py new file mode 100644 index 00000000000..c088732d90c --- /dev/null +++ b/Electronics_Algorithms/resistance.py @@ -0,0 +1,69 @@ +def resistance_calculator(material:str, lenght:float, section:float, temperature:float): + """ + material is a string indicating the material of the wire + + lenght is a floating value indicating the lenght of the wire in meters + + diameter is a floating value indicating the diameter of the wire in millimeters + + temperature is a floating value indicating the temperature at which the wire is operating in °C + + Available materials: + - silver + - copper + - aluminium + - tungsten + - iron + - steel + - zinc + - solder""" + + materials = { + "silver": { + "rho": 0.0163, + "coefficient": 0.0038 + }, + + "copper": { + "rho": 0.0178, + "coefficient": 0.00381 + }, + + "aluminium": { + "rho": 0.0284, + "coefficient": 0.004 + }, + + "tungsten": { + "rho": 0.055, + "coefficient": 0.0045 + }, + + "iron": { + "rho": 0.098, + "coefficient": 0.006 + }, + + "steel": { + "rho": 0.15, + "coefficient": 0.0047 + }, + + "zinc": { + "rho": 0.06, + "coefficient": 0.0037 + }, + + "solder": { + "rho": 0.12, + "coefficient": 0.0043 + } + } + + rho_20deg = materials[material]["rho"] + temp_coefficient = materials[material]["coefficient"] + + rho = rho_20deg * (1 + temp_coefficient * (temperature - 20)) + resistance = rho * lenght / section + + return f"{resistance}Ω"