I need help creating the matlab code to calculate the voltage at all the nodes i
ID: 2292268 • Letter: I
Question
I need help creating the matlab code to calculate the voltage at all the nodes in this multisim circuit.
This is the code I have so far:
% Defining resistor values
R1 = 1;
R2 = 6;
R3 = 4;
% Defining current source values
I1 = 3;
I2 = 2;
I3 = 8;
% Defining voltage source values
V1 = 7;
V2 = 5;
% Setting matrix A row 1 as left hand side of KCL equation @ node 1
A11 = 1/R1;
A12 = ;
A13 = ;
A14 = ;
A15 = ;
% Setting matrix A row 2 as left hand side of KCL equation @ node 2
A21 = 0;
A22 = ;
A23 = ;
A24 = ;
A25 = ;
% Setting matrix A row 3 as left hand side of KCL equation @ node 3
A31 = 0;
A32 = ;
A33 = ;
A34 = ;
A35 = ;
% Setting matrix A row 4 as left hand side of KCL equation @ node 4
A41 = 0;
A42 = ;
A43 = ;
A44 = ;
A45 = ;
% Setting matrix A row 5 as left hand side of KCL equation @ node 5
A51 = 0;
A52 = ;
A53 = ;
A54 = ;
A55 = ;
% Creating matrix A
A = [A11, A12, A13, A14, A15; A21, A22, A23, A24, A25; A31, A32, A33, A34, A35; A41, A42, A43, A44, A45; A51, A52, A53, A54, A55];
% Setting transposed matrix I as right hand side of KCL equations @ nodes
I = [ -I1-I2; ; ; ; ];
% Finding & showing voltages at all nodes
V = inv(A)*I;
V1 = V(1)
V2 = V(2)
V3 = V(3)
V4 = V(4)
V5 = V(5)
Explanation / Answer
matlab code:
clear all
clc
% Defining resistor values
R1 = 1;
R2 = 6;
R3 = 4;
% Defining current source values
I1 = 3;
I2 = 2;
I3 = 8;
% Defining voltage source values
V1 = 7;
V2 = 5;
% Setting matrix A row 1 as left hand side of KCL equation @ node 1
A11 = 1/R1;
A12 = 0 ;
A13 = 0 ;
A14 = 0 ;
A15 = 0 ;
% Setting matrix A row 2 as left hand side of KCL equation @ node 2
A21 = 0 ;
A22 = 1/R3;
A23 = 0 ;
A24 = -1/R3;
A25 = 0 ;
% Setting matrix A row 3 as left hand side of KCL equation @ node 3
A31 = 0 ;
A32 = 0 ;
A33 = 1 ;
A34 = 0 ;
A35 = 0 ;
% Setting matrix A row 4 as left hand side of KCL equation @ node 4
A41 = 0 ;
A42 = 0 ;
A43 = 0 ;
A44 = 1 ;
A45 = -1;
% Setting matrix A row 5 as left hand side of KCL equation @ node 5
A51 = 0;
A52 = -1/R3;
A53 = -1/R2;
A54 = 1/R3 ;
A55 = 1/R2 ;
% Creating matrix A
A = [A11, A12, A13, A14, A15;
A21, A22, A23, A24, A25;
A31, A32, A33, A34, A35;
A41, A42, A43, A44, A45;
A51, A52, A53, A54, A55]
% Setting transposed matrix I as right hand side of KCL equations @ nodes
I = [ -(I1+I2);
I1 ;
-V1 ;
V2 ;
-I3 ]
% Finding & showing voltages at all nodes
V = inv(A)*I;
V1 = V(1)
V2 = V(2)
V3 = V(3)
V4 = V(4)
V5 = V(5)
matlab output:
A =
1.0000 0 0 0 0
0 0.2500 0 -0.2500 0
0 0 1.0000 0 0
0 0 0 1.0000 -1.0000
0 -0.2500 -0.1667 0.2500 0.1667
I =
-5
3
-7
5
-8
V1 =
-5
V2 =
-20
V3 =
-7
V4 =
-32
V5 =
-37
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.