## Friday, 4 November 2011

### Circuit Solver using MATLAB Programming

In this blog we will learn to simulate a circuit using MATLAB Programming which is the basic step to create your own circuit solver. The circuit we are going to solve is shown in Fig 1. Here V is 6V.

 Fig 1: Circuit
Create NetList and SourceList
You need to first represent this circuit in terms of matrixes so that you can use them in MATLAB. These two matrixs will describe the network- NetList and SourceList
Let us first give a number to all the nodes in the circuit. Two nodes should be separated by atleast an element.
The considered circuit has 4 nodes and let us choose node 4 as the reference/ground node.

Now create a matrix named as NetList with three columns N1, N2 and R. Each row of this matrix will represent a R resistance element between Node N1 and N2.

Now create a matrix named SourceList with two columns N and V. Each row of this matrix will represent a N node with V voltage. Since only two node voltages are know, this will contain two rows.

 Fig 2: NetList and Source List

Create A and B matrix
If Total Nodes are N
A is of N x N
Aij=
Case 1: if i is not a Source Nodes
-1/Rij where Rij is the resistance between i and j (if i!=j)
Sum of inverse of all resistance connected to i (if i==j)

Case 2: if i is a source Node
Aii=1 and
rest Aik=0

If Total Nodes are N
B is of N x 1
Bi=
Case 1: if i is not a Source Node
0
Case 2: if i is a source Node
Voltage of that source Node

Nodal Equations

Using the above nodal equation can be represented as
$\mathbf{AV=B}$$\mathbf{V}=[V_1 V_2 ... V_N]^T$$V=A^{-1}B$

This V represent the Voltage of all the nodes, thus circuit is solved.

MATLAB Code
Initialization of the matrixs
NetList=[1 2 2; 1 3 4; 2 3 5.2; 3 4 6; 2 4 3];
Vnod=[1 6; 4 2];
l=size(NetList,1);
N=max([NetList(:,1) ;
NetList(:,2)]);
A=zeros(N,N);
B=zeros(N,1);
A Matrix Creation
for i=1:l
n1=NetList(i,1);
n2=NetList(i,2);
if n1==n2
else
A(n1,n2)=A(n1,n2)-1/NetList(i,3);
A(n2,n1)=A(n2,n1)-1/NetList(i,3);
A(n1,n1)=A(n1,n1)+1/NetList(i,3);
A(n2,n2)=A(n2,n2)+1/NetList(i,3);
end
end
B Matrix Creation

for i=1:size(Vnod,1)
A(Vnod(i,1),:)=zeros(1,N);
A(Vnod(i,1),Vnod(i,1))=1;
B(Vnod(i,1),1)=Vnod(i,2);
end

Solution
Vo=A\B;
disp(Vo);

1. https://iversity.org/c/13?r=efbf0

robotic simulation using matlab .check this out

2. Thanks, that was really useful.

3. You explain it greate.

Check here you will find more :

https://www.udemy.com/learn-matlab/?couponCode=MATLAB25

4. hello m doing hand drawn circuit detection as my mtech project..can i get help from yu..pls

5. we can also create inverse of matrix A in matlab using inv(A) and use the same in the program. But anyways nice turorial. I liked this post. Very informative.
You can find my blog on matlab with many programs from here: https://radiusofcircle.blogspot.com. Thanks!

6. This comment has been removed by the author.

7. This blog awesome and i learn a lot about programming from here.The best thing about this blog is that you doing from beginning to experts level.

Love from

8. I really appreciate information shared above. It’s of great help. If someone want to learn Online (Virtual) instructor lead live training in MATLAB, kindly contact us http://www.maxmunus.com/contact
MaxMunus Offer World Class Virtual Instructor led training on MATLAB. We have industry expert trainer. We provide Training Material and Software Support. MaxMunus has successfully conducted 100000+ trainings in India, USA, UK, Australlia, Switzerland, Qatar, Saudi Arabia, Bangladesh, Bahrain and UAE etc.