Electronics.h Library Documentation

Overview

The Electronics.h library is a C++ header file designed to assist with calculations related to electrical engineering. It provides functions for computing various electrical properties such as voltage, current, and charge, and includes constants and macros for commonly used values in the field.

Constants and Macros

The library defines several constants and macros for use in electrical calculations:

Functions

1. float E_Voltage_v1(float φ2, float φ1)

Description: Calculates the voltage as the difference between two electric potentials.

Parameters:

  • φ2: Electric potential at point 2 (in volts).
  • φ1: Electric potential at point 1 (in volts).

Returns: The voltage (in volts).

float voltage = E_Voltage_v1(10.0, 5.0);
// voltage = 5.0 volts

2. float E_Voltage_v2(float E, float Q)

Description: Calculates the voltage using energy and electric charge.

Parameters:

  • E: Energy in joules (J).
  • Q: Electric charge in coulombs (C).

Returns: The voltage (in volts).

float voltage = E_Voltage_v2(10.0, 2.0);
// voltage = 5.0 volts

3. float Voltage_Series(vector v_series)

Description: Calculates the total voltage in a series circuit.

Parameters:

  • v_series: A vector of voltages in the series circuit (in volts).

Returns: The total voltage (in volts).

vector voltages = {3.0, 4.0, 5.0};
float total_voltage = Voltage_Series(voltages);
// total_voltage = 12.0 volts

4. float Voltage_divider(float vt, float Ri, vector R_vector)

Description: Calculates the voltage across a specific resistor in a series circuit using the voltage divider rule.

Parameters:

  • vt: Total voltage applied to the series circuit (in volts).
  • R_vector: Vector of resistances in the series circuit (in ohms).
  • Ri: Resistance across which the voltage is calculated (in ohms).

Returns: The voltage across the specified resistor (in volts).

vector resistances = {10.0, 20.0, 30.0};
float voltage = Voltage_divider(12.0, resistances, 10.0);
// voltage = 2.0 volts

5. float Voltage_ohm(float i, float r, float Iz, float Z, int circuit)

Description: Calculates the voltage drop using Ohm's Law, depending on whether the circuit is DC or AC.

Parameters:

  • i: Current through the resistor in DC circuit (in amperes).
  • r: Resistance in the DC circuit (in ohms).
  • Iz: Current through the load in AC circuit (in amperes).
  • Z: Impedance in the AC circuit (in ohms).
  • circuit: Type of circuit (DC or AC).

Returns: The voltage drop (in volts).

float voltage = Voltage_ohm(2.0, 6.0, 2.0, 3.0, DC_circuit);
// voltage = 12.0 volts

6. float momentry_Voltage(float MaximalVoltage, float w, float θ, float t)

Description: Calculates the momentary voltage at a specific time in an AC circuit using the sine wave equation.

Parameters:

  • MaximalVoltage: Maximum voltage (amplitude) of the sine wave (in volts).
  • w: Angular frequency (in radians per second).
  • θ: Phase of the sine wave (in radians).
  • t: Time at which the voltage is calculated (in seconds).

Returns: The momentary voltage (in volts).

float voltage = momentry_Voltage(10.0, 50.0, 0.0, 0.02);
// voltage = 10.0 volts

7. float RMS_Voltage(float Vmax)

Description: Calculates the RMS (Root Mean Square) voltage for a sine wave.

Parameters:

  • Vmax: Maximum voltage (amplitude) of the sine wave (in volts).

Returns: The RMS voltage (in volts).

float rms_voltage = RMS_Voltage(10.0);
// rms_voltage = 7.07 volts

8. float VoltageP_P(float Vmax)

Description: Calculates the peak-to-peak voltage for a sine wave.

Parameters:

  • Vmax: Maximum voltage (amplitude) of the sine wave (in volts).

Returns: The peak-to-peak voltage (in volts).

float peak_to_peak_voltage = VoltageP_P(10.0);
// peak_to_peak_voltage = 20.0 volts

9. float Electric_Current(float q, float t)

Description: Calculates the electric current given charge and time.

Parameters:

  • q: Electric charge in coulombs (C).
  • t: Time in seconds (s).

Returns: The electric current (in amperes).

float current = Electric_Current(10.0, 2.0);
            // current = 5.0 amperes

10. float Electric_current_Ohm(float V, float R)

Description: Calculates the current in a circuit using Ohm's Law.

Parameters:

  • V: Voltage across the circuit (in volts).
  • R: The resistance of the circuit (in ohms).

Returns: The current (in amperes).

float current = Electric_current_Ohm(12.0, 6.0);
// current = 2.0 amperes

11. float Current_parallel(vector c_parallel)

Description: Calculates the total current in a parallel circuit.

Parameters:

  • c_parallel: A vector of individual currents in parallel branches (in amperes).

Returns: The total current (in amperes).

vector currents = {1.0, 2.0, 3.0};
            float total_current = Current_parallel(currents);
            // total_current = 6.0 amperes

12. float current_div(float R1, float R2, float R3, float It, float Rt, int type)

Description: Calculates either the equivalent resistance or the current in a specific branch of a current divider circuit.

Parameters:

  • R1: Resistance of the first branch (in ohms).
  • R2: Resistance of the second branch (in ohms).
  • R3: Resistance of the third branch (in ohms).
  • It: Total current entering the parallel circuit (in amperes).
  • Rt: Total equivalent resistance of the parallel branches (in ohms).
  • type: Indicates whether to calculate equivalent resistance (R_t) or current in the first branch (I_1).

Returns: The equivalent resistance (in ohms) or the current in the first branch (in amperes), depending on the type.

float resistance = current_div(10.0, 20.0, 30.0, 5.0, 8.0, R_t);
// resistance = 12.0 ohms

float current = current_div(10.0, 20.0, 30.0, 5.0, 8.0, I_1);
// current = 2.67 amperes

13. float Alterent_Current(float Vz, float Z)

Description: Calculates the alternating current (AC) given voltage and impedance.

Parameters:

  • Vz: Voltage across the impedance (in volts).
  • Z: Impedance (in ohms).

Returns: The alternating current (in amperes).

float AC = Alterent_Current(120.0, 30.0);
// AC = 4.0 amperes

14. float Angular_Frequancy(float frequancy)

Description: Calculates the angular frequency given the frequency of an AC signal.

Parameters:

  • frequancy: Frequency of the AC signal (in hertz).

Returns: The angular frequency (in radians per second).

float w = Angular_Frequancy(50.0);
// w = 314.16 radians per second

15. float Mumentary_currant(float Ipeak, float w, float temp, float θ)

Description: Calculates the instantaneous current in an AC circuit.

Parameters:

  • Ipeak: Peak current (in amperes).
  • w: Angular frequency (in radians per second).
  • temp: Time at which current is calculated (in seconds).
  • θ: Phase angle (in radians).

Returns: The instantaneous current (in amperes).

float i_t = Mumentary_currant(10.0, 314.16, 0.01, 0.0);
// i_t = 9.5 amperes

16. float RMS_current(float Ipeak)

Description: Calculates the RMS (Root Mean Square) current given the peak current.

Parameters:

  • Ipeak: Peak current (in amperes).

Returns: The RMS current (in amperes).

float rms = RMS_current(10.0);
// rms = 7.07 amperes

17. float Ip_p(float Ipeak)

Description: Calculates the peak-to-peak current given the peak current.

Parameters:

  • Ipeak: Peak current (in amperes).

Returns: The peak-to-peak current (in amperes).

float i_pp = Ip_p(10.0);
// i_pp = 20.0 amperes

18. float Resistance(float ρ, float l, float a)

Description: Calculates the electrical resistance of a material given its resistivity, length, and cross-sectional area.

Parameters:

  • ρ: Resistivity of the material (in ohm-meters).
  • l: Length of the material (in meters).
  • a: Cross-sectional area of the material (in square meters).

Returns: The resistance (in ohms).

float r = Resistance(1.68e-8, 2.0, 1e-6);
// r = 0.0336 ohms

19. float Resistance_Ohm(float v, float i)

Description: Calculates the electrical resistance using Ohm's Law.

Parameters:

  • v: Voltage across the resistor (in volts).
  • i: Current flowing through the resistor (in amperes).

Returns: The resistance (in ohms).

float r = Resistance_Ohm(10.0, 2.0);
// r = 5.0 ohms

20. float Temperature_eff(float r1, float α, float T1, float T2)

Description: Calculates the effective resistance at a new temperature.

Parameters:

  • r1: Initial resistance at temperature T1 (in ohms).
  • α: Temperature coefficient of resistance (per degree Celsius).
  • T1: Initial temperature (in degrees Celsius).
  • T2: Final temperature (in degrees Celsius).

Returns: The resistance at temperature T2 (in ohms).

float r2 = Temperature_eff(100.0, 0.004, 20.0, 30.0);
// r2 = 104.0 ohms

21. float Resistance_Series(vector r_series)

Description: Calculates the total resistance in a series circuit.

Parameters:

  • r_series: A vector of resistances in the series circuit (in ohms).

Returns: The total resistance (in ohms).

vector resistances = {10.0, 20.0, 30.0};
float total_resistance = Resistance_Series(resistances);
// total_resistance = 60.0 ohms

22. float Resistance_Parallel(vector r_parallel)

Description: Calculates the total resistance in a parallel circuit.

Parameters:

  • r_parallel: A vector of resistances in the parallel circuit (in ohms).

Returns: The total resistance (in ohms).

vector resistances = {10.0, 20.0, 30.0};
float total_resistance = Resistance_Parallel(resistances);
// total_resistance = 5.45 ohms

23. float power(string i, string r, float angle, int circuit, int type)

Description: Calculates the electrical power in different types of circuits, including AC and DC, based on the provided current, resistance, and phase angle.

Parameters:

  • i: Current as a string with units (e.g., "10amp").
  • r: Resistance as a string with units (e.g., "5ohm").
  • angle: Phase angle in radians (used for AC circuits).
  • circuit: Type of circuit (e.g., AC_circuit_single_phase, DC_circuit, AC_circuit_3_phase).
  • type: For 3-phase circuits, indicates whether it’s line-to-line or line-to-neutral (e.g., line_to_line, line_to_zero).

Returns: The calculated power (in watts). Returns -1 if the input is invalid.

float p = power("10amp", "5ohm", 0.5, AC_circuit_single_phase, 0);
// p = 50.0 watts (assuming valid inputs and no errors)

24. float Power_Real(float Vrms, float Irms, float φ)

Description: Calculates the real power in an AC circuit using the root mean square (RMS) voltage and current, and the phase angle.

Parameters:

  • Vrms: RMS voltage (in volts).
  • Irms: RMS current (in amperes).
  • φ: Phase angle (in radians).

Returns: The real power (in watts).

float real_power = Power_Real(220.0, 5.0, 0.5);
// real_power = 968.9 watts

25. float Reactive_power(float Vrms, float Irms, float φ)

Description: Calculates the reactive power in an AC circuit using the RMS voltage and current, and the phase angle.

Parameters:

  • Vrms: RMS voltage (in volts).
  • Irms: RMS current (in amperes).
  • φ: Phase angle (in radians).

Returns: The reactive power (in VAR, Volt-Ampere Reactive).

float reactive_power = Reactive_power(220.0, 5.0, 0.5);
// reactive_power = 528.5 VAR

26. float Apparent_power(float Vrms, float Irms)

Description: Calculates the apparent power in an AC circuit using the RMS voltage and current.

Parameters:

  • Vrms: RMS voltage (in volts).
  • Irms: RMS current (in amperes).

Returns: The apparent power (in VA, Volt-Amperes).

float apparent_power = Apparent_power(220.0, 5.0);
// apparent_power = 1100.0 VA

27. float relation_real_reactive_apparent(string i, string r)

Description: Calculates the relationship between real, reactive, and apparent power in an AC circuit.

Parameters:

  • i: First power value as a string with units (e.g., "500wat", "300var", "100vam").
  • r: Second power value as a string with units (e.g., "400var", "200wat", "150vam").

Returns: The calculated value based on the relationship between the two power types. Returns -1 if the input is invalid.

float result = relation_real_reactive_apparent("500wat", "300var");
// result = sqrt(500 + 300) = 28.28 (assuming valid inputs and no errors)

28. float electric_charge(string i, string r)

Description: Calculates the electric charge based on the relationship between time, current, and charge.

Parameters:

  • i: First value as a string with units (e.g., "10sec", "5amp", "15cou").
  • r: Second value as a string with units (e.g., "2amp", "3cou", "4sec").

Returns: The calculated electric charge (in coulombs or related units) based on the inputs. Returns -1 if the input is invalid.

float charge = electric_charge("10sec", "5amp");
// charge = 10 / 5 = 2 (assuming valid inputs)

29. float Coulombs_Law(float q1, float q2, float r)

Description: Computes the electrostatic force between two charges using Coulomb's Law.

Parameters:

  • q1: The first charge (in coulombs).
  • q2: The second charge (in coulombs).
  • r: The distance between the charges (in meters).

Returns: The force between the charges (in newtons).

float force = Coulombs_Law(1.6e-19, -1.6e-19, 0.1);
// force = some value in newtons

30. float efficiency(float in, float out)

Description: Calculates the efficiency of a system based on the input and output power.

Parameters:

  • in: Input power to the system (in watts or any consistent unit).
  • out: Output power from the system (in the same unit as input).

Returns: The efficiency of the system as a percentage.

float eff = efficiency(100.0, 80.0);
// eff = 80.0 (which is 80%)

31. float Power_factor(float power_real, float apparent_power)

Description: Calculates the power factor of a system, which is the ratio of real power to apparent power.

Parameters:

  • power_real: Real power in the system (in watts).
  • apparent_power: Apparent power in the system (in volt-amperes).

Returns: The power factor of the system, a dimensionless number between 0 and 1.

float pf = Power_factor(300.0, 400.0);
// pf = 300.0 / 400.0 = 0.75

Namespace: units_conv

This namespace contains functions for converting between different units of voltage, current, resistance, power, capacitance, inductance, conductance, and energy.

Voltage Conversions

Current Conversions

Resistance Conversions