mph- / lcapy

Lcapy is a Python package for symbolic linear circuit analysis and signal processing. It uses SymPy for symbolic mathematics.
GNU Lesser General Public License v2.1
244 stars 46 forks source link

double units and wrong units combinations #139

Open TheHowland opened 1 month ago

TheHowland commented 1 month ago

When accessing the the current and voltage of the component the matamatically interpreted result is V*2 for voltage and P for current. The Current has VA in the expressoin which physically would represent power instead of ampere. I suspect that it is because the expression has a symbol named 'V' which seems to not be the Voltage Symbol 'V'. Accessing the units property yields the correct unit.

from lcapy import t
from lcapy import state

state.show_units = True

cct = Circuit('''V1 0 1 dc {10}; up
W 1 2; right
R1 2 3 {1000}; down
W 3 0; left
''')
voltage = cct.R1.V(t)
current = cct.R1.I(t)

print("Voltage: " + str(voltage))
print("Current: " + str(current))`

output: Voltage: V(-10V) Current: A(-V/100) for V1 0 1 ac {10} {0} {100}; up Voltage: V(-10Vcos(100t)) Current: A(-Vcos(100t)/100)

mph- commented 1 month ago

Thanks for letting me know. Yes there is a bug when show_units is enabled. I've tracked down the source of the problem and will ponder a fix tomorrow.