Name: Hafiz Waqar Ahmad Bhatti
Reg. No: L1F20BSEE0053
Section-EA (Power)
Assignment-1 (Power System operation & Control)
Example-3c (allen j. wood)
Economic Dispatch Problem with considered Transmission network losses
Matlab Code (Particle Swarm Optimization):
function [cost, solution] = PSO_Economic_Dispatch(A, PD, Pmin, Pmax, B, population_size, max_iterations, w, c1, c2)
% Particle Swarm Optimization for Economic Dispatch with losses
A = [510.0 7.2 0.00142; 310.0 7.85 0.00194; 78.0 7.97 0.00482]; % Cost Coeffcients
PD = 850; % Power Demand
pmax = [600; 400; 200];
pmin = [150; 100; 50];
B = [0.00003,0.00009,0.00012]; % Loss Coefficients
population_size = 50;
max_iterations = 1000;
w = 0.8;
c1 = 1.8;
c2 = 1.9;
% Initialize particle positions and velocities
num_generators = size(A, 1);
swarm_size = population_size;
positions = rand(swarm_size, num_generators) .* (Pmax - Pmin) + Pmin;
velocities = rand(swarm_size, num_generators) .* (Pmax - Pmin);
% Initialize personal best positions and global best position
pBest_positions = positions;
pBest_costs = evaluate_cost(pBest_positions, A, PD, B);
[gBest_cost, idx] = min(pBest_costs);
gBest_position = pBest_positions(idx, :);
% Main loop
for iter = 1:max_iterations
% Update velocities and positions
r1 = rand(swarm_size, num_generators);
r2 = rand(swarm_size, num_generators);
velocities = w * velocities + c1 * r1 .* (pBest_positions - positions) + c2 * r2 .* (repmat(gBest_position, swarm_size, 1) -
positions);
positions = positions + velocities;
% Clip positions to be within the limits
positions = max(min(positions, Pmax), Pmin);
% Evaluate fitness (total cost)
costs = evaluate_cost(positions, A, PD, B);
% Update personal best positions
better_idx = costs < pBest_costs;
pBest_positions(better_idx, :) = positions(better_idx, :);
pBest_costs(better_idx) = costs(better_idx);
% Update global best position
[min_cost, idx] = min(pBest_costs);
if min_cost < gBest_cost
gBest_cost = min_cost;
gBest_position = pBest_positions(idx, :);
end
% Termination condition (optional)
% if some_condition, break; end
end
% Output
cost = gBest_cost;
solution = gBest_position;
end
function total_cost = evaluate_cost(positions, A, PD, B)
% Evaluate the total cost of generation for given positions
num_particles = size(positions, 1);
total_cost = zeros(num_particles, 1);
for i = 1:num_particles
total_cost(i) = sum(A(:, 1) + A(:, 2) .* positions(i, :)' + A(:, 3) .* positions(i, :)'.^2) ...
+ sum(B .* positions(i, :)'.^2) + PD;
pl = sum(B * (p.^2));
end
end
% Display results
disp('Economic Dispatch using Particle Swarm Optimization with losses:');
disp('Results:');
disp(['Lambda (lamda): ', num2str(lamda)]);
disp(p);
disp(['Power Losses: ', num2str(pl)]);
end
Output:
Matlab Code (Newton Method):
function [p,sump,lamda,cost]=newton_method_with_losses(cost,B,pd,p,iter)
cost=[561 7.92 0.001562;310 7.85 0.00194;78 7.97 0.00482];
B = [0.00003 0.00009 0.00012];
pd=800;
p=[300 200 300];
iter=10;
n=length(cost);
nlang=50;
j=1;
for i=1:n
a(i,1)=cost(i,1);
b(i,1)=cost(i,2);
y(i,1)=cost(i,3);
end
lamda =0;
H=[0.003124 0 0 -1;0 0.00388 0 -1;0 0 0.00964 -1;-1 -1 -1 0];
while(j<iter);
x=p';
x(4,1)=lamda;
nlang=b+2*y.*p'-lamda;
nlang(4,1)=pd-sum(p');
x=x-(inv(H)*nlang);
p=x(1:3);
p=p';
lamda=x(4,1);
sum(p);
j=j+1;
end
p=p';
sump=sum(p);
lamda;
cost=sum([sum(a) sum(b.*p) sum(y.*p.*p)]);
% Display results
disp('Economic Dispatch using Newton Method with losses:');
disp('Results:');
disp(p);
disp(['Lambda (lamda): ', num2str(lamda)]);
disp(['Power Losses: ', num2str(pl)]);
Output:
Matlab Code (Linear Programming):
% Define cost coefficients (ai, bi, ci)
A = [561, 7.92, 0.001562;
310, 7.85, 0.00194;
78, 7.97, 0.00482];
% Define power demand (PD)
PD = 850;
% Define generation limits (Pmin, Pmax)
Pmin = [150; 100; 50];
Pmax = [600; 400; 200];
% Define transmission loss coefficients (B)
B = [0.00003, 0.00009, 0.00012];
% Define objective function coefficients
f = zeros(length(A), 1);
for i = 1:length(A)
f(i) = A(i, 2) + 2 * A(i, 3) * PD + 2 * sum(B * PD^2);
end
% Define inequality constraints: Pmin <= P <= Pmax
Aeq = [];
beq = [];
lb = Pmin;
ub = Pmax;
% Solve the linear programming problem
[x, cost] = linprog(f, [], [], Aeq, beq, lb, ub);
% Display results
disp('Economic Dispatch using Newton Method with losses:');
disp('Results:');
disp(p);
disp(['Lambda (lamda): ', num2str(lamda)]);
disp(['Power Losses: ', num2str(pl)]);
Output:
Conclusion:
The Newton’s Method is the best as it optimize the Fuel Cost functions fast as compared to
Linear Programming and Particle Swarm Optimization. In simple words, Newton’s Method is
Computationally more efficient.