Clear Filters
Clear Filters

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

18 views (last 30 days)
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

Answers (5)

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

PRASANTH R
PRASANTH R on 27 Dec 2020

Anthony
Anthony on 1 Mar 2021
Edited: DGM on 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 on 15 May 2022
Edited: DGM on 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 on 15 May 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

Categories

Find more on MATLAB in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!