CEP MATLAB Codes
CEP MATLAB Codes
Section: EA (Power)
(b) Part 2: (WP2,WP3, WP4, EP2) - 10 marks • Design a lambda iteration program that can
solve the Lagrange function you have formulated in Q3 to find the incremental cost and the
power generated by each plant.
% Given data
Pd = 200; % Total load demand
% Initialize Lambda
lambda_min = min(A(:, 2)); % Minimum b value
lambda_max = max(A(:, 2)); % Maximum b value
lambda = (lambda_min + lambda_max) / 2;
iter = 0;
while iter < maxIter
% Calculate power generation for each unit
P = max(Pmin, min(Pmax, (lambda - A(:, 2)) ./ (2 * A(:, 3))));
% Update Lambda
if deltaP > 0
lambda_min = lambda;
else
lambda_max = lambda;
end
lambda = (lambda_min + lambda_max) / 2;
iter = iter + 1;
end
% Display results
if iter == maxIter
disp('Lambda Iteration did not converge.');
else
fprintf('Lambda Iteration converged in %d iterations.\n', iter);
fprintf('Lambda = %.6f\n', lambda);
fprintf('Power generation for each unit (MW):\n');
for i = 1:length(P)
fprintf('P%d = %.4f\n', i, P(i));
end
end
The Output:
(c) Part 3: (WP2, WP3, WP4, WP5) - 20 marks • Compute the Transmission Line Loss
Coefficients, reformulate the Economic Load Dispatch problem along with the Lagrange
function and use lambda iterative method to find the new set of generated powers.
% Power demand
Pd = 200;
% Adjust lambda
if P_total > Pd + P_loss
lambda = lambda - d_lambda;
else
lambda = lambda + d_lambda;
end
end
% Display results
fprintf('Lambda: %.5f\n', lambda);
fprintf('Iterations: %d\n', iter);
fprintf('Generator Outputs (MW):\n');
fprintf('P1: %.2f\n', P(1));
fprintf('P2: %.2f\n', P(2));
fprintf('P3: %.2f\n', P(3));
fprintf('Total Generation: %.2f MW\n', P_total);
fprintf('Transmission Losses: %.2f MW\n', P_loss);
fprintf('Total Demand + Losses: %.2f MW\n', Pd + P_loss);
The Output: