From 8a6fccf3739febbb24a5bcb2264faa41954a75ad Mon Sep 17 00:00:00 2001 From: Shaurya Shukla Date: Thu, 24 Sep 2026 18:10:29 -0400 Subject: [PATCH] fix modified inductance element La to match its documented definition La computed (L * j * omega)^alpha, which also raises L to the power alpha. The docs (and EC-Lab's definition) give Z = L * (j * omega)^alpha. Fix the formula, update the La reference values in test_each_element, add a test that Z is linear in L, and correct the units of L to H sec^(a - 1). Fixes #312 --- impedance/models/circuits/elements.py | 4 ++-- impedance/tests/test_circuit_elements.py | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/impedance/models/circuits/elements.py b/impedance/models/circuits/elements.py index fa067407..d72009ec 100644 --- a/impedance/models/circuits/elements.py +++ b/impedance/models/circuits/elements.py @@ -208,7 +208,7 @@ def CPE(p, f): return Z -@element(num_params=2, units=["H sec", ""]) +@element(num_params=2, units=["H sec^(a - 1)", ""]) def La(p, f): """defines a modified inductance element as represented in [1] @@ -225,7 +225,7 @@ def La(p, f): """ omega = 2 * np.pi * np.array(f) L, alpha = p[0], p[1] - Z = (L * 1j * omega) ** alpha + Z = L * (1j * omega) ** alpha return Z diff --git a/impedance/tests/test_circuit_elements.py b/impedance/tests/test_circuit_elements.py index 5276c44e..d0199372 100644 --- a/impedance/tests/test_circuit_elements.py +++ b/impedance/tests/test_circuit_elements.py @@ -40,9 +40,9 @@ def test_each_element(): (1.6541327179718126 - 0.537460300252313j), ], "La": [ - (0.21769191 + 0.07073239j), - (0.86664712 + 0.28159072j), - (3.45018434 + 1.12103285j), + (0.03450184 + 0.01121033j), + (0.13735431 + 0.04462912j), + (0.54681737 + 0.17767173j), ], "G": [ (0.09999994078244179 - 0.00006283179105931961j), @@ -98,6 +98,15 @@ def test_each_element(): circuit_elements["T"]([1, 2, 50, 100], [10000]) +def test_La_linear_in_L(): + # Z = L * (j omega)^alpha, so doubling L must double Z for any alpha + freqs = [0.001, 1.0, 1000] + La = circuit_elements["La"] + Z1 = La([0.1, 0.7], freqs) + Z2 = La([0.2, 0.7], freqs) + assert np.isclose(Z2, 2 * Z1).all() + + def test_s(): a = np.array([5 + 6 * 1j, 2 + 3 * 1j]) b = np.array([5 + 6 * 1j, 2 + 3 * 1j])