How can I build a circuit solver in matlab ?

48 views (last 30 days)
My Mine
My Mine on 19 Sep 2016
Answered: Bardo on 25 Feb 2020
I am a beginner in Matlab. I want to bulid a program which will take input the nodes and the resistance,current source or voltage source present in between the nodes and will show me the output of the branch currents along with the node voltages.
This is the code I found in a blog http://matlabbyexamples.blogspot.com/2011/11/circuit-solver-using-matlab-programming.html and modified a little bit. This code only shows output of the node voltages.
NetList=input('input node and resistance');
Vnod=input('input voltage and node');
%NetList=[1 2 2; 1 3 4; 2 3 5.2; 3 4 6; 2 4 3];
%Vnod=[1 6; 4 0];
l=size(NetList,1);
N=max([NetList(:,1) ;
NetList(:,2)]);
A=zeros(N,N);
B=zeros(N,1);
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
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
Vo=A\B;
disp(Vo);
It can solve the following types of circuits taking input as matrix and give output only the node voltages
But I can't solve the circuits in which voltage source is present between any two nodes other than ground.
I want to build a simple program which will solve the above problem and give output the branch currents along with the node voltages.
  1 Comment
Emanuele Zanetti
Emanuele Zanetti on 17 Jun 2019
Hello,
I have the same issue. Did you find a solution for this problem?

Sign in to comment.

Answers (1)

Bardo
Bardo on 25 Feb 2020
Hi,
you need to familiarize yourself with MNA equations, see a nice explanation in

Categories

Find more on Circuit Envelope Simulation in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!