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

% Load the Matpower case file

mpc = loadcase('case30'); % Load a sample case file (you can use your own case
file)

% Initial load condition


initialLoad = mpc.bus(:, 3); % Initial load in MW
loadIncrease = 0.1; % 10% load increase
maxIterations = 100; % Maximum number of iterations

% Perform power flow analysis with initial load


results = runopf(mpc);
Pg = mpc.gen(:, 2);
[BL2, BL1, BL0] = makeBloss(mpc);
loss = (0.5 * Pg' * BL2 * Pg + BL1' * Pg + BL0 )
Pf = 1 ./ (1 - BL2 * Pg + BL1)
% Loop for load increase until convergence
for i = 1:maxIterations
if results.success
% Increase load by 10%
newLoad = initialLoad * (1 + loadIncrease);

% Update the load in the power system case


mpc.bus(:, 3) = newLoad;

% Perform power flow analysis with increased load


results = rundcpf(mpc);
Pg = mpc.gen(:, 2);
[BL2, BL1, BL0] = makeBloss(mpc);
loss = (0.5 * Pg' * BL2 * Pg + BL1' * Pg + BL0 )
Pf = 1 ./ (1 - BL2 * Pg + BL1)
if ~results.success
disp('Power flow did not converge. Exiting loop.');
break;
end

% Update initial load for the next iteration


initialLoad = newLoad;
else
disp('Power flow did not converge. Exiting loop.');
break;
end
end

You might also like