engineeringkit.electrical_engineering#
Ohm’s law, series and parallel equivalents, the Wheatstone bridge,
modified nodal analysis and mesh analysis; Thévenin and Norton equivalents
and maximum power transfer; RC and RL transients and the second-order RLC
step; phasors, complex impedance, series resonance and the ideal
transformer; ideal op-amp circuits, the Shockley diode and its load line;
DC machine and induction motor torque-speed curves; lossless and lossy
transmission lines, the distortionless condition, reflection coefficients
and input impedance; real, reactive and three-phase power, the per-unit
system, symmetrical components and fault currents, Gauss-Seidel and
Newton-Raphson load flow, the swing equation and the equal-area criterion
(linear systems by numpy.linalg, the RLC step response by
scipy.signal, roots by scipy.optimize and swing curves by
engineeringkit.integrators).
engineeringkit.electrical_engineering: circuits from Ohm’s law to the digital load flow.
Ohm’s law, series and parallel equivalents, the Wheatstone bridge, modified nodal analysis and mesh analysis of resistive networks; Thévenin, Norton and Jacobi’s maximum power transfer; RC and RL transients and the over-, critically and underdamped RLC step; complex impedance, series resonance and the ideal transformer; ideal op-amp circuits, Shockley’s diode equation and the load line; DC machine and induction motor torque-speed curves; lossless and lossy transmission lines, Heaviside’s distortionless condition, reflections and input impedance for the Smith chart; and real, reactive and three-phase power, the per-unit system, Fortescue’s symmetrical components and fault currents, Gauss-Seidel and Newton-Raphson load flow, and the swing equation with the equal-area criterion. Models are hand-written; NumPy solves the linear systems and SciPy computes the RLC step response, integrals, roots and swing curves.
- class engineeringkit.electrical_engineering.CircuitResult(t, response)[source]#
Bases:
objectTime response of a circuit, from
step_response().- Parameters:
t (ndarray)
response (ndarray)
- response: ndarray#
Loop current at each sample [A].
- Type:
ndarray
- t: ndarray#
Time samples [s].
- Type:
ndarray
- class engineeringkit.electrical_engineering.LoadFlowResult(voltages, power, iterations, converged, history)[source]#
Bases:
objectOutput of
engineeringkit.electrical_engineering.gauss_seidel_load_flow()andengineeringkit.electrical_engineering.newton_raphson_load_flow().All quantities are per unit on the system base.
- Parameters:
voltages (ndarray)
power (ndarray)
iterations (int)
converged (bool)
history (ndarray)
- converged: bool#
Whether the convergence measure in
historyfell below the tolerance.- Type:
bool
- history: ndarray#
Largest voltage update in each Gauss-Seidel sweep, or largest power mismatch before each Newton step.
- Type:
ndarray
- iterations: int#
Gauss-Seidel sweeps or Newton-Raphson steps performed.
- Type:
int
- property losses: complex#
Total network losses, the sum of all bus injections (per unit).
- power: ndarray#
Net complex power injected at each bus, \(S_i = V_i I_i^*\).
- Type:
ndarray of complex
- summary()[source]#
Convergence, smallest voltage magnitude, slack power and losses (per unit).
- Return type:
dict
- voltages: ndarray#
Bus voltages, bus 0 is the slack bus.
- Type:
ndarray of complex
- class engineeringkit.electrical_engineering.MeshResult(mesh_currents, resistor_currents, kvl_residual)[source]#
Bases:
objectOutput of
engineeringkit.electrical_engineering.mesh_analysis().- Parameters:
mesh_currents (ndarray)
resistor_currents (ndarray)
kvl_residual (float)
- kvl_residual: float#
Largest net voltage around any mesh [V]; zero up to rounding.
- Type:
float
- mesh_currents: ndarray#
Clockwise current in each mesh [A], index 0 is mesh 1.
- Type:
ndarray
- resistor_currents: ndarray#
Current in each resistor in the clockwise sense of its first mesh [A].
- Type:
ndarray
- class engineeringkit.electrical_engineering.NodalResult(voltages, resistor_currents, source_currents, kcl_residual)[source]#
Bases:
objectOutput of
engineeringkit.electrical_engineering.nodal_analysis().- Parameters:
voltages (ndarray)
resistor_currents (ndarray)
source_currents (ndarray)
kcl_residual (float)
- kcl_residual: float#
Largest net current leaving any non-ground node [A]; zero up to rounding.
- Type:
float
- resistor_currents: ndarray#
Current in each resistor from its first node to its second [A].
- Type:
ndarray
- source_currents: ndarray#
Current delivered by each voltage source out of its + terminal [A].
- Type:
ndarray
- summary()[source]#
Number of nodes, largest node voltage magnitude [V] and the KCL residual [A].
- Return type:
dict
- voltages: ndarray#
Node voltages [V], index 0 is the ground node (always 0).
- Type:
ndarray
- class engineeringkit.electrical_engineering.SeriesRLC(resistance, inductance, capacitance)[source]#
Bases:
objectSeries RLC circuit driven by a voltage source, with zero initial energy.
- Parameters:
resistance (
float) – Series resistance [ohm], nonnegative (zero gives an undamped ring).inductance (
float) – Series inductance [H], positive.capacitance (
float) – Series capacitance [F], positive.
Notes
Inputs are raw SI numbers with no dimensional metadata; see Electrical engineering: passive components and circuit responses.
- capacitance: float#
Series capacitance [F].
- Type:
float
- impedance(omega)[source]#
Complex impedance of the series circuit; see
series_rlc_impedance().- Parameters:
omega (float or array_like) – Angular frequency [rad/s], positive.
- Returns:
Impedance [ohm].
- Return type:
complex or ndarray
- inductance: float#
Series inductance [H].
- Type:
float
- property quality_factor: float#
Quality factor \(Q = \sqrt{L/C}/R\) [-]; infinite for \(R = 0\).
- resistance: float#
Series resistance [ohm].
- Type:
float
- property resonance_frequency: float#
Undamped resonant frequency \(1/(2\pi\sqrt{LC})\) [Hz].
- class engineeringkit.electrical_engineering.SwingResult(t, delta, speed_deviation, clearing_time, max_stable_angle)[source]#
Bases:
objectOutput of
engineeringkit.electrical_engineering.swing_response().- Parameters:
t (ndarray)
delta (ndarray)
speed_deviation (ndarray)
clearing_time (float)
max_stable_angle (float)
- clearing_time: float#
Time at which the fault is cleared [s].
- Type:
float
- delta: ndarray#
Rotor angle against the infinite bus at each sample [rad].
- Type:
ndarray
- max_stable_angle: float#
Unstable equilibrium \(\pi - \arcsin(P_m/P_{max,post})\) of the post-fault curve [rad].
- Type:
float
- speed_deviation: ndarray#
Rotor speed above synchronous speed at each sample [rad/s, electrical].
- Type:
ndarray
- property stable: bool#
Whether the rotor angle stays below the post-fault unstable equilibrium (first swing).
- summary()[source]#
First-swing stability, largest rotor angle [rad] and clearing time [s].
- Return type:
dict
- t: ndarray#
Time samples [s].
- Type:
ndarray
- engineeringkit.electrical_engineering.admittance_matrix(n_buses, lines)[source]#
Bus admittance matrix \(Y_{bus}\) of a network of \(\pi\)-model lines.
Each line adds its series admittance \(y = 1/z\) to the two diagonal entries and subtracts it from the two off-diagonal ones, and puts half its total shunt admittance on each end.
- Parameters:
n_buses (int) – Number of buses, at least two.
lines (sequence of (int, int, complex) or (int, int, complex, complex)) –
(i, j, z)or(i, j, z, y_shunt): busesiandj(0..n_buses-1), series impedance \(z\) (nonzero) and total line-charging admittance \(y_{shunt}\), all per unit.
- Returns:
\(Y_{bus}\), shape
(n_buses, n_buses), per unit.- Return type:
ndarray of complex
Notes
Inputs are raw SI numbers with no dimensional metadata; see Electrical engineering: passive components and circuit responses.
Examples
>>> admittance_matrix(2, [(0, 1, 0.1j)]).tolist() [[-10j, 10j], [10j, -10j]]
- engineeringkit.electrical_engineering.capacitor_impedance(C, omega)[source]#
Capacitor impedance \(Z_C = 1/(j\omega C)\).
- Parameters:
C (float or array_like) – Capacitance [F], positive.
omega (float or array_like) – Angular frequency [rad/s], positive (an ideal capacitor is an open circuit at DC).
- Returns:
Impedance [ohm], purely negative imaginary.
- Return type:
complex or ndarray of complex
Notes
Inputs are raw SI numbers with no dimensional metadata; see Electrical engineering: passive components and circuit responses.
Examples
>>> complex(capacitor_impedance(1e-3, 1e3)) -1j
- engineeringkit.electrical_engineering.capacitors_parallel(*c)[source]#
Equivalent capacitance of capacitors in parallel, \(C = \sum C_k\).
- Parameters:
*c (float) – Capacitances [F], positive.
- Returns:
Equivalent capacitance [F].
- Return type:
float
Notes
Inputs are raw SI numbers with no dimensional metadata; see Electrical engineering: passive components and circuit responses.
- engineeringkit.electrical_engineering.capacitors_series(*c)[source]#
Equivalent capacitance of capacitors in series, \(1/C = \sum 1/C_k\).
- Parameters:
*c (float) – Capacitances [F], positive.
- Returns:
Equivalent capacitance [F].
- Return type:
float
Notes
Inputs are raw SI numbers with no dimensional metadata; see Electrical engineering: passive components and circuit responses.
- engineeringkit.electrical_engineering.change_base(z_pu, s_old, v_old, s_new, v_new)[source]#
Convert a per-unit impedance to new bases, \(z_{new} = z_{old}(V_{old}/V_{new})^2(S_{new}/S_{old})\).
Nameplate impedances of generators and transformers are given on their own ratings; a network study puts them all on one system base.
- Parameters:
z_pu (complex or array_like) – Impedance on the old bases [pu].
s_old (float or array_like) – Old base power [VA] and base voltage [V], positive.
v_old (float or array_like) – Old base power [VA] and base voltage [V], positive.
s_new (float or array_like) – New base power [VA] and base voltage [V], positive.
v_new (float or array_like) – New base power [VA] and base voltage [V], positive.
- Returns:
Impedance on the new bases [pu].
- Return type:
complex or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Electrical engineering: passive components and circuit responses.
Examples
>>> round(complex(change_base(0.1j, 50e6, 13.8e3, 100e6, 13.8e3)).imag, 6) 0.2
- engineeringkit.electrical_engineering.critical_clearing_time(inertia_constant, p_mech, p_max_pre, frequency=60.0, p_max_post=None)[source]#
Critical clearing time of a bolted fault that drops the electrical power to zero.
With \(P_e = 0\) during the fault the swing equation integrates to \(\delta = \delta_0 + \omega_s P_m t^2/4H\), so the critical clearing angle of
equal_area_clearing_angle()is reached at\[t_{cr} = \sqrt{\frac{4H(\delta_{cr} - \delta_0)}{\omega_s P_m}}, \qquad \omega_s = 2\pi f.\]- Parameters:
inertia_constant (float or array_like) – Inertia constant \(H\) [s] (stored kinetic energy per unit rating), positive.
p_mech (float or array_like) – Mechanical input power [pu], positive.
p_max_pre (float or array_like) – Prefault power-angle amplitude [pu], above
p_mech.frequency (float or array_like, optional) – System frequency [Hz], positive.
p_max_post (float or array_like, optional) – Post-fault amplitude [pu]; defaults to
p_max_pre(the fault is cleared without losing a line).
- Returns:
Critical clearing time [s].
- Return type:
float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Electrical engineering: passive components and circuit responses. For a fault that leaves some power flowing there is no closed form: integrate with
swing_response().Examples
>>> round(float(critical_clearing_time(5.0, 1.0, 2.0)), 4) 0.2142
- engineeringkit.electrical_engineering.dc_motor_speed(v_terminal, armature_resistance, k_phi, torque)[source]#
Speed \(\omega = V/k\Phi - R_a T/(k\Phi)^2\) of a separately excited DC motor; the inverse of
dc_motor_torque().- Parameters:
v_terminal (float or array_like) – Armature terminal voltage [V].
armature_resistance (float or array_like) – Armature resistance [ohm], positive.
k_phi (float or array_like) – Machine constant [V s/rad], positive.
torque (float or array_like) – Load torque [N m].
- Returns:
Shaft speed [rad/s].
- Return type:
float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Electrical engineering: passive components and circuit responses.
Examples
>>> float(dc_motor_speed(240.0, 0.5, 2.0, 160.0)) 100.0
- engineeringkit.electrical_engineering.dc_motor_torque(v_terminal, armature_resistance, k_phi, omega)[source]#
Torque \(T = k\Phi(V - k\Phi\omega)/R_a\) of a separately excited DC machine.
The armature is its back EMF \(E = k\Phi\omega\) behind the armature resistance, so the current is \((V - E)/R_a\) and the torque \(k\Phi I_a\). The torque-speed curve is a straight line from the stall torque \(k\Phi V/R_a\) to the no-load speed \(V/k\Phi\).
- Parameters:
v_terminal (float or array_like) – Armature terminal voltage [V].
armature_resistance (float or array_like) – Armature resistance \(R_a\) [ohm], positive.
k_phi (float or array_like) – Machine constant \(k\Phi\) at the set field current [V s/rad] (equally N m/A), positive.
omega (float or array_like) – Shaft speed [rad/s].
- Returns:
Electromagnetic torque [N m]; negative when the machine runs above its no-load speed and generates.
- Return type:
float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Electrical engineering: passive components and circuit responses. Armature reaction, brush drop and rotational losses are neglected.
References
J. Hopkinson and E. Hopkinson, “Dynamo-electric machinery,” Phil. Trans. R. Soc. 177 (1886) 331.
Examples
>>> float(dc_motor_torque(240.0, 0.5, 2.0, 100.0)) 160.0
- engineeringkit.electrical_engineering.diode_operating_point(v_source, resistance, saturation_current, ideality=1.0, temperature=300.0)[source]#
Operating point of a diode in series with a resistor: the load-line solution.
The resistor fixes the load line \(i = (V_s - v)/R\), and the operating point is where it crosses the diode curve of
shockley_diode_current(). The crossing is found by bracketed root finding (Brent’s method), on the current for forward bias, where the diode voltage \(nV_T\ln(1 + i/I_S)\) stays bounded, and on the voltage for reverse bias.- Parameters:
v_source (float) – Source voltage driving the anode through the resistor [V].
resistance (float) – Series resistance [ohm], positive.
saturation_current (float) – Reverse saturation current [A], positive.
ideality (float, optional) – Ideality factor [-], positive.
temperature (float, optional) – Junction temperature [K], positive.
- Returns:
(v_diode, i_diode): diode voltage [V] and current [A].- Return type:
tuple of float
Notes
Inputs are raw SI numbers with no dimensional metadata; see Electrical engineering: passive components and circuit responses. All parameters are scalar-only: each operating point is one root find.
Examples
>>> v, i = diode_operating_point(5.0, 1e3, 1e-14) >>> round(v, 4), round(i * 1e3, 4) (0.6925, 4.3075)
- engineeringkit.electrical_engineering.distortionless_condition(R_per_m, L_per_m, G_per_m, C_per_m, rtol=1e-09)[source]#
Whether a line meets Heaviside’s distortionless condition \(R/L = G/C\).
On such a line the attenuation \(\alpha = \sqrt{RG}\) and the velocity \(1/\sqrt{LC}\) are the same at every frequency, so a pulse shrinks without changing shape.
- Parameters:
R_per_m (float) – Series resistance per unit length [ohm/m], nonnegative.
L_per_m (float) – Series inductance per unit length [H/m], positive.
G_per_m (float) – Shunt conductance per unit length [S/m], nonnegative.
C_per_m (float) – Shunt capacitance per unit length [F/m], positive.
rtol (float, optional) – Relative tolerance on \(RC = GL\) [-], nonnegative.
- Returns:
Trueif the line is distortionless.- Return type:
bool
Notes
Inputs are raw SI numbers with no dimensional metadata; see Electrical engineering: passive components and circuit responses.
References
O. Heaviside, “Electromagnetic induction and its propagation,” The Electrician (1887); reprinted in Electrical Papers, vol. 2 (London: Macmillan, 1892).
Examples
>>> distortionless_condition(0.01, 1e-6, 1e-8, 1e-12) True
- engineeringkit.electrical_engineering.equal_area_clearing_angle(p_mech, p_max_pre, p_max_fault, p_max_post)[source]#
Initial and critical clearing rotor angles by the equal-area criterion.
The rotor starts at \(\delta_0 = \arcsin(P_m/P_1)\) on the prefault curve, accelerates along the fault curve \(P_2\sin\delta\) and, once cleared, decelerates along \(P_3\sin\delta\) until at most \(\delta_{max} = \pi - \arcsin(P_m/P_3)\). Equating the accelerating and decelerating areas,
\[\cos\delta_{cr} = \frac{P_m(\delta_{max} - \delta_0) + P_3\cos\delta_{max} - P_2\cos\delta_0}{P_3 - P_2}.\]- Parameters:
p_mech (float or array_like) – Mechanical input power \(P_m\) [pu], positive.
p_max_pre (float or array_like) – Amplitudes \(P_1, P_2, P_3\) of the prefault, fault-on and post-fault power-angle curves [pu]; \(P_1, P_3 > P_m\) and \(0 \le P_2 < P_3\).
p_max_fault (float or array_like) – Amplitudes \(P_1, P_2, P_3\) of the prefault, fault-on and post-fault power-angle curves [pu]; \(P_1, P_3 > P_m\) and \(0 \le P_2 < P_3\).
p_max_post (float or array_like) – Amplitudes \(P_1, P_2, P_3\) of the prefault, fault-on and post-fault power-angle curves [pu]; \(P_1, P_3 > P_m\) and \(0 \le P_2 < P_3\).
- Returns:
(delta0, delta_critical)[rad]. If the fault-on curve keeps the rotor from passing \(\delta_{max}\) whenever it is cleared,delta_criticalis \(\delta_{max}\).- Return type:
tuple of float or ndarray
- Raises:
ValueError – For inconsistent powers, or if the post-fault system cannot hold the rotor even when the fault is cleared at once.
Notes
Inputs are raw SI numbers with no dimensional metadata; see Electrical engineering: passive components and circuit responses. Classical model: constant voltage behind transient reactance, constant mechanical power, no damping, one machine against an infinite bus.
References
R. D. Evans and C. F. Wagner, “Studies of transmission stability,” Trans. AIEE 45 (1926); E. W. Kimbark, Power System Stability, vol. 1 (New York: Wiley, 1948), ch. 4.
Examples
>>> d0, dcr = equal_area_clearing_angle(1.0, 2.0, 0.0, 2.0) >>> round(float(np.degrees(d0)), 2), round(float(np.degrees(dcr)), 2) (30.0, 79.56)
- engineeringkit.electrical_engineering.fault_currents(e_prefault, z1, z2, z0, kind='slg', z_fault=0.0)[source]#
Phase fault currents at a bus from its sequence impedances.
The fault’s boundary conditions connect the Thévenin sequence networks seen from the faulted bus (phase a is the reference phase; a line-to-line fault is between phases b and c):
"3ph", balanced three-phase: \(I_1 = E/(Z_1 + Z_f)\), \(I_0 = I_2 = 0\);"slg", single line (a) to ground: the three networks in series, \(I_0 = I_1 = I_2 = E/(Z_0 + Z_1 + Z_2 + 3Z_f)\);"ll", line to line: positive and negative networks in parallel opposition, \(I_1 = -I_2 = E/(Z_1 + Z_2 + Z_f)\), \(I_0 = 0\);"llg", double line to ground: the negative network in parallel with the zero network plus \(3Z_f\).
The phase currents then follow from
phase_components().- Parameters:
e_prefault (complex or array_like) – Prefault (Thévenin) voltage at the bus [pu or V], nonzero.
z1 (complex or array_like) – Positive-, negative- and zero-sequence Thévenin impedances at the bus [pu or ohm].
z2 (complex or array_like) – Positive-, negative- and zero-sequence Thévenin impedances at the bus [pu or ohm].
z0 (complex or array_like) – Positive-, negative- and zero-sequence Thévenin impedances at the bus [pu or ohm].
kind ({"slg", "ll", "llg", "3ph"}, optional) – Fault type.
z_fault (complex or array_like, optional) – Fault impedance [pu or ohm] (to ground for
"slg"and"llg", between the faulted lines for"ll", per phase for"3ph").
- Returns:
(Ia, Ib, Ic), phase currents into the fault [pu or A].- Return type:
tuple of complex or ndarray
- Raises:
ValueError – For an unknown
kindor a fault path of zero total impedance.
Notes
Inputs are raw SI numbers with no dimensional metadata; see Electrical engineering: passive components and circuit responses. Use one consistent unit system (per unit, or volts and ohms) for all inputs. Load current before the fault is neglected.
References
C. L. Fortescue, “Method of symmetrical co-ordinates applied to the solution of polyphase networks,” Trans. AIEE 37 (1918) 1027-1140; J. D. Glover, T. J. Overbye and M. S. Sarma, Power System Analysis and Design, 6th ed. (Boston: Cengage, 2017), ch. 7 and 9.
Examples
>>> ia, ib, ic = fault_currents(1.0, 0.2j, 0.2j, 0.1j) >>> round(abs(ia), 4), round(abs(ib), 12) (6.0, 0.0)
- engineeringkit.electrical_engineering.gauss_seidel_load_flow(Y, p_load, q_load, v_slack=1.0, tol=1e-08, max_iter=500, acceleration=1.0)[source]#
Gauss-Seidel load flow for a slack bus and PQ buses.
Bus 0 is the slack bus with fixed voltage. At every other bus the net injected complex power \(S_i = P_i + jQ_i\) is specified, and each sweep updates the bus voltages in turn,
\[V_i \leftarrow \frac{1}{Y_{ii}}\left(\frac{S_i^*}{V_i^*} - \sum_{k \ne i} Y_{ik} V_k\right),\]using the newest value of every \(V_k\).
- Parameters:
Y (array_like of complex) – Bus admittance matrix [pu], square, at least 2x2, nonzero diagonal; see
admittance_matrix().p_load (array_like) – Real [pu] and reactive [pu] power consumed at buses
1..n-1(lengthn - 1); negative values are generation.q_load (array_like) – Real [pu] and reactive [pu] power consumed at buses
1..n-1(lengthn - 1); negative values are generation.v_slack (complex, optional) – Slack-bus voltage [pu], nonzero.
tol (float, optional) – Stop when the largest voltage update is below this [pu], positive.
max_iter (int, optional) – Maximum number of sweeps, at least one.
acceleration (float, optional) – Over-relaxation factor [-] in \((0, 2)\); 1.4 to 1.6 is typical, 1 is plain Gauss-Seidel.
- Returns:
Bus voltages, injected powers (bus 0 gives the slack power), sweep count, a convergence flag and the update history. No exception is raised on non-convergence; check
converged.- Return type:
Notes
Inputs are raw SI numbers with no dimensional metadata; see Electrical engineering: passive components and circuit responses. PV (voltage-controlled) buses are not modelled.
References
J. B. Ward and H. W. Hale, “Digital computer solution of power-flow problems,” Trans. AIEE Part III 75 (1956) 398-404.
Examples
>>> Y = admittance_matrix(2, [(0, 1, 0.1j)]) >>> r = gauss_seidel_load_flow(Y, [0.5], [0.0]) >>> r.converged, round(float(abs(r.voltages[1])), 4) (True, 0.9987)
- engineeringkit.electrical_engineering.induction_motor_breakdown(v_phase, synchronous_speed, r1, x1, r2, x2, xm, phases=3)[source]#
Slip and torque at the breakdown (pull-out) point of an induction motor.
Torque is greatest when the rotor resistance \(R_2/s\) matches the impedance in front of it, at
\[s_{max} = \frac{R_2}{\sqrt{R_{th}^2 + (X_{th} + X_2)^2}},\qquad T_{max} = \frac{m V_{th}^2}{2\omega_s\left[R_{th} + \sqrt{R_{th}^2 + (X_{th} + X_2)^2}\right]},\]so the breakdown torque does not depend on \(R_2\), only where it occurs.
- Parameters:
v_phase (float or array_like) – RMS phase voltage [V], nonnegative.
synchronous_speed (float or array_like) – Synchronous shaft speed [rad/s], positive.
r1 (float or array_like) – Equivalent-circuit parameters [ohm]; see
induction_motor_torque().x1 (float or array_like) – Equivalent-circuit parameters [ohm]; see
induction_motor_torque().r2 (float or array_like) – Equivalent-circuit parameters [ohm]; see
induction_motor_torque().x2 (float or array_like) – Equivalent-circuit parameters [ohm]; see
induction_motor_torque().xm (float or array_like) – Equivalent-circuit parameters [ohm]; see
induction_motor_torque().phases (int, optional) – Number of phases, at least one.
- Returns:
(slip_max, torque_max): slip [-] and torque [N m] at breakdown.- Return type:
tuple of float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Electrical engineering: passive components and circuit responses.
Examples
>>> s, T = induction_motor_breakdown(230.0, 2 * np.pi * 25, 0.3, 0.6, 0.25, 0.6, 20.0) >>> round(float(s), 4), round(float(T), 1) (0.2049, 316.8)
- engineeringkit.electrical_engineering.induction_motor_torque(v_phase, slip, synchronous_speed, r1, x1, r2, x2, xm, phases=3)[source]#
Torque of an induction motor from Steinmetz’s per-phase equivalent circuit.
Replacing the stator impedance and magnetizing reactance by their Thévenin equivalent \(V_{th}, R_{th} + jX_{th}\) seen from the rotor,
\[T = \frac{m V_{th}^2\, R_2/s}{\omega_s\left[(R_{th} + R_2/s)^2 + (X_{th} + X_2)^2\right]},\]computed in the equivalent form multiplied through by \(s^2\) so that \(s = 0\) gives zero torque.
- Parameters:
v_phase (float or array_like) – RMS phase voltage at the stator [V], nonnegative.
slip (float or array_like) – Slip \(s = (\omega_s - \omega)/\omega_s\) [-]: 0 at synchronous speed, 1 at standstill, negative when generating and above 1 when plugging.
synchronous_speed (float or array_like) – Synchronous shaft speed \(\omega_s\) [rad/s], positive.
r1 (float or array_like) – Stator resistance [ohm] (nonnegative) and leakage reactance [ohm] (positive).
x1 (float or array_like) – Stator resistance [ohm] (nonnegative) and leakage reactance [ohm] (positive).
r2 (float or array_like) – Rotor resistance and leakage reactance referred to the stator [ohm], positive.
x2 (float or array_like) – Rotor resistance and leakage reactance referred to the stator [ohm], positive.
xm (float or array_like) – Magnetizing reactance [ohm], positive.
phases (int, optional) – Number of phases \(m\), at least one.
- Returns:
Electromagnetic torque [N m].
- Return type:
float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Electrical engineering: passive components and circuit responses. Core loss is neglected (no shunt resistance) and the parameters are constant: deep-bar and double-cage rotors, whose \(R_2\) rises with slip, are not modelled.
References
C. P. Steinmetz, “The alternating current induction motor,” Trans. AIEE 14 (1897) 183-217.
Examples
>>> round(float(induction_motor_torque(230.0, 0.03, 2 * np.pi * 25, 0.3, 0.6, 0.25, 0.6, 20.0)), 1) 104.9
- engineeringkit.electrical_engineering.inductor_impedance(L, omega)[source]#
Inductor impedance \(Z_L = j\omega L\).
- Parameters:
L (float or array_like) – Inductance [H], positive.
omega (float or array_like) – Angular frequency [rad/s], nonnegative.
- Returns:
Impedance [ohm], purely positive imaginary.
- Return type:
complex or ndarray of complex
Notes
Inputs are raw SI numbers with no dimensional metadata; see Electrical engineering: passive components and circuit responses.
Examples
>>> complex(inductor_impedance(1e-3, 1e3)) 1j
- engineeringkit.electrical_engineering.input_impedance(z_load, z0, electrical_length)[source]#
Input impedance of a lossless line of electrical length \(\beta\ell\) ending in \(Z_L\).
The reflection coefficient rotates clockwise around the Smith chart, \(\Gamma_{in} = \Gamma_L e^{-2j\beta\ell}\), and the impedance is \(Z_{in} = Z_0(1 + \Gamma_{in})/(1 - \Gamma_{in})\), equivalent to \(Z_0 (Z_L + jZ_0\tan\beta\ell)/(Z_0 + jZ_L\tan\beta\ell)\).
- Parameters:
z_load (complex or array_like) – Load impedance [ohm], finite with nonnegative real part.
z0 (float) – Characteristic impedance [ohm], positive.
electrical_length (float or array_like) – \(\beta\ell = 2\pi\ell/\lambda\) [rad], nonnegative.
- Returns:
Input impedance [ohm]; very large where the line transforms the load into an open circuit.
- Return type:
complex or ndarray of complex
Notes
Inputs are raw SI numbers with no dimensional metadata; see Electrical engineering: passive components and circuit responses.
References
P. H. Smith, “Transmission line calculator,” Electronics 12 (January 1939) 29-31.
Examples
>>> round(float(abs(input_impedance(100.0, 50.0, np.pi / 2))), 9) 25.0
- engineeringkit.electrical_engineering.inverting_amplifier_gain(r_feedback, r_input)[source]#
Voltage gain \(v_o/v_i = -R_f/R_{in}\) of an ideal inverting amplifier.
The ideal op amp draws no input current and, with negative feedback, holds its inverting input at the grounded non-inverting one (a virtual ground), so the input current \(v_i/R_{in}\) all flows through \(R_f\).
- Parameters:
r_feedback (float or array_like) – Feedback resistance \(R_f\) [ohm], positive.
r_input (float or array_like) – Input resistance \(R_{in}\) [ohm], positive.
- Returns:
Voltage gain [-], negative.
- Return type:
float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Electrical engineering: passive components and circuit responses.
References
J. R. Ragazzini, R. H. Randall and F. A. Russell, “Analysis of problems in dynamics by electronic circuits,” Proc. IRE 35 (1947) 444-452.
Examples
>>> inverting_amplifier_gain(10e3, 1e3) -10.0
- engineeringkit.electrical_engineering.maximum_power_transfer(vth, rth)[source]#
Matched load \(R_L = R_{th}\) and the power \(V_{th}^2/4R_{th}\) it receives.
- Parameters:
vth (float) – Thévenin (open-circuit) voltage [V].
rth (float) – Thévenin resistance [ohm], positive.
- Returns:
(R_L [ohm], P_max [W]). At the match the efficiency is 50%.- Return type:
tuple of float
Notes
Inputs are raw SI numbers with no dimensional metadata; see Electrical engineering: passive components and circuit responses.
Examples
>>> maximum_power_transfer(12.0, 6.0) (6.0, 6.0)
- engineeringkit.electrical_engineering.mesh_analysis(n_meshes, resistors, voltage_sources=())[source]#
Solve a planar resistive DC network by mesh analysis.
Each mesh (window) of the planar circuit carries a clockwise mesh current. Kirchhoff’s voltage law around every mesh, with Ohm’s law for every resistor, gives the resistance system \(R\mathbf{i} = \mathbf{v}\): \(R_{kk}\) is the total resistance around mesh \(k\), \(R_{kl}\) minus the resistance mesh \(k\) shares with mesh \(l\), and \(v_k\) the sum of the source EMFs driving clockwise around mesh \(k\). It is the dual of
nodal_analysis().- Parameters:
n_meshes (int) – Number of meshes, at least one. Meshes are numbered
1..n_meshes;0stands for the outside of the circuit.resistors (sequence of (int, int, float)) –
(a, b, R)for each resistor on the boundary between meshesaandb(b = 0for an outer branch), with \(R\) [ohm] positive.voltage_sources (sequence of (int, int, float), optional) –
(a, b, V): an ideal source on the boundary between meshesaandbwhose EMF \(V\) [V] drives current clockwise around mesha(and so anticlockwise around meshb).
- Returns:
Mesh currents [A], resistor currents in the clockwise sense of their first mesh [A] and the KVL residual [V].
- Return type:
- Raises:
ValueError – For bad mesh indices or values, or if the network has no unique solution (a mesh with no resistance).
Notes
Inputs are raw SI numbers with no dimensional metadata; see Electrical engineering: passive components and circuit responses. Current sources are not accepted: replace one by its Thévenin equivalent, or use
nodal_analysis().References
W. H. Hayt, J. E. Kemmerly and S. M. Durbin, Engineering Circuit Analysis, 8th ed. (New York: McGraw-Hill, 2012), ch. 4.
Examples
>>> r = mesh_analysis(2, [(1, 0, 2.0), (1, 2, 4.0), (2, 0, 4.0)], voltage_sources=[(1, 0, 12.0)]) >>> [round(float(i), 6) for i in r.mesh_currents] [3.0, 1.5]
- engineeringkit.electrical_engineering.newton_raphson_load_flow(Y, p_load, q_load, v_slack=1.0, pv_buses=None, tol=1e-08, max_iter=20)[source]#
Newton-Raphson load flow in polar coordinates, with PQ and PV buses.
Bus 0 is the slack bus. A PV (generator) bus has its real power and voltage magnitude specified; a PQ (load) bus its real and reactive power. The unknowns are the angles \(\theta\) of every non-slack bus and the magnitudes \(|V|\) of the PQ buses. Each step solves
\[\begin{split}\begin{bmatrix}\partial P/\partial\theta & \partial P/\partial|V|\\ \partial Q/\partial\theta & \partial Q/\partial|V|\end{bmatrix} \begin{bmatrix}\Delta\theta\\ \Delta|V|\end{bmatrix} = \begin{bmatrix}\Delta P\\ \Delta Q\end{bmatrix}\end{split}\]for the correction, where the mismatches are the specified minus the computed injections \(S_i = V_i(\sum_k Y_{ik}V_k)^*\). Near the solution the mismatch is squared at every step.
- Parameters:
Y (array_like of complex) – Bus admittance matrix [pu], square, at least 2x2; see
admittance_matrix().p_load (array_like) – Real [pu] and reactive [pu] power consumed at buses
1..n-1(lengthn - 1); negative values are generation.q_loadis ignored at PV buses, whose reactive power is an output.q_load (array_like) – Real [pu] and reactive [pu] power consumed at buses
1..n-1(lengthn - 1); negative values are generation.q_loadis ignored at PV buses, whose reactive power is an output.v_slack (complex, optional) – Slack-bus voltage [pu], nonzero.
pv_buses (mapping of int to float, optional) –
{bus: |V|}, the voltage-magnitude setpoint [pu] (positive) of each PV bus,busin1..n-1.tol (float, optional) – Stop when the largest power mismatch is below this [pu], positive.
max_iter (int, optional) – Maximum number of Newton steps, at least one.
- Returns:
Bus voltages, injected powers (bus 0 gives the slack power; PV buses their reactive output), step count, a convergence flag and the largest mismatch before each step. No exception is raised on non-convergence; check
converged.- Return type:
Notes
Inputs are raw SI numbers with no dimensional metadata; see Electrical engineering: passive components and circuit responses. The Jacobian is dense here; Tinney and Hart’s contribution was to keep it sparse by optimal ordering. Generator reactive limits (PV-to-PQ switching) are not modelled.
References
W. F. Tinney and C. E. Hart, “Power flow solution by Newton’s method,” IEEE Trans. Power App. Syst. PAS-86 (1967) 1449-1460.
Examples
>>> Y = admittance_matrix(2, [(0, 1, 0.1j)]) >>> r = newton_raphson_load_flow(Y, [0.5], [0.0]) >>> r.converged, round(float(abs(r.voltages[1])), 4) (True, 0.9987)
- engineeringkit.electrical_engineering.nodal_analysis(n_nodes, resistors, current_sources=(), voltage_sources=())[source]#
Solve a resistive DC network by modified nodal analysis.
Kirchhoff’s current law at each non-ground node, with Ohm’s law for every resistor, gives the conductance system \(G\mathbf{v} = \mathbf{i}\). Each ideal voltage source adds one unknown (its current) and one equation (its terminal voltage), the modified nodal system.
- Parameters:
n_nodes (int) – Number of non-ground nodes, at least one. Nodes are numbered
1..n_nodes; node0is ground.resistors (sequence of (int, int, float)) –
(a, b, R)for each resistor between nodesaandb, with \(R\) [ohm] positive.current_sources (sequence of (int, int, float), optional) –
(a, b, I): a source driving current \(I\) [A] from nodeathrough itself into nodeb.voltage_sources (sequence of (int, int, float), optional) –
(plus, minus, V): an ideal source holding \(v_{plus} - v_{minus} = V\) [V].
- Returns:
Node voltages [V] (ground first), resistor currents from
atob[A], voltage-source currents out of the+terminal [A] and the KCL residual [A].- Return type:
- Raises:
ValueError – For bad node indices or values, or if the network has no unique solution (a floating node or a loop of voltage sources).
Notes
Inputs are raw SI numbers with no dimensional metadata; see Electrical engineering: passive components and circuit responses.
References
G. Kirchhoff, “Ueber den Durchgang eines elektrischen Stromes durch eine Ebene, insbesondere durch eine kreisförmige,” Ann. Phys. 64 (1845) 497-514; C.-W. Ho, A. E. Ruehli and P. A. Brennan, “The modified nodal approach to network analysis,” IEEE Trans. Circuits Syst. 22 (1975) 504-509.
Examples
>>> r = nodal_analysis(2, [(1, 2, 1e3), (2, 0, 1e3)], voltage_sources=[(1, 0, 10.0)]) >>> [round(float(v), 6) for v in r.voltages] [0.0, 10.0, 5.0]
- engineeringkit.electrical_engineering.noninverting_amplifier_gain(r_feedback, r_ground)[source]#
Voltage gain \(v_o/v_i = 1 + R_f/R_g\) of an ideal non-inverting amplifier.
- Parameters:
r_feedback (float or array_like) – Feedback resistance \(R_f\) from the output to the inverting input [ohm], nonnegative (zero gives the unity-gain follower).
r_ground (float or array_like) – Resistance \(R_g\) from the inverting input to ground [ohm], positive.
- Returns:
Voltage gain [-], at least one.
- Return type:
float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Electrical engineering: passive components and circuit responses.
Examples
>>> noninverting_amplifier_gain(9e3, 1e3) 10.0
- engineeringkit.electrical_engineering.norton_from_thevenin(vth, rth)[source]#
Norton equivalent \(I_N = V_{th}/R_{th}\) in parallel with \(R_{th}\).
- Parameters:
vth (float) – Thévenin (open-circuit) voltage [V].
rth (float) – Thévenin resistance [ohm], positive (an ideal voltage source has no Norton form).
- Returns:
(I_N [A], R_N [ohm]); \(I_N\) is the short-circuit current.- Return type:
tuple of float
Notes
Inputs are raw SI numbers with no dimensional metadata; see Electrical engineering: passive components and circuit responses.
References
E. L. Norton, “Design of finite networks for uniform frequency characteristic,” Bell Laboratories Technical Report TM26-0-1860 (1926).
Examples
>>> norton_from_thevenin(10, 5) (2.0, 5)
- engineeringkit.electrical_engineering.ohms_law(voltage=None, current=None, resistance=None)[source]#
Solve \(V = IR\) for whichever of the three quantities is omitted.
- Parameters:
voltage (float, optional) – Voltage across the resistor [V].
current (float, optional) – Current through the resistor [A].
resistance (float, optional) – Resistance [ohm], positive when given.
- Returns:
The missing voltage [V], current [A] or resistance [ohm].
- Return type:
float
- Raises:
ValueError – Unless exactly two quantities are given, or if a resistance would be inferred from zero current or comes out negative.
Notes
Inputs are raw SI numbers with no dimensional metadata; see Electrical engineering: passive components and circuit responses.
References
G. S. Ohm, Die galvanische Kette, mathematisch bearbeitet (Berlin: T. H. Riemann, 1827).
Examples
>>> ohms_law(voltage=12.0, resistance=4.0) 3.0
- engineeringkit.electrical_engineering.op_amp_integrator(v_in, t, R, C, v0=0.0)[source]#
Output \(v_o(t) = v_0 - \frac{1}{RC}\int_0^t v_i\,dt'\) of an ideal inverting integrator.
The virtual ground makes the input current \(v_i/R\), and it can only go into the feedback capacitor. The integral of the sampled input is taken by the trapezoidal rule.
- Parameters:
v_in (array_like) – Input voltage at each sample [V].
t (array_like) – Sample times [s], strictly increasing, same length as
v_in(at least two).R (float) – Input resistance [ohm], positive.
C (float) – Feedback capacitance [F], positive.
v0 (float, optional) – Output voltage at
t[0][V].
- Returns:
Output voltage [V] at each sample.
- Return type:
ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Electrical engineering: passive components and circuit responses. A real integrator saturates at its supply rails and drifts on its input offset; neither is modelled.
References
J. R. Ragazzini, R. H. Randall and F. A. Russell, “Analysis of problems in dynamics by electronic circuits,” Proc. IRE 35 (1947) 444-452.
Examples
>>> t = np.linspace(0, 1e-3, 11) >>> round(float(op_amp_integrator(np.ones(11), t, 1e3, 1e-6)[-1]), 6) -1.0
- engineeringkit.electrical_engineering.parallel_resistance(*r)[source]#
Equivalent resistance of resistors in parallel, \(1/R = \sum 1/R_k\).
- Parameters:
*r (float) – Resistances [ohm], positive (model a short circuit separately).
- Returns:
Equivalent resistance [ohm].
- Return type:
float
Notes
Inputs are raw SI numbers with no dimensional metadata; see Electrical engineering: passive components and circuit responses.
Examples
>>> parallel_resistance(100.0, 100.0) 50.0
- engineeringkit.electrical_engineering.per_unit_base(s_base, v_base, phases=3)[source]#
Base impedance and base current of a per-unit system.
Choosing a base power and a base voltage fixes the other two bases. For a three-phase system with three-phase base power \(S_b\) and line-to-line base voltage \(V_b\), \(Z_b = V_b^2/S_b\) and \(I_b = S_b/\sqrt3 V_b\); for a single-phase system \(Z_b = V_b^2/S_b\) and \(I_b = S_b/V_b\). A quantity in per unit is its value divided by its base.
- Parameters:
s_base (float or array_like) – Base apparent power [VA], three-phase total when
phases=3, positive.v_base (float or array_like) – Base voltage [V], line-to-line when
phases=3, positive.phases ({1, 3}, optional) – Single-phase or three-phase bases.
- Returns:
(z_base, i_base): base impedance [ohm] and base current [A].- Return type:
tuple of float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Electrical engineering: passive components and circuit responses. Choosing base voltages in the turns ratio of every transformer makes the ideal transformers vanish from the per-unit network.
References
J. D. Glover, T. J. Overbye and M. S. Sarma, Power System Analysis and Design, 6th ed. (Boston: Cengage, 2017), sec. 3.3.
Examples
>>> z, i = per_unit_base(100e6, 138e3) >>> round(float(z), 2), round(float(i), 1) (190.44, 418.4)
- engineeringkit.electrical_engineering.phase_components(v0, v1, v2)[source]#
Phase phasors \((V_a, V_b, V_c)\) from symmetrical components; the inverse of
symmetrical_components().- Parameters:
v0 (complex or array_like) – Zero-, positive- and negative-sequence components [V or A].
v1 (complex or array_like) – Zero-, positive- and negative-sequence components [V or A].
v2 (complex or array_like) – Zero-, positive- and negative-sequence components [V or A].
- Returns:
(Va, Vb, Vc), same units as the input.- Return type:
tuple of complex or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Electrical engineering: passive components and circuit responses.
Examples
>>> [round(abs(x), 12) for x in phase_components(0, 1, 0)] [1.0, 1.0, 1.0]
- engineeringkit.electrical_engineering.phasor(magnitude, phase)[source]#
Complex phasor \(A e^{j\phi}\) from a magnitude and a phase.
- Parameters:
magnitude (float or array_like) – Amplitude or RMS value [V, A or other], nonnegative.
phase (float or array_like) – Phase angle [rad].
- Returns:
Phasor in rectangular form, same units as
magnitude.- Return type:
complex or ndarray of complex
Notes
Inputs are raw SI numbers with no dimensional metadata; see Electrical engineering: passive components and circuit responses.
Examples
>>> complex(np.round(phasor(2.0, np.pi / 2), 12)) 2j
- engineeringkit.electrical_engineering.polar(z)[source]#
Magnitude and phase of a phasor, the inverse of
phasor().- Parameters:
z (complex or array_like) – Phasor [V, A, ohm or other].
- Returns:
magnitude (float or ndarray) – \(|z|\), same units as
z.phase (float or ndarray) – \(\arg z\) in \((-\pi, \pi]\) [rad].
Notes
Inputs are raw SI numbers with no dimensional metadata; see Electrical engineering: passive components and circuit responses.
Examples
>>> polar(1j) (1.0, 1.5707963267948966)
- engineeringkit.electrical_engineering.power_factor(real_power_value, apparent_power)[source]#
Power factor \(P/S\).
- Parameters:
real_power_value (float) – Real power [W], with \(|P| \le S\).
apparent_power (float) – Apparent power \(S = V_{rms} I_{rms}\) [VA], positive.
- Returns:
Power factor [-], in \([-1, 1]\).
- Return type:
float
Notes
Inputs are raw SI numbers with no dimensional metadata; see Electrical engineering: passive components and circuit responses.
Examples
>>> power_factor(8.0, 10.0) 0.8
- engineeringkit.electrical_engineering.propagation_constant(R_per_m, L_per_m, G_per_m, C_per_m, omega)[source]#
Propagation constant \(\gamma = \alpha + j\beta = \sqrt{(R + j\omega L)(G + j\omega C)}\).
A sinusoidal wave on the line varies as \(e^{-\gamma x}\): its amplitude decays by \(\alpha\) nepers per metre and its phase advances by \(\beta\) radians per metre, so it travels at \(\omega/\beta\).
- Parameters:
R_per_m (float) – Series resistance per unit length [ohm/m], nonnegative.
L_per_m (float) – Series inductance per unit length [H/m], positive.
G_per_m (float) – Shunt conductance per unit length [S/m], nonnegative.
C_per_m (float) – Shunt capacitance per unit length [F/m], positive.
omega (float or array_like) – Angular frequency [rad/s], positive.
- Returns:
\(\gamma\) [1/m], with \(\alpha, \beta \ge 0\).
- Return type:
complex or ndarray of complex
Notes
Inputs are raw SI numbers with no dimensional metadata; see Electrical engineering: passive components and circuit responses.
References
Heaviside, “On the extra current,” Phil. Mag. 2 (1876) 135-145.
Examples
>>> complex(np.round(propagation_constant(0, 1e-6, 0, 1e-12, 1e6), 12)) 0.001j
- engineeringkit.electrical_engineering.rc_charging_voltage(v_source, R, C, t, v0=0.0)[source]#
Capacitor voltage \(v(t) = V_s + (v_0 - V_s)e^{-t/RC}\) after a step.
- Parameters:
v_source (float) – Constant source voltage applied at \(t = 0\) [V].
R (float) – Series resistance [ohm], positive.
C (float) – Capacitance [F], positive.
t (float or array_like) – Time since the step [s], nonnegative.
v0 (float, optional) – Initial capacitor voltage [V].
- Returns:
Capacitor voltage [V], shaped like
t.- Return type:
ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Electrical engineering: passive components and circuit responses.
Examples
>>> round(float(rc_charging_voltage(1.0, 1e3, 1e-6, 1e-3)), 4) 0.6321
- engineeringkit.electrical_engineering.rc_time_constant(R, C)[source]#
RC time constant \(\tau = RC\).
- Parameters:
R (float or array_like) – Resistance [ohm], positive.
C (float or array_like) – Capacitance [F], positive.
- Returns:
Time constant [s].
- Return type:
float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Electrical engineering: passive components and circuit responses.
References
W. Thomson, “On the theory of the electric telegraph,” Proc. R. Soc. London 7 (1855) 382-399.
Examples
>>> rc_time_constant(1e3, 1e-6) 0.001
- engineeringkit.electrical_engineering.reactive_power(v_rms, i_rms, phase_rad)[source]#
Reactive power \(Q = V_{rms} I_{rms} \sin\phi\).
- Parameters:
v_rms (float or array_like) – RMS voltage [V], nonnegative.
i_rms (float or array_like) – RMS current [A], nonnegative.
phase_rad (float or array_like) – Angle \(\phi\) by which the current lags the voltage [rad].
- Returns:
Reactive power [var]; positive for an inductive (lagging) load.
- Return type:
float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Electrical engineering: passive components and circuit responses.
References
C. I. Budeanu, Puissances réactives et fictives (Bucharest: Institut National Roumain pour l’Étude de l’Aménagement et de l’Utilisation des Sources d’Énergie, 1927).
Examples
>>> round(float(reactive_power(230.0, 10.0, np.pi / 6)), 6) 1150.0
- engineeringkit.electrical_engineering.real_power(v_rms, i_rms, pf=1)[source]#
Real (active) power \(P = V_{rms} I_{rms} \cos\phi\).
- Parameters:
v_rms (float or array_like) – RMS voltage [V], nonnegative.
i_rms (float or array_like) – RMS current [A], nonnegative.
pf (float or array_like, optional) – Power factor \(\cos\phi\) [-], in \([-1, 1]\).
- Returns:
Real power [W].
- Return type:
float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Electrical engineering: passive components and circuit responses.
Examples
>>> real_power(230.0, 10.0, 0.8) 1840.0
- engineeringkit.electrical_engineering.reflection_coefficient(z_load, z0)[source]#
Voltage reflection coefficient \(\Gamma = (Z_L - Z_0)/(Z_L + Z_0)\).
- Parameters:
z_load (complex or array_like) – Load impedance [ohm], finite with nonnegative real part (a passive load); an open circuit is the limit \(\Gamma = 1\).
z0 (float) – Characteristic impedance [ohm], positive.
- Returns:
\(\Gamma\) [-], inside or on the unit circle.
- Return type:
complex or ndarray of complex
Notes
Inputs are raw SI numbers with no dimensional metadata; see Electrical engineering: passive components and circuit responses.
Examples
>>> complex(reflection_coefficient(150.0, 50.0)) (0.5+0j)
- engineeringkit.electrical_engineering.resonance_frequency(L, C)[source]#
Resonant frequency \(f_0 = 1/(2\pi\sqrt{LC})\) of an LC circuit.
- Parameters:
L (float or array_like) – Inductance [H], positive.
C (float or array_like) – Capacitance [F], positive.
- Returns:
Resonant frequency [Hz].
- Return type:
float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Electrical engineering: passive components and circuit responses.
References
O. J. Lodge, “Improvements in syntonized telegraphy without line wires,” British Patent 11,575 (1897).
Examples
>>> round(float(resonance_frequency(1e-3, 1e-9)), 1) 159154.9
- engineeringkit.electrical_engineering.rl_current(v_source, R, L, t, i0=0.0)[source]#
Inductor current \(i(t) = V_s/R + (i_0 - V_s/R)e^{-Rt/L}\) after a step.
- Parameters:
v_source (float) – Constant source voltage applied at \(t = 0\) [V].
R (float) – Series resistance [ohm], positive.
L (float) – Inductance [H], positive.
t (float or array_like) – Time since the step [s], nonnegative.
i0 (float, optional) – Initial inductor current [A].
- Returns:
Inductor current [A], shaped like
t.- Return type:
ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Electrical engineering: passive components and circuit responses.
References
H. Helmholtz, “Ueber die Dauer und den Verlauf der durch Stromesschwankungen inducirten elektrischen Ströme,” Ann. Phys. 83 (1851) 505-540.
Examples
>>> round(float(rl_current(10.0, 5.0, 0.5, 0.1)), 4) 1.2642
- engineeringkit.electrical_engineering.rl_time_constant(L, R)[source]#
RL time constant \(\tau = L/R\).
- Parameters:
L (float or array_like) – Inductance [H], positive.
R (float or array_like) – Resistance [ohm], positive.
- Returns:
Time constant [s].
- Return type:
float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Electrical engineering: passive components and circuit responses.
- engineeringkit.electrical_engineering.rlc_damping(R, L, C)[source]#
Neper frequency, resonant frequency and damping regime of a series RLC circuit.
The natural response of a series RLC circuit has the characteristic roots \(s = -\alpha \pm \sqrt{\alpha^2 - \omega_0^2}\) with \(\alpha = R/2L\) and \(\omega_0 = 1/\sqrt{LC}\). It is overdamped for \(\alpha > \omega_0\), critically damped for \(\alpha = \omega_0\) (\(R = 2\sqrt{L/C}\)) and underdamped, an oscillation decaying as \(e^{-\alpha t}\), for \(\alpha < \omega_0\).
- Parameters:
R (float) – Series resistance [ohm], nonnegative.
L (float) – Inductance [H], positive.
C (float) – Capacitance [F], positive.
- Returns:
(alpha, omega0, regime): the neper frequency [1/s], the undamped resonant frequency [rad/s] and one of"overdamped","critically damped"(within a relative 1e-9),"underdamped"or"undamped"(\(R = 0\)).- Return type:
tuple of (float, float, str)
Notes
Inputs are raw SI numbers with no dimensional metadata; see Electrical engineering: passive components and circuit responses. The damping ratio is \(\zeta = \alpha/\omega_0\).
R,LandCare scalar-only: the regime names one circuit.References
W. Thomson, “On transient electric currents,” Phil. Mag. 5 (1853) 393-405.
Examples
>>> rlc_damping(2.0, 1.0, 1.0) (1.0, 1.0, 'critically damped')
- engineeringkit.electrical_engineering.rlc_step_voltage(v_source, R, L, C, t)[source]#
Capacitor voltage of a series RLC circuit after a voltage step, from rest.
With \(\alpha\) and \(\omega_0\) from
rlc_damping(),\[\begin{split}\frac{v_C(t)}{V_s} = \begin{cases} 1 + \dfrac{s_2 e^{s_1 t} - s_1 e^{s_2 t}}{s_1 - s_2} & \text{overdamped},\\ 1 - (1 + \alpha t)e^{-\alpha t} & \text{critically damped},\\ 1 - e^{-\alpha t}\left(\cos\omega_d t + \dfrac{\alpha}{\omega_d} \sin\omega_d t\right) & \text{underdamped}, \end{cases}\end{split}\]with \(s_{1,2} = -\alpha \pm \sqrt{\alpha^2 - \omega_0^2}\) and \(\omega_d = \sqrt{\omega_0^2 - \alpha^2}\).
- Parameters:
v_source (float) – Constant source voltage applied at \(t = 0\) [V].
R (float) – Series resistance [ohm], nonnegative.
L (float) – Inductance [H], positive.
C (float) – Capacitance [F], positive.
t (float or array_like) – Time since the step [s], nonnegative.
- Returns:
Capacitor voltage [V], shaped like
t. The loop current is \(C\,dv_C/dt\), as returned bySeriesRLC.step_response.- Return type:
ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Electrical engineering: passive components and circuit responses. Within the relative 1e-9 band that
rlc_damping()calls critical, the critical formula is used.R,LandCare scalar-only (one circuit, swept overt).Examples
>>> round(float(rlc_step_voltage(1.0, 2.0, 1.0, 1.0, 1.0)), 4) 0.2642
- engineeringkit.electrical_engineering.rms_sine(amplitude)[source]#
RMS value \(A/\sqrt2\) of a sinusoid of peak amplitude \(A\).
- Parameters:
amplitude (float or array_like) – Peak amplitude [V or A], nonnegative.
- Returns:
RMS value, same units as
amplitude.- Return type:
float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Electrical engineering: passive components and circuit responses.
Examples
>>> round(float(rms_sine(325.0)), 1) 229.8
- engineeringkit.electrical_engineering.series_resistance(*r)[source]#
Equivalent resistance of resistors in series, \(R = \sum R_k\).
- Parameters:
*r (float) – Resistances [ohm], nonnegative.
- Returns:
Equivalent resistance [ohm].
- Return type:
float
Notes
Inputs are raw SI numbers with no dimensional metadata; see Electrical engineering: passive components and circuit responses.
Examples
>>> series_resistance(100.0, 220.0) 320.0
- engineeringkit.electrical_engineering.series_rlc_impedance(R, L, C, omega)[source]#
Series RLC impedance \(Z = R + j(\omega L - 1/\omega C)\).
- Parameters:
R (float) – Resistance [ohm], nonnegative.
L (float) – Inductance [H], positive.
C (float) – Capacitance [F], positive.
omega (float or array_like) – Angular frequency [rad/s], positive.
- Returns:
Impedance [ohm]; purely resistive at resonance.
- Return type:
complex or ndarray of complex
Notes
Inputs are raw SI numbers with no dimensional metadata; see Electrical engineering: passive components and circuit responses.
References
C. P. Steinmetz, “Complex quantities and their use in electrical engineering,” Proc. International Electrical Congress, Chicago 1893 (New York: AIEE, 1894) 33-74.
Examples
>>> complex(series_rlc_impedance(10.0, 1e-3, 1e-3, 1e3)) (10+0j)
- engineeringkit.electrical_engineering.shockley_diode_current(v, saturation_current, ideality=1.0, temperature=300.0)[source]#
Shockley’s diode equation \(i = I_S\left(e^{v/nV_T} - 1\right)\).
- Parameters:
v (float or array_like) – Voltage across the diode, anode to cathode [V], at most \(40\,nV_T\) (beyond that the exponential overflows any real device’s limits).
saturation_current (float) – Reverse saturation current \(I_S\) [A], positive.
ideality (float, optional) – Ideality factor \(n\) [-], positive (1 for Shockley’s ideal junction, up to about 2 for real silicon diodes).
temperature (float, optional) – Junction temperature [K], positive.
- Returns:
Diode current [A]; tends to \(-I_S\) under reverse bias.
- Return type:
float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Electrical engineering: passive components and circuit responses. Reverse breakdown, series resistance and high injection are not modelled.
References
W. Shockley, “The theory of p-n junctions in semiconductors and p-n junction transistors,” Bell Syst. Tech. J. 28 (1949) 435-489.
Examples
>>> round(float(shockley_diode_current(0.7, 1e-14)) * 1e3, 4) 5.7475
- engineeringkit.electrical_engineering.standing_wave_ratio(gamma)[source]#
Voltage standing-wave ratio \((1 + |\Gamma|)/(1 - |\Gamma|)\).
- Parameters:
gamma (complex or array_like) – Reflection coefficient [-], with \(|\Gamma| < 1\).
- Returns:
VSWR [-], one for a matched line.
- Return type:
float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Electrical engineering: passive components and circuit responses.
Examples
>>> float(standing_wave_ratio(0.5)) 3.0
- engineeringkit.electrical_engineering.swing_response(inertia_constant, p_mech, p_max_pre, p_max_fault, p_max_post, clearing_time, t_end, frequency=60.0, damping=0.0, n_points=2001)[source]#
Swing curve of a generator against an infinite bus through a cleared fault.
Integrates the swing equation
\[\frac{2H}{\omega_s}\frac{d^2\delta}{dt^2} = P_m - P_{max}\sin\delta - D\frac{d\delta}{dt}\]from rest at \(\delta_0 = \arcsin(P_m/P_1)\), with \(P_{max} = P_2\) until
clearing_timeand \(P_3\) after. The two intervals are integrated separately, so the step change in \(P_{max}\) falls on a sample.- Parameters:
inertia_constant (float) – Inertia constant \(H\) [s], positive.
p_mech (float) – Mechanical input power [pu], positive.
p_max_pre (float) – Power-angle amplitudes before, during and after the fault [pu]; see
equal_area_clearing_angle().p_max_fault (float) – Power-angle amplitudes before, during and after the fault [pu]; see
equal_area_clearing_angle().p_max_post (float) – Power-angle amplitudes before, during and after the fault [pu]; see
equal_area_clearing_angle().clearing_time (float) – Fault duration [s], in \((0, t_{end})\).
t_end (float) – End of the simulation [s], positive.
frequency (float, optional) – System frequency [Hz], positive.
damping (float, optional) – Damping coefficient \(D\) [pu power s/rad], nonnegative.
n_points (int, optional) – Number of output samples over \([0, t_{end}]\), at least three (the clearing instant is added to them).
- Returns:
Rotor angle [rad] and speed deviation [rad/s] against time [s], with a first-swing
stableflag.- Return type:
Notes
Inputs are raw SI numbers with no dimensional metadata; see Electrical engineering: passive components and circuit responses. Integrated with
engineeringkit.integrators.integrate_ode()(RK45). All parameters are scalar-only: the result is one swing curve.Examples
>>> r = swing_response(5.0, 1.0, 2.0, 0.0, 2.0, 0.2, 1.5) >>> r.stable, round(float(np.degrees(r.delta.max())), 1) (True, 119.4)
- engineeringkit.electrical_engineering.symmetrical_components(va, vb, vc)[source]#
Fortescue’s zero-, positive- and negative-sequence components of three phasors.
With \(a = e^{j2\pi/3}\),
\[\begin{split}\begin{bmatrix}V_0\\V_1\\V_2\end{bmatrix} = \frac13 \begin{bmatrix}1&1&1\\1&a&a^2\\1&a^2&a\end{bmatrix} \begin{bmatrix}V_a\\V_b\\V_c\end{bmatrix}.\end{split}\]- Parameters:
va (complex or array_like) – Phase phasors [V or A].
vb (complex or array_like) – Phase phasors [V or A].
vc (complex or array_like) – Phase phasors [V or A].
- Returns:
(V0, V1, V2), the phase-a members of the zero-, positive- and negative-sequence sets, same units as the input.- Return type:
tuple of complex or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Electrical engineering: passive components and circuit responses.
References
C. L. Fortescue, “Method of symmetrical co-ordinates applied to the solution of polyphase networks,” Trans. AIEE 37 (1918) 1027-1140.
Examples
>>> a = np.exp(2j * np.pi / 3) >>> [round(abs(complex(x)), 12) for x in symmetrical_components(1, a**2, a)] [0.0, 1.0, 0.0]
- engineeringkit.electrical_engineering.thermal_voltage(temperature=300.0)[source]#
Thermal voltage \(V_T = k_B T/q\).
- Parameters:
temperature (float or array_like, optional) – Junction temperature [K], positive.
- Returns:
Thermal voltage [V]; about 25.85 mV at 300 K.
- Return type:
float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Electrical engineering: passive components and circuit responses.
Examples
>>> round(thermal_voltage(300.0) * 1e3, 3) 25.852
- engineeringkit.electrical_engineering.thevenin_from_source(vs, rs)[source]#
Thévenin equivalent of a real voltage source with internal resistance.
A source \(V_s\) behind \(R_s\) already is a Thévenin equivalent; the function validates and returns it as a pair, so it can be passed to
norton_from_thevenin()ormaximum_power_transfer(). To reduce a whole network, usenodal_analysis()for the open-circuit voltage and the short-circuit current.- Parameters:
vs (float) – Open-circuit source voltage [V].
rs (float) – Internal resistance [ohm], nonnegative.
- Returns:
(V_th [V], R_th [ohm]).- Return type:
tuple of float
Notes
Inputs are raw SI numbers with no dimensional metadata; see Electrical engineering: passive components and circuit responses.
References
L. Thévenin, “Extension de la loi d’Ohm aux circuits électromoteurs complexes,” Annales Télégraphiques 10 (1883) 222-224.
Examples
>>> thevenin_from_source(9, 2) (9.0, 2.0)
- engineeringkit.electrical_engineering.three_phase_power(v_line, i_line, pf=1)[source]#
Balanced three-phase real power \(P = \sqrt3 V_L I_L \cos\phi\).
- Parameters:
v_line (float or array_like) – RMS line-to-line voltage [V], nonnegative.
i_line (float or array_like) – RMS line current [A], nonnegative.
pf (float or array_like, optional) – Power factor [-], in \([-1, 1]\).
- Returns:
Total real power [W] of the three phases.
- Return type:
float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Electrical engineering: passive components and circuit responses.
References
N. Tesla, “A new system of alternate current motors and transformers,” Trans. AIEE 5 (1888) 308-327.
Examples
>>> round(float(three_phase_power(400.0, 10.0)), 1) 6928.2
- engineeringkit.electrical_engineering.transformer_secondary(v_primary, n_primary, n_secondary)[source]#
Ideal-transformer secondary voltage \(V_2 = V_1 N_2/N_1\).
- Parameters:
v_primary (float or array_like) – Primary voltage [V].
n_primary (float) – Primary turns [-], positive.
n_secondary (float) – Secondary turns [-], positive.
- Returns:
Secondary voltage [V]. Currents transform by the inverse ratio and impedances by its square.
- Return type:
float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Electrical engineering: passive components and circuit responses.
References
Stanley, “Induction-coil,” U.S. Patent 349,611 (1886).
Examples
>>> transformer_secondary(240, 100, 50) 120.0
- engineeringkit.electrical_engineering.transmission_line_velocity(L_per_m, C_per_m)[source]#
Wave velocity \(v = 1/\sqrt{LC}\) on a lossless line.
- Parameters:
L_per_m (float or array_like) – Series inductance per unit length [H/m], positive.
C_per_m (float or array_like) – Shunt capacitance per unit length [F/m], positive.
- Returns:
Phase velocity [m/s].
- Return type:
float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Electrical engineering: passive components and circuit responses.
Examples
>>> round(float(transmission_line_velocity(250e-9, 100e-12)) / 1e8, 3) 2.0
- engineeringkit.electrical_engineering.transmission_line_z0(L_per_m, C_per_m)[source]#
Characteristic impedance \(Z_0 = \sqrt{L/C}\) of a lossless line.
- Parameters:
L_per_m (float or array_like) – Series inductance per unit length [H/m], positive.
C_per_m (float or array_like) – Shunt capacitance per unit length [F/m], positive.
- Returns:
Characteristic impedance [ohm].
- Return type:
float or ndarray
Notes
Inputs are raw SI numbers with no dimensional metadata; see Electrical engineering: passive components and circuit responses.
Examples
>>> round(float(transmission_line_z0(250e-9, 100e-12)), 1) 50.0
- engineeringkit.electrical_engineering.wheatstone_balanced(r1, r2, r3, r4, rtol=1e-09)[source]#
Whether a Wheatstone bridge is balanced, \(R_1/R_2 = R_3/R_4\).
The bridge has \(R_1, R_2\) in one arm and \(R_3, R_4\) in the other, both arms across the same source. At balance the two midpoints are at the same potential and the galvanometer between them reads zero.
- Parameters:
r1 (float) – Bridge resistances [ohm], positive.
r2 (float) – Bridge resistances [ohm], positive.
r3 (float) – Bridge resistances [ohm], positive.
r4 (float) – Bridge resistances [ohm], positive.
rtol (float, optional) – Relative tolerance on the ratio comparison [-], nonnegative.
- Returns:
Trueat balance.- Return type:
bool
Notes
Inputs are raw SI numbers with no dimensional metadata; see Electrical engineering: passive components and circuit responses.
References
C. Wheatstone, “An account of several new instruments and processes for determining the constants of a voltaic circuit,” Phil. Trans. R. Soc. 133 (1843) 303-327.
Examples
>>> wheatstone_balanced(100.0, 200.0, 50.0, 100.0) True
Visualizers#
Matplotlib visualizers for engineeringkit.electrical_engineering.
- engineeringkit.electrical_engineering.visualizers.plot_phasors(phasors, labels=None, ax=None)[source]#
Draw phasors as arrows from the origin of the complex plane.
- Parameters:
phasors (array_like of complex) – Phasors to draw [V, A or other], at least one.
labels (sequence of str, optional) – One legend label per phasor.
ax (matplotlib.axes.Axes, optional) – Axes to draw on; a new figure is created if omitted.
- Return type:
matplotlib.axes.Axes
- engineeringkit.electrical_engineering.visualizers.plot_smith_chart(gamma=None, ax=None, label=None)[source]#
Draw a Smith chart grid and, optionally, reflection coefficients on it.
Circles of constant normalized resistance \(r\) and arcs of constant normalized reactance \(x\) are drawn in the \(\Gamma\) plane.
- Parameters:
gamma (array_like of complex, optional) – Reflection coefficients [-] to plot as a line (a single value as a point), all with \(|\Gamma| \le 1\).
ax (matplotlib.axes.Axes, optional) – Axes to draw on; a new figure is created if omitted.
label (str, optional) – Legend label for
gamma.
- Return type:
matplotlib.axes.Axes