How can I build a circuit solver in matlab ?

39 次查看(过去 30 天)
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.

回答(2 个)

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

Andy Zambell
Andy Zambell 2024-5-23
Building a circuit simulator in MATLAB is no small task. For everyone, I recommend looking at the Circuit Simulation Onramp to familiarize yourself with the circuit simulation capabilities of Simscape.

类别

Help CenterFile Exchange 中查找有关 Electrical Sensors 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by