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
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 CenterFile Exchange 中查找有关 Circuits and Systems 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by