MATLAB

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

% Define RLC circuit parameters

R = 100; % Resistance (in ohms)


L = 0.1; % Inductance (in Henry)
C = 1e-3; % Capacitance (in Farads)

% Calculate damping frequency and damping ratio


omega_n = 1 / sqrt(L * C); % natural frequency
R_crit = 2 * sqrt(L / C); % critical resistance
zeta = R / R_crit; % damping ratio
omega_d = omega_n * sqrt(1 - zeta^2); % damping frequency

% Define the transfer function of the RLC circuit


num = [1];
den = [L*C, R*C, 1];
sys = tf(num, den);

% Simulate the transient response of the RLC circuit


t = 0:0.001:2; % Time vector
u = zeros(size(t)); % Input signal (zero for transient response)
[y, t] = lsim(sys, u, t); % Simulate the system response

% Plot the transient response


figure;
plot(t, y);
xlabel('Time (s)');
ylabel('Output');
title('Transient Response of RLC Circuit');

% Display damping frequency and damping ratio


fprintf('Damping Frequency: %f rad/s\n', omega_d);
fprintf('Damping Ratio: %f\n', zeta);
% Open-Circuit Test Data
V_oc = [50, 100, 150, 200]; % Open-Circuit Voltages (V)
I_oc = [0.5, 0.7, 0.9, 1.2]; % Open-Circuit Currents (A)

% Short-Circuit Test Data


V_sc = [5, 10, 15, 20]; % Short-Circuit Voltages (V)
I_sc = [10, 20, 30, 40]; % Short-Circuit Currents (A)

% Rated Voltage and Current


V_rated = 220; % Rated Voltage (V)
I_rated = 10; % Rated Current (A)

% Calculating Equivalent Circuit Parameters


% Calculate magnetizing impedance (Zm) from OC test
Zm = V_oc ./ I_oc;

% Calculate equivalent resistance (Req) from SC test


Req = V_sc ./ I_sc;

% Calculate equivalent leakage reactance (Xeq)


Xeq = sqrt((Zm .^ 2) - (Req .^ 2));

% Calculate equivalent series resistance (R)


R = Req * (V_rated / V_sc(1))^2;

% Calculate equivalent series reactance (X)


X = Xeq * (V_rated / V_sc(1))^2;

% Displaying Equivalent Circuit Parameters


fprintf('Equivalent Series Resistance (R): %.4f ohms\n', R);
fprintf('Equivalent Series Reactance (X): %.4f ohms\n', X);
fprintf('Equivalent Leakage Reactance (Xeq): %.4f ohms\n',
Xeq);
fprintf('Magnetizing Impedance (Zm): %.4f ohms\n', Zm);
% Parameters
V_source = 230; % Source voltage (kV)
R_line = 0.1; % Resistance per unit length of the line (ohms/km)
L_line = 1e-3; % Inductance per unit length of the line (H/km)
C_line = 1e-6; % Capacitance per unit length of the line (F/km)
length_line = 100; % Length of the transmission line (km)
load_power = 100; % Load power (MW)
load_pf = 0.8; % Load power factor

% Calculations
Z_line = R_line + 1i*2*pi*50*L_line; % Line impedance
Y_line = 1i*2*pi*50*C_line; % Line admittance
Z_load = (V_source^2) / (load_power * load_pf); % Load
impedance

% Simulation
distance = linspace(0, length_line, 1000); % Distance along the
line
V_received = zeros(size(distance)); % Received voltage array

for i = 1:length(distance)
Z_total = Z_line * distance(i) + Z_load; % Total impedance
Y_total = Y_line * distance(i); % Total admittance
I_received = V_source / Z_total; % Current received at this
point
V_received(i) = V_source - I_received * Z_total * distance(i);
% Voltage received at this point
end

% Plotting
figure;
plot(distance, abs(V_received) / 1000); % Plot voltage profile
(kV)
xlabel('Distance (km)');
ylabel('Voltage (kV)');
title('Voltage Profile along the Transmission Line');
grid on;

% Parameters
R_line = 0.1; % Resistance per unit length of the line (ohms/km)
L_line = 1e-3; % Inductance per unit length of the line (H/km)
C_line = 1e-6; % Capacitance per unit length of the line (F/km)
G_line = 1e-9; % Conductance per unit length of the line (S/km)
length_line = 100; % Length of the transmission line (km)
f = 50; % Frequency (Hz)
% Simulation parameters

num_segments = 1000; % Number of segments to divide the line

% Calculate segment length


segment_length = length_line / num_segments;

% Initialize matrices for voltage and current


V = zeros(num_segments, 1); % Voltage (V)
I = zeros(num_segments, 1); % Current (A)

% Iterate over segments


for i = 2:num_segments
% Calculate voltage and current for each segment using transmission
line equations
V(i) = V(i-1) + segment_length * (R_line * I(i-1) + L_line * (I(i) - I(i-
1)) / segment_length);
I(i) = I(i-1) + segment_length * (G_line * V(i) + C_line * (V(i) - V(i-
1)) / segment_length);
end

% Plot results
distance = linspace(0, length_line, num_segments);
figure;
subplot(2, 1, 1);
plot(distance, abs(V));
xlabel('Distance (km)');
ylabel('Voltage (V)');
title('Voltage Profile along the Transmission Line');
grid on;
subplot(2, 1, 2);
plot(distance, abs(I));
xlabel('Distance (km)');
ylabel('Current (A)');
title('Current Profile along the Transmission Line');
grid on;

% Parameters
R_line = 0.1; % Resistance per unit length of the line (ohms/km)
L_line = 1e-3; % Inductance per unit length of the line (H/km)
C_line = 1e-6; % Capacitance per unit length of the line (F/km)
G_line = 1e-9; % Conductance per unit length of the line (S/km)
length_line = 100; % Length of the transmission line (km)
f = 50; % Frequency (Hz)

% Calculate ABCD parameters


Z0 = sqrt((R_line + 1i*2*pi*f*L_line) / (G_line +
1i*2*pi*f*C_line)); % Characteristic impedance
gamma = sqrt((R_line + 1i*2*pi*f*L_line) * (G_line +
1i*2*pi*f*C_line)); % Propagation constant

% ABCD matrix
A = cosh(gamma * length_line);
B = Z0 * sinh(gamma * length_line);
C = (1/Z0) * sinh(gamma * length_line);
D = A;

% Display ABCD parameters


fprintf('ABCD Parameters for the medium transmission line:\n');
fprintf('A = %.4f\n', A);
fprintf('B = %.4f\n', B);
fprintf('C = %.4f\n', C);
fprintf('D = %.4f\n', D);
% Parameters
R_line = 0.1; % Resistance per unit length of the line (ohms/km)
L_line = 1e-3; % Inductance per unit length of the line (H/km)
C_line = 1e-6; % Capacitance per unit length of the line (F/km)
G_line = 1e-9; % Conductance per unit length of the line (S/km)
length_line = 100; % Length of the transmission line (km)
num_segments = 1000; % Number of segments to divide the
line
f = 50; % Frequency (Hz)

% Calculate segment length


segment_length = length_line / num_segments;

% Initialize ABCD parameters


A_total = 1;
B_total = 0;
C_total = 0;
D_total = 1;

% Calculate ABCD parameters for each segment


for i = 1:num_segments
Z = sqrt((R_line + 1i*2*pi*f*L_line) / (G_line +
1i*2*pi*f*C_line)) * segment_length; % Characteristic
impedance
gamma = sqrt((R_line + 1i*2*pi*f*L_line) * (G_line +
1i*2*pi*f*C_line)); % Propagation constant
A = cosh(gamma * segment_length);
B = Z * sinh(gamma * segment_length);
C = (1/Z) * sinh(gamma * segment_length);
D = cosh(gamma * segment_length);
% Multiply ABCD matrices
ABCD_segment = [A, B; C, D];
ABCD_total = [A_total, B_total; C_total, D_total];
ABCD_total = ABCD_segment * ABCD_total;
% Update ABCD parameters for the total line
A_total = ABCD_total(1, 1);
B_total = ABCD_total(1, 2);
C_total = ABCD_total(2, 1);
D_total = ABCD_total(2, 2);
end

% Display ABCD parameters for the total line


fprintf('ABCD Parameters for the long transmission line
network:\n');
fprintf('A = %.4f\n', A_total);
fprintf('B = %.4f\n', B_total);
fprintf('C = %.4f\n', C_total);
fprintf('D = %.4f\n', D_total);

You might also like