You are on page 1of 4

MATLAB CODE:

clear
clc
close all

%initializing the input values


v = 10*sqrt(2); %AC voltage
r = 5; %resistance
x_l = 5j; %inductance
f = 50; %frequency of the AC input
system = 1; %variable to differentiate between system 1 and system 2

%calculation of angular frequency and time period


w = 2*pi*f; %angular frequency
t = 1/f; %time period

%declaration of loop arrays


v_t = zeros(1,101); %instantaneous voltage
i_t = zeros(1,101); %instantaneous current
p_s = zeros(1,101); %instantaneous supply power
p_r = zeros(1,101); %instantaneous resistive power
pf = 0; %power factor
t1 = (0 : t/100 : t); %testing time
p_real = 0; %real power

%loop
for h = 1:101
v_t(h) = v * sin(w * t(h));
if system == 1
i_t(h) = v_t(h) / ((r * x_l) / (r + x_l));
p_r(h) = (v_t(h) ^ 2) / r;
elseif system == 2
i_t(h) = v_t(h) / (r + x_l);
p_r(h) = ((abs(i_t(h))) ^ 2) * r;
end
p_s(h) = v_t(h) * i_t(h);
pf = pf + abs(cos(angle(i_t(h))));
p_real = p_real + abs(p_r(h));
end

%calculation
p_avg = p_real / 101; %average real power consumption
pf_avg = pf / 101; %average power factor

%plotting of graphs
%instantaneous resistive load power versus time
figure
plot(t, p_r);
xlabel(‘Time’);
ylabel(‘Instantaneous Resistive Power’);
grid on;
%instantaneous supply power versus time
figure
plot(t, abs(p_s));
xlabel(‘Time’);
ylabel(‘Instantaneous Supply Power’);
grid on;

OUTPUT:

System 1:
System 2:
RESULT:
Thus, the given problem was analysed using MATLAB and the output was recorded.

You might also like