── schemdraw is optional but gives you prettier wire layouts.
2. A minimal ASCII diagram
python
from lcapy import Circuit
cct = Circuit()
# define a DC source, resistor, capacitor in series
cct.add('V 1 0 DC 5V; R 1 2 1k; C 2 0 1u; .op')
print(cct) # textual netlist
print(cct.draw())
File "/home/hzhou/miniconda3/envs/robotics/lib/python3.9/site-packages/lcapy/sym.py", line 251, in sympify1
raise SyntaxError('Invalid expression %s' % arg)
SyntaxError: Invalid expression 1k
Assistant
It turns out that SymPy’s parser (which lcapy uses under the hood) does not recognize the suffix “k” on numeric literals, so writing
python
cct.add('R 1 2 1k')
will give you exactly the “Invalid expression 1k” error. The simplest fix is to use plain Python‐style scientific notation for kilo, milli, micro, etc.:
python
from lcapy import Circuit
cct = Circuit()
cct.add('V 1 0 DC 5') # 5 V
cct.add('R 1 2 1e3') # 1 kΩ = 1×10³ Ω
cct.add('C 2 0 1e-6') # 1 µF = 1×10⁻⁶ F
print(cct.draw())
If you really want to use SI‐prefixes like “k”, “M”, “m”, “u”, “n” in your code, you can combine them with lcapy’s unit objects:
python
from lcapy import Circuit
from lcapy.units import k, m, u, n
cct = Circuit()
cct.add('V 1 0 DC 5') # 5 V
cct.R(1, 2, 1 * k) # 1 kΩ
cct.C(2, 0, 1 * u) # 1 µF
print(cct.draw())
Here, 1 * k is 1000.0 internally, and 1 * u is 1e-6. That way you get the readability of prefixes without tripping SymPy’s parser.