292
Practical MATLAB
® Applications for Engineers
Note that the aforementioned matrix equations can be expressed as [Z] * [I] = [V],
where
Z
j
j
j
j
ϭ
ϩ
Ϫ
Ϫ
Ϫ
ϩ
Ϫ
ϩ
ϩ
(
)
(/ )
(
( / ))
( / )
( / )
10 20
1 20
20
0
20
20
30 1 40
1 40
0
1 40
10 Ϫ Ϫ j( / )
1 40
and
V ϭ
Њ
Њ
5 0
0
9 45
∠
∠
The currents I 1 , I 2 , and I 3 can be evaluated by using the following MATLAB matrix
relation
I = inv (Z) * [V]
MATLAB Solution
% Script file: loops
disp(‘**********************************’)
disp(‘
System Matrices
’)
disp(‘**********************************’)
disp(‘The impedance matrix is given by:’)
Z = [30-j*1/20 -20 0;-20 20+j*(30-1/40) j*(1/40); 0 j*(1/40) 10-j*(1/40)]
A = 9*exp(j*45*pi/180);
disp(‘The voltage matrix is given by:’)
V= [5; 0; A]
disp(‘**********************************’)
disp(‘
Loop Currents
’)
disp(‘**********************************’)
% Solve for loop currents I1, I2 and I3
I = inv(Z)*V;
% Solve for Magnitude and Phase Angle.
I1mag = abs(I(1));
I2mag = abs(I(2));
I3mag = abs(I(3));
I1ang = angle(I(1))*180/pi;
I2ang = angle(I(2))*180/pi;
I3ang = angle(I(3))*180/pi;
% Print currents
disp(‘^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^’)
disp(‘
phasor domain
’)
disp(‘^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^’)
fprintf(‘The magnitude of the Current I1 (in amps) is :%f\n and its
phase angle in degrees is :%f\n’,I1mag,I1ang)
fprintf(‘The magnitude of the current I2 (in amps) is :%f\n and its
phase angle in degrees :%f\n’,I2mag,I2ang)
fprintf(‘The magnitude of the current I3 (in amps)is :%f\n and its
phase angle in degrees is :%f\n’,I3mag,I3ang)
disp(‘^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^’)
disp(‘
time domain
’)
disp(‘^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^’)
CRC_47760_CH003.indd 292
CRC_47760_CH003.indd 292
7/23/2008 1:27:50 PM
7/23/2008 1:27:50 PM
Practical MATLAB
® Applications for Engineers
Note that the aforementioned matrix equations can be expressed as [Z] * [I] = [V],
where
Z
j
j
j
j
ϭ
ϩ
Ϫ
Ϫ
Ϫ
ϩ
Ϫ
ϩ
ϩ
(
)
(/ )
(
( / ))
( / )
( / )
10 20
1 20
20
0
20
20
30 1 40
1 40
0
1 40
10 Ϫ Ϫ j( / )
1 40
and
V ϭ
Њ
Њ
5 0
0
9 45
∠
∠
The currents I 1 , I 2 , and I 3 can be evaluated by using the following MATLAB matrix
relation
I = inv (Z) * [V]
MATLAB Solution
% Script file: loops
disp(‘**********************************’)
disp(‘
System Matrices
’)
disp(‘**********************************’)
disp(‘The impedance matrix is given by:’)
Z = [30-j*1/20 -20 0;-20 20+j*(30-1/40) j*(1/40); 0 j*(1/40) 10-j*(1/40)]
A = 9*exp(j*45*pi/180);
disp(‘The voltage matrix is given by:’)
V= [5; 0; A]
disp(‘**********************************’)
disp(‘
Loop Currents
’)
disp(‘**********************************’)
% Solve for loop currents I1, I2 and I3
I = inv(Z)*V;
% Solve for Magnitude and Phase Angle.
I1mag = abs(I(1));
I2mag = abs(I(2));
I3mag = abs(I(3));
I1ang = angle(I(1))*180/pi;
I2ang = angle(I(2))*180/pi;
I3ang = angle(I(3))*180/pi;
% Print currents
disp(‘^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^’)
disp(‘
phasor domain
’)
disp(‘^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^’)
fprintf(‘The magnitude of the Current I1 (in amps) is :%f\n and its
phase angle in degrees is :%f\n’,I1mag,I1ang)
fprintf(‘The magnitude of the current I2 (in amps) is :%f\n and its
phase angle in degrees :%f\n’,I2mag,I2ang)
fprintf(‘The magnitude of the current I3 (in amps)is :%f\n and its
phase angle in degrees is :%f\n’,I3mag,I3ang)
disp(‘^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^’)
disp(‘
time domain
’)
disp(‘^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^’)
CRC_47760_CH003.indd 292
CRC_47760_CH003.indd 292
7/23/2008 1:27:50 PM
7/23/2008 1:27:50 PM
