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 visualizzazioni (ultimi 30 giorni)
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

Risposte (5)

Ritvij Sahasrabuddhe
Ritvij Sahasrabuddhe il 2 Gen 2021
You have used 'sol' and 'SOL' as function def output, which are considered 2 different variables

PRASANTH R
PRASANTH R il 27 Dic 2020

Anthony
Anthony il 1 Mar 2021
Modificato: DGM il 4 Mar 2023
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 il 15 Mag 2022
Modificato: DGM il 4 Mar 2023
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 il 15 Mag 2022
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

Categorie

Scopri di più su Circuits and Systems in Help Center e File Exchange

Prodotti


Release

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by