RLC circuit
A series RLC circuit written as Kirchhoff's voltage law, L q'' + R q' + q / C = V cos(ω t).
- Name:
rlc_circuit - Field:
engineering/circuits - Formalism: ordinary differential equations
- References: Kirchhoff 1845
Factory
@register_model(
field='engineering/circuits',
tags=('electromagnetism', 'circuit', 'ode', 'second order'),
references=('Kirchhoff 1845',),
defaults={'until': 50.0, 'dt': 0.05},
)
def rlc_circuit(
q: float = 1.0,
current: float = 0.0,
*,
L: float = 1.0,
R: float = 0.1,
C: float = 1.0,
V: float = 0.0,
omega: float = 1.0,
) -> System:
"""Return a series RLC circuit written as Kirchhoff's voltage law, `L q'' + R q' + q / C = V cos(ω t)`.
Args:
q:
The initial charge of the capacitor.
current:
The initial current.
L:
The inductance.
R:
The resistance.
C:
The capacitance.
V:
The amplitude of the source voltage.
omega:
The angular frequency of the source.
Returns:
system:
The model, with the circuit `circuit`, whose charge has order 2 and current `circuit.q_d1`.
Examples:
>>> from skcomplex.models.engineering.circuits import rlc_circuit
>>> rlc_circuit(R=0.5).elements[0].R
0.5
"""
return System(elements=[CircuitElement('circuit', q=q, q_d1=current, L=L, R=R, C=C, V=V, omega=omega)])
Components
class CircuitElement(Element):
"""RLC circuit whose charge follows `L q'' + R q' + q / C = V cos(ω t)`."""
def __init__(
self,
label: str,
visual: VisualSpec | None = None,
*,
q: Annotated[object, StateSpec(order=2)] = 1.0,
q_d1: float = 0.0,
L: Annotated[object, ParameterSpec(domain=RealSet.open(0, oo))] = 1.0,
R: Annotated[object, ParameterSpec(domain=RealSet.closed_open(0, oo))] = 0.1,
C: Annotated[object, ParameterSpec(domain=RealSet.open(0, oo))] = 1.0,
V: Annotated[object, ParameterSpec()] = 0.0,
omega: Annotated[object, ParameterSpec(domain=RealSet.closed_open(0, oo))] = 1.0,
) -> None:
super().__init__(label, visual=visual)
self.q = q
self.q_d1 = q_d1
self.L = L
self.R = R
self.C = C
self.V = V
self.omega = omega
def _get_laws(self, s: SimpleNamespace) -> list[BaseLaw]:
"""Return the equation of the charge."""
return [
EquationLaw(s.L * derivative(s.q, 2) + s.R * derivative(s.q, 1) + s.q / s.C == s.V * cos(s.omega * s.t)),
]
Equations
circuit.q: diff(q_circuit(t), t, t) == (V_circuit*cos(omega_circuit*t) - R_circuit*diff(q_circuit(t), t) - q_circuit(t)/C_circuit)/L_circuit