I have a project that Im struggling with that reflects an elementary Circuit Solver consisting of only voltage, and resistance elements. The program inputs a netlist text document of all the components in the circuit in the following format.
"branch label |source node label | destination node label |value"
Example of a netlist
Example 1:
V1 1 0 5
R1 1 2 10
R2 2 0 20
Example 2:
V1 1 0 6
R1 1 2 6
R2 2 0 3.33
R3 2 3 3
R4 3 0 11
R5 3 4 4
R6 4 0 7
R7 4 5 7
R8 5 0 7
The programs purpose is to:
1.Read a new netlist. One of the easiest ways is to leverage filestream.
2.Count the numbers of branches and nodes.
3. Create an incidence matrix. You may derive a 2D incidence matrix from a netlist.
4. Create a voltage coefficients matrix.
5.Create a current coefficients matrix.
6.Create a combined matrix.
7.Append the input to the combined matrix.
8. Calculate the parameters (using either guassian elimination, lu factorization or matrix inversion)
The program then creates an output text file with the parameters in output.txt
The form of the output.txt is :
e1 e2 … en v1 v2 … vn i1 i2 … in
That is, the potentials, voltages, and currents are written in a row separated by
one space between each two.
Each result is a floating-point number in a decimal notation with 3 decimal places after the point (e.g.,14.654)
For the following input netlist (example 1) the expected output is:
5, 3.333, 5, 1.667, 3.333, -0.167, 0.167, 0.167
The goal is to implement an elementary circuit analysis tool that reads a circuit netlist and computes the current, voltage potential, and voltage drop at each component.
-Note:Your code should be in C++ only and you can only use C++ standard libraries
(including STL) Any libraries that implement matrices foryou are not allowed.
Important:
Please help code this problem for me the most IMPORTANT part that I find difficult and Struggle with is a runtime error when Vector Subscript is out of range, and also making sure all the matrices are initilized correctly to output the proper values. Please ensure the program works given any complete netlist of data and can output values into the output.txt document without any errors occuring, or any of the output values being example: (-nan(ind) -nan(ind) -nan(ind) 0.000 0.000 0.000 0.000 0.000). Usually when trying to fix this Runtime Error of vectors accessing allocated memory it involves, the number of nodes and branches not being properly initialized in the incidence matrix. Please explain how you manage to avoid an error like this also in your code.
I've Attached a following work in progress C++ text file code where the main problem is -nan(ind) is being returned. Please help revise and help explain the code and its problems.