PS Coding Solution
PS Coding Solution
Experiment:1
To write a computer program for plotting instantaneous voltage, current
and power in ac circuits.
Ex.1: Consider a single-phase circuit with a resistive load. The circuit parameters are as
follows:
• Voltage amplitude (Vm) = 100 V
• Frequency (f) = 50 Hz
• Resistance (R) = 50 ohms
Write a Scilab/MATLAB code to generate and plot the instantaneous current, voltage,
Real power time varying component,Pr, and reactive power time varying component,
Px,over one cycle of the AC waveform. Assume a sinusoidal waveform for the
voltage.
subplot(2, 2, 2);
plot(t, I);
xlabel('Time (s)');
ylabel('Current (A)');
title('Instantaneous Current');
subplot(2, 2, 3);
plot(t, Pr);
xlabel('Time (s)');
subplot(2, 2, 4);
plot(t, Px);
xlabel('Time (s)');
clear all
close all
% Circuit Parameters
Z=sqrt(R^2+(w*L)^2)
% Time vector
ThV=0;
ThI=atan((w*L)/R);
theta= (ThV-ThI)
v= Vm.*cos(w*t+ThV);
Im=Vm/Z;
i= Im.*cos((w*t)+theta);
V=Vm/sqrt(2);
I=Im/sqrt(2);
% Real power
P = v.*i;
Px= V.*I.*sin(theta).*sin(2.*(w*t+ThV))
% Plotting
figure;
subplot(2,2,1);
plot(t, v);
xlabel('Time (s)');
ylabel('Voltage (V)');
title('Instantaneous Voltage');
subplot(2,2,2);
plot(t, i);
xlabel('Time (s)');
ylabel('Current (A)');
title('Instantaneous Current');
subplot(2,2,3);
plot(t, P);
xlabel('Time (s)');
subplot(2,2,4);
plot(t, Px);
xlabel('Time (s)');
Ex.3: Consider a single-phase circuit with an inductive load. The circuit parameters are as
follows:
● Voltage amplitude (Vm) = 100 V
● Frequency (f) = 50 Hz
● Inductance (L) = 0.1 H
● Resistance (R) = 50 ohms
● Capacitance(C)=0.01 F
Write a Scilab/MATLAB code to generate and plot the instantaneous current, voltage,
real power, and reactive power over one cycle of the AC waveform. Assume a
sinusoidal waveform for the voltage.
% Circuit Parameters
Vm = 100; % Voltage amplitude (V)
f = 50; % Frequency (Hz)
L = 0.1; % Inductance (H)
R = 50; % Resistance (ohms)
C = 0.01; % Capacitance (F)
% Time vector
t = linspace(0, 1/f, 1000); % 1000 samples over one cycle
% Real power
P = v.*i;
% Reactive power
Q = (Vm^2/(R^2 + (2*pi*f*L - 1/(2*pi*f*C))^2)^0.5) * sin(atan((2*pi*f*L -
1/(2*pi*f*C))/R) - 2*pi*f*t + atan((2*pi*f*L - 1/(2*pi*f*C))/R));
% Plotting
figure;
subplot(2,2,1);
plot(t, v);
xlabel('Time (s)');
ylabel('Voltage (V)');
title('Instantaneous Voltage');
subplot(2,2,2);
plot(t, i);
xlabel('Time (s)');
ylabel('Current (A)');
title('Instantaneous Current');
subplot(2,2,3);
plot(t, P);
xlabel('Time (s)');
ylabel('Real Power (W)');
title('Real Power');
subplot(2,2,4);
plot(t, Q);
xlabel('Time (s)');
ylabel('Reactive Power (VAR)');
title('Reactive Power');
Ex4
Two loads connected in parallel are supplied from a single-phase 240-V rms
source. The two loads draw a total real power of 400 kW at a power factor
of 0.8 lagging. One of the loads draws 120 kW at a power factor of 0.96
leading. Find the complex power of the other load.
MATLAB problem :
% Given :
Vrms = 240; % RMS voltage in volts
P_total = 400e3; % Total real power in watts
pf_total = 0.8; % Power factor (lagging) for the total load
P1 = 120e3; % Real power of one load in watts
pf1 = 0.96; % Power factor (leading) of one load
Ex.5:
A balanced three-phase source supplies a balanced Y-connected load with
an impedance of Z = 300 * (36.87 + 1i) per phase.
The instantaneous phase voltages are given by:
van = 2800 * cos(wt)
vbn = 2800 * cos(wt - 120)
vcn = 2800 * cos(wt - 240)
Using Scilab/MATLAB, plot the instantaneous powers for each phase (pa,
pb, pc) and their sum (total three-phase real power) versus time (wt) over a
range of 0 to 2pi with an increment of 0.01pi on the same graph.
Z = 300 * (36.87 + 1i); % Impedance per phase
V_rms = 2800 / sqrt(2); % RMS phase voltage
%Matlab code:
% Given
Z = 300 * (36.87 + 1i); % Impedance per phase
V_rms = 2800 / sqrt(2); % RMS phase voltage
t = 0:0.01*pi:2*pi;
w=2*pi*50;
wt=w.*t;
% Instantaneous phase voltages
van = 2800 .* cos(wt);
vbn = 2800 .* cos(wt - 120);
vcn = 2800 .* cos(wt - 240);
Frequency (f): 50 Hz
Transmission line length (d): 300 km
Total series resistance (R): 40 ohm
Total series reactance (XL): j120 ohms
Total shunt admittance (Y): 10^(-3) mho
Receiving-end load:
Load power (P): 50 MW
Load voltage (V): 220 kV
Power factor (pf): 0.8 lagging
Find the sending-end voltage, current, power and power factor using computer program for
following mathematical models:
(a) Short line approximation,
Vr_ph=Vr/sqrt(3)
Ir=Pr/(pf*sqrt(3)*Vr)
Ir_ang=-acos(0.8)
Z=R+i*Xl
Ir_v=Ir*cos(Ir_ang) + i*Ir*sin(Ir_ang)
Vs_ph=Vr_ph+Ir_v*Z
Vs_m=abs(Vs_ph)
Vs_line=Vs_m*sqrt(3)
Is=Ir
Is_ang=Ir_ang
ss_v=3*Vs_ph*conj(Ir_v)
Ps=real(ss_v)
VR=(Vs_m-Vr_ph)*100/Vr_ph
eta=Pr*100/real(ss_v)
% display results
fprintf('Short line approximation')
fprintf(' \n \n Phase value of sending end voltage is %.2f kV at angel %.2f
\n',Vs_m/1e3,angle(Vs_ph)*180/pi)
fprintf(' Sending end active power is %.2f MW \n',Ps/1e6)
fprintf(' Voltage regulation is %.2f percent \n',VR)
fprintf(' Efficiency is %.2f percent \n \n \n',eta)
Vr_ph=Vr/sqrt(3)
Ir=Pr/(pf*sqrt(3)*Vr)
Ir_ang=-acos(0.8)
Z=R+i*Xl
Ir_v=Ir*cos(Ir_ang) + i*Ir*sin(Ir_ang)
A=1+Y*Z/2
D=A
B=Z
C=Y*(1+Y*Z/4)
Vs_ph=A*Vr_ph+B*Ir_v
Is_v=C*Vr_ph+D*Ir_v
Vs_m=abs(Vs_ph)
Vs_line=Vs_m*sqrt(3)
Is=abs(Is_v)
Is_ang=angle(Is_v)
ss_v=3*Vs_ph*conj(Is_v)
Ps=real(ss_v)
VR=(Vs_m-Vr_ph)*100/Vr_ph
eta=Pr*100/real(ss_v)
% display results
fprintf('Nominal PI method')
fprintf(' \n \n Phase value of sending end voltage is %.2f kV at angel %.2f
\n',Vs_m/1e3,angle(Vs_ph)*180/pi)
fprintf(' Sending end active power is %.2f MW \n',Ps/1e6)
fprintf(' Voltage regulation is %.2f percent \n',VR)
fprintf(' Efficiency is %.2f percent \n \n \n',eta)
%Nominal PI method
Vr_ph=Vr/sqrt(3)
Ir=Pr/(pf*sqrt(3)*Vr)
Ir_ang=-acos(0.8)
Z=R+i*Xl
Ir_v=Ir*cos(Ir_ang) + i*Ir*sin(Ir_ang)
Zc=sqrt(Z/Y)
yl=sqrt(Y*Z)
A=cosh(yl)
D=A
B=Zc*sinh(yl)
C=sinh(yl)/Zc
Vs_ph=A*Vr_ph+B*Ir_v
Is_v=C*Vr_ph+D*Ir_v
Vs_m=abs(Vs_ph)
Vs_line=Vs_m*sqrt(3)
Is=abs(Is_v)
Is_ang=angle(Is_v)
ss_v=3*Vs_ph*conj(Is_v)
Ps=real(ss_v)
VR=(Vs_m-Vr_ph)*100/Vr_ph
eta=Pr*100/real(ss_v)
% display results
fprintf('exact method')
fprintf(' \n \n Phase value of sending end voltage is %.2f kV at angel %.2f
\n',Vs_m/1e3,angle(Vs_ph)*180/pi)
fprintf(' Sending end active power is %.2f MW \n',Ps/1e6)
fprintf(' Voltage regulation is %.2f percent \n',VR)
fprintf(' Efficiency is %.2f percent \n \n \n',eta)
%Exact method
Ex1:
Write a computer program to analyze following data and plot A vs line length and receiving
end voltage vs line length
ll = 0:0.001:600;
% Given parameters
A = cos(beta * ll);
subplot(2,1,1)
plot(ll, A)
ylabel('Parameter A')
grid on
Vrnl = Vs ./ A;
subplot(2,1,2)
plot(ll, Vrnl)
title('Ferranti Effect')
grid on
Ex.2
Write a computer program to analyze following data and Display Distance (km), | Receiving-end
Voltage (kV) | Angle (degrees),
d = [50, 100, 150, 200, 250]; % Distance of the transmission line (in km)
f = 50;
% Constants
% Calculation
d_miles = d * 0.621371;
VL_ferranti = zeros(size(VL));
angle_ferranti = zeros(size(VL));
for i = 1:length(VL)
end
% Constants
for i = 1:numel(load_conditions)
d_miles = d * 0.621371;
end
% Display the results
fprintf('Receiving-end voltages (VL): %.2f kV, %.2f kV, %.2f kV, %.2f kV\n', abs(VL(1)),
abs(VL(2)), abs(VL(3)), abs(VL(4)));
fprintf('Phase angles of receiving-end voltages (VL): %.2f degrees, %.2f degrees, %.2f
degrees, %.2f degrees\n', angle(VL(1)) * (180 / pi), angle(VL(2)) * (180 / pi), angle(VL(3)) *
(180 / pi), angle(VL(4)) * (180 / pi));
Experiment #4
%% formate figure
title('Receiving end circle diagram')
xlabel('Real power axis(MW)')
ylabel('Reactive power axis (MVAR)')
axis('square')
% insert text
text(0,Y(2)+r*sin(pi/2),'\leftarrow Operating point')
text(-10,Y(2)+r*sin(pi/2)-30,'\uparrow')
text(-175,Y(2)+r*sin(pi/2)-30,'Req. MVAR')
text(-150,-70,'Beta-alpha')
text(-20,-350,'|A/B||Vr|^2')
text(200,-450,' r=|Vs||Vr|/|B|')
% end of code %
Ex.2.
Write a computer problem to draw power circle diagram and solve the following:
A 275 kV, three-phase line has the following line parameters:
(b) The maximum power that can be delivered if the sending-end voltage is
(c) The additional MVA that has to be provided at the receiving-end when
delivering 400 MVA at 0.8 lagging pf, the supply voltage being
%% format figure
title('Receiving end circle diagram (a)')
xlabel('Real power axis(MW)')
ylabel('Reactive power axis (MVAR)')
axis('square')
% insert text
text(x2(1),x2(2),'\leftarrow Operating point')
text(-150,-70,'Beta-alpha')
text(-180,-230,'|A/B||Vr|^2')
text(50,-350,' r=|Vs||Vr|/|B|')
str=num2str(r)
text(100,-270,str)
str=['Vs = ' num2str(Vs)]
text(400,50,str)
%% part b)
x0=[0,0];
beta=77
alpha=1.5
A=0.93
B=115
Vr=275
%Vs=Vr
ang=(180+(beta-alpha))*pi/180
M=A*Vr^2/B
[x,y]=pol2cart(ang,M)
x1=[x,y]
X=[x0(1) x1(1)]
Y=[x0(2) x1(2)]
figure1 = figure;
plot(X,Y,'LineWidth',1)
line([0,0],[-600,200],'color','g')
line([-200,600],[0,0],'color','g')
grid on
title('Receiving end circle diagram (b)')
xlabel('Real power axis(MW)')
ylabel('Reactive power axis (MVAR)')
axis('square')
text(-150,-70,'Beta-alpha')
text(-180,-230,'|A/B||Vr|^2')
In the circuit of Fig.5.1. let R = 0.125Ω , L = 10 mH, and the source voltage be given by:
Determine the current response after closing the switch for the following cases.
(a) No dc offset.
(b) For maximum de offset.
clc
clear all
close all
r=0.125
l=0.01
f=60
Vm=151
gama=atan(2*pi*f*l/r)
alpha1=gama
alpha2=gama-(pi/2)
Z=r+(i*2*pi*f*l)
w=2*pi*f
t=0:0.001:3
tau=l/r
Im= abs(Vm/Z)
i1= Im.*sin((w.*t)+alpha1-gama)-(Im.*exp(-t./tau).*sin(alpha1-gama))
i2= Im.*sin((w.*t)+alpha2-gama)-(Im.*exp(-t./tau).*sin(alpha2-gama))
subplot(2,1,1), plot(t,i1)
xlabel('t, sec'), ylabel('i(t), ampere')
subplot(2,1,2), plot(t,i2)
xlabel('t, sec'), ylabel('i(t), ampere')
Ex.2
Determine the current response after closing the switch for the following cases.
(a) No dc offset.
(b) For maximum de offset.
clear all
close all
clc
Vrms=230; % rms value of the voltage source %
Vmax=sqrt(2)*Vrms; % peak value of the voltage source %
f=50; % source frequency in Hz %
r=0.001; % resistance of the transmission line %
l=0.36e-3; % inductance of the transmission line in mH %
tc=l/r; % time constant of the rl series circuit %
w=2*pi*f; % angular frequency in radian per seconds %
x=w*l; % reactance of the transmission line ohms %
z=r+x*1i; % impedance of the transmission line in ohms %
zmag=abs(z); % magnitude of the impedance of the transmission line%
theta=angle(z); % phase angle of the transmission line %
alpha=0; % alpha in radian %
t=0:0.0001:2.5;
Iac=(Vmax/zmag)*sin((w*t)+alpha-theta) % sinusoidal component of the
current %
Idc=-(Vmax/zmag)*exp((-r*t)/l)*sin(alpha-theta); % dc offset component of
the current %
It=Iac+Idc; % current as a function of time in RL circuit %
Result
It_m2 = 5.7518e+003
It_max = 5.6729e+003
Experiment #6
Vrms = 230 V
Xd’’ = 0.15 Ω
Xd’ = 0.24 Ω
Xd = 1.1 Ω
α =0
Td’’ = 0.035 S
Td’ = 2.0 S
f = 50 Hz
clear all
close all
clc
Vrms=230; % rms value of the voltage source %
Vm=sqrt(2)*Vrms; % peak value of the voltage source %
Xdst=0.15; % subtransient reactance in ohms %
Xdt=0.24; % subtransient reactance in ohms %
Xd=1.1; % transient reactance in ohms %
alpha=0; % alpha in radian %
Tdst=0.035/1; % direct axis short-circuit subtransient time constant in seconds %
Tdt=2.0/1; % direct axis short-circuit transient time constant in seconds %
f=60; % system frequency in Hz %
w=2*pi*f; % angular frequency in radian per second %
t=0:0.001:15;
Excercise:
Use a separate sheet of paper to write a program for the following numerical problem data also
paste the result of the program.
Obtain the short circuit solution for a three-phase solid fault on bus 4 (load bus).
Assume prefault voltages to be 1 pu and prefault currents to be zero.
1,Fig.7.3 on-line diagram
YBUS data:
From To R XL G
Bus Bus
1 2 0 0.2 0.15
1 3 0 0.15 0
1 4 0 0.1 0
2 3 0 0.1 0
2 4 0 0.15 0
Solution:
Computer program:
Result:
ybus =
zbus =
If =
0 - 7.3740i
Bus voltage obtained in matrix form are
V=
0.4244
0.4695
0.4515
0
Experiment #8
Write a computer program to analyze unbalanced phasors. Compute and plot symmetrical
components using above expressions for the following data:
Write a computer program for the animation of traveling wave having following data of
numerical:
Consider a transmission line with length of 400 km having sending end voltage 220 kV, 50 Hz,
3-phase transmissionline having defined by line parameters r = 0.125 Ω/km, x = 0.4 Ω/km, and y
= 2.8X10-06 mho/km.
With α = 0.163X10-3 and β = 1.068X103
Solution:
clc
clear all
close all
% length of transmission line
len=400
% varry length of Tx line from 0 to len
x=0:0.1:len
% given data
Vr=220
Zc=400
Ir=00 % no load condition
alpha=0.163e-3*15 %assuming higher value for understanding purpose
beta=1.068e-3*50 %assuming higher value for understanding purpose
gma=alpha+i*beta
A1=((Vr+Zc*Ir)/2)
A2=((Vr-Zc*Ir)/2)
w=2*pi*50
Exercise:
Write a computer program to verify power invariance for symmetrical components for the
following data:
Va = 568.3121 + j369.9066
Vb = -305.6848 - j406.7205
Vc = -222.6273 + j36.8139
Ia = 1.7754 + j0.8157
Ib = -4.0194 - j13.1284
Ic = -5.8983 - j5.6112
clear all
close all
clc
% Create matrix A with elements [1 1 1; 1 a^2 a; 1 a a^2] to transform unbalanced voltage and
current to symmetrical components
A=[1 1 1;1 a2 a;1 a a2];