Lcapy is a Python package for analyzing linear circuits and uses sympy for symbol analysis.
Official documentation: Welcome to Lcapy ’s documentation!
Lcapy can perform numerical and symbolic analysis of circuits. Numerical analysis expresses the analysis result numerically, like the result output by the SPICE simulator. Symbol analysis is to express the transfer function and impedance of a circuit with symbols (mathematical formulas). By using this function, you can let the computer do the work of solving troublesome circuit equations.
Lcapy also has the ability to draw textbook-quality schematics on a command basis [^ 1].
As of October 31, 2020, there were no information about Lcapy on Qiita. When I searched on Google, the information was hardly hit not only in Japanese-speaking countries but also in English-speaking countries.
What can you do with Lcapy? You may want to read the Official Documentation Overview. Last but not least, my article on Lcapy may help you get to know the features of Lcapy.
This article describes how to enable Lcapy. We hope that the number of Lcapy users will increase and that we will be able to exchange useful information.
According to Installation of official documentation, the following python packages are required, so let's install them using pip. lcapy, sympy, numpy, matplotlib, networkx
If you don't use the schematic drawing feature, this is the end of the installation.
After installation, let's check the operation on Jupyter-notebook. In Lcapy, the transfer function of the circuit can be obtained by various methods, and an example is shown below.
Circuit for finding the transfer function:
Find the transfer function symbolically
from lcapy import Circuit, s
cct = Circuit("""
Vi 1 0
R 1 2 RF
C 2 0 CF
""")
H = (cct.C.V(s) / cct.Vi.V(s)).simplify()
H
The execution result is as follows, and the transfer function of the circuit could be analyzed symbolically.
If you want to use the schematic drawing function, you need to install TeX.
According to the Official Documentation Installation, you need pdflatex, circuitikz, and ghostscript. I found that pdflatex is distributed in W32TeX [^ 2], and the circuitikz package seems to be installed as standard in that W32TeX [^ 3]. It seems that ghostscript can be installed by using W32TeX installer. In other words, if you install only W32TeX, you will have everything you need. W32TeX can be easily installed by using TeX Installer 3.
Draw a schematic
from lcapy import Circuit
cct = Circuit("""
Vi 1 0_1 step; down
R 1 2; right, size=1.5
C 2 0; down
W 0_1 0; right
W 0 0_2; right, size=0.5
P1 2_2 0_2; down
W 2 2_2;right, size=0.5""")
cct.draw()
The execution result is as follows, and a beautiful circuit diagram is drawn.
The above code is quoted from: https://github.com/mph-/lcapy/tree/master/doc/examples/notebooks
I've been involved in circuit design-related work for several years, but until recently I didn't know the existence of tools that could analyze circuit symbols.
The following doctoral dissertations will be helpful for the types and tools of circuit analysis. About the mathematical behavior of electric circuits and their symbolic calculations
In Table 1.1 of the paper, SAPWIN and SCAM are used as circuit symbol analysis tools. 3443-scam-a-tool-for-symbolically-solving-circuit-equations), WASABI are introduced, but in addition to these, [QSapecNG] There seem to be tools such as (http://qsapecng.sourceforge.net/) and CircuitNAVI. I think it's best to choose the best tool for what you want to do.
In my case, what I wanted to do was:
I have written the following article about Lcapy, so please have a look there as well. [Circuit x Python] How to find the transfer function of a circuit using Lcapy [Circuit x Python] How to expand and calculate transfer function using Lcapy [^ 1]: Lcapy cannot analyze non-linear devices such as diodes and MOS, but it can be drawn as a circuit diagram.
Recommended Posts