Generating a DC Solver for Linear Resistive Circuits with AI

Generating a DC Solver for Linear Resistive Circuits with AI

In our latest video, we demonstrate how to use the ChatGPT AI to generate a general Python program, which you can then run directly within the TINA simulation software. This allows you to compare the results from the AI-generated code with the accuracy of a professional simulation environment.

Generating the Python Code with ChatGPT

Start chatgpt.com and enter the following request:

“Generate a DC solver from netlist using Python. Include one test example with a voltage source of VS=100V, R1=20, R2=30.”

The AI will immediately respond with a structured explanation, followed by the generated Python code.
The generated code is typically quite general, allowing you to solve any DC circuit using the specified netlist syntax.

The generated Python code by chatGPT

Important Note: Keep in mind that ChatGPT and most other AI systems may generate slightly different Python code or result formats each time they are used.

Integration into the TINA Environment

Once the code is generated, we need to import it into the TINA simulation software for execution.

Running the Code
  • Use the “Copy code” icon to copy the generated Python code to your clipboard.
  • Start TINA.
  • Open the built-in Python compiler: Select Python Shell from the Tools menu.
  • Paste the Python code into the compiler’s editing area.
  • Press the “Run” icon.

The Python program will execute and display the nodal voltages, including the source current.

Inserting the Python code into TINA’s Python Shell

Comparison with TINA Simulation

To check the validity and accuracy, draw the circuit using the Schematic Editor of TINA and run a DC analysis. Enter the schematic equivalent of the example circuit, then press the DC button.

Results Match

The values calculated by TINA (V2 = 60 V and I= -2A) match exactly the results obtained from the AI-generated Python program.

The calculated values from TINA match the result obtained from our Python program

This method perfectly demonstrates how AI can quickly generate a basic DC solver whose results reliably align with the accuracy of professional simulation software like TINA.

You can learn more about TINA here: www.tina.com

You can learn more about TINACloud here: www.tinacloud.com

Explore more content from our channel: https://www.youtube.com/@TinaDesignSuite