How can I build a circuit solver in matlab ?
26 ビュー (過去 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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/156469/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/156470/image.png)
But I can't solve the circuits in which voltage source is present between any two nodes other than ground.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/156471/image.png)
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 件のコメント
Emanuele Zanetti
2019 年 6 月 17 日
Hello,
I have the same issue. Did you find a solution for this problem?
回答 (2 件)
Bardo
2020 年 2 月 25 日
Hi,
you need to familiarize yourself with MNA equations, see a nice explanation in
0 件のコメント
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.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Electrical Sensors についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!