To Write a function called voltage that computes the voltages at different junctions in electrical circuit. after writing the program the output is not coming please help

16 ビュー (過去 30 日間)
function sol = voltage(V,R)
M =[R(2)*R(7)+R(1)*R(2)+R(1)*R(7),-R(1)*R(2),0;-R(3)*R(4)*R(8),R(4)*R(7)*R(8)+R(3)*R(4)*R(8)+R(3)*R(4)*R(7)+R(3)*R(7)*R(8),-R(3)*R(4)*R(7);0,-R(5)*R(6),R(6)*R(8)+R(5)*R(6)+R(5)*R(8)];
y =V*[R(2)*R(7);R(4)*R(7)*R(8);R(6)*R(8)];
SOL=M\y;
end

回答 (5 件)

Ritvij Sahasrabuddhe
Ritvij Sahasrabuddhe 2021 年 1 月 2 日
You have used 'sol' and 'SOL' as function def output, which are considered 2 different variables

PRASANTH R
PRASANTH R 2020 年 12 月 27 日

Anthony
Anthony 2021 年 3 月 1 日
編集済み: DGM 2023 年 3 月 4 日
function sol = voltage(V,R)
M =[R(2)*R(7)+R(1)*R(2)+R(1)*R(7),-R(1)*R(2),0;
-R(3)*R(4)*R(8),R(4)*R(7)*R(8)+R(3)*R(4)*R(8)+R(3)*R(4)*R(7)+R(3)*R(7)*R(8),-R(3)*R(4)*R(7);
0,-R(5)*R(6),R(6)*R(8)+R(5)*R(6)+R(5)*R(8)];
y =V*[R(2)*R(7);R(4)*R(7)*R(8);R(6)*R(8)];
sol=M\y;
end

Tapan Chahar
Tapan Chahar 2022 年 5 月 15 日
編集済み: DGM 2023 年 3 月 4 日
function [X]=voltage(V,R)
% Writing equations about the 3 node points using Kirchoffs Law & rewritting
% them in terms of matrix we get
if R(1)==0||R(3)==0||R(5)==0
% When resistor R1 =0
if R(1)==0
A=[(1/R(3)+1/R(7)+1/R(8)+1/R(4)),(-1/R(8)) ; (-1/R(8)),(1/R(5)+1/R(8)+1/R(6))];
b=[(V/R(3)+V/R(7));V/R(5)];
XX=A\b;
X=[V;XX];
end
% When resistor R3 =0
if R(3)==0
A=[(1/R(1)+1/R(2)+1/R(7)),0 ; (-1/R(8)),(1/R(5)+1/R(8)+1/R(6))];
b=[(V/R(1)+V/R(7));V/R(5)];
XX=A\b;
X=[XX(1);V;XX(2)];
end
% When resistor R5 =0
if R(5)==0
A=[(1/R(1)+1/R(2)+1/R(7)),(-1/R(7)) ; (-1/R(7)),(1/R(3)+1/R(4)+1/R(7)+1/R(8))];
b=[V/R(1);V/R(3)+V/R(8)];
XX=A\b;
X=[XX;V];
end
% When both resistor R3 & R5 are =0
if R(3)==0&R(5)==0
A=[(1/R(1)+1/R(2)+1/R(7))];
b=[V/R(1)+V/R(7)];
XX=A\b;
X=[XX;V;V];
end
% When both resistor R1 & R3 are =0
if R(1)==0&R(3)==0
A=[(1/R(5)+1/R(6)+1/R(8))];
b=[V/R(5)+V/R(8)];
XX=A\b;
X=[V;V;XX];
end
% When both resistor R1 & R5 are =0
if R(1)==0&R(5)==0
A=[(1/R(3)+1/R(4)+1/R(7)+1/R(8))];
b=[V/R(3)+V/R(7)+V/R(8)];
XX=A\b;
X=[V;XX;V];
end
% When resistor R1, R3 & R5 are =0
if R(1)==0&R(3)==0&R(5)==0
X=[V;V;V];
end
% When resistor R1,R3 & R5 are non zero
else
A=[(1/R(1)+1/R(2)+1/R(7)),(-1/R(7)),0 ; (-1/R(7)),(1/R(3)+1/R(7)+1/R(8)+1/R(4)),(-1/R(8)) ; 0,(-1/R(8)),(1/R(5)+1/R(8)+1/R(6))];
b=[V/R(1);V/R(3);V/R(5)];
X=A\b;
end
end

Tapan Chahar
Tapan Chahar 2022 年 5 月 15 日
function X = voltage(V,R)
A = [ R(2)*R(7) + R(1)*R(2) + R(1)*R(7), -R(1)*R(2), 0;
-R(3)*R(4)*R(8), R(4)*R(7)*R(8) + R(3)*R(4)*R(8) + R(3)*R(4)*R(7) + R(3)*R(7)*R(8), -R(3)*R(4)*R(7);
0, -R(5)*R(6), R(6)*R(8) + R(5)*R(6) + R(5)*R(8) ];
b = V * [R(2)*R(7); R(4)*R(7)*R(8); R(6)*R(8)];
X = A \ b;
end

カテゴリ

Help Center および File ExchangeCircuits and Systems についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by