Assignment 1
Assignment 1
Section-EA (Power)
function [cost, solution] = PSO_Economic_Dispatch(A, PD, Pmin, Pmax, B, population_size, max_iterations, w, c1, c2)
% 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;
% Output
cost = gBest_cost;
solution = gBest_position;
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):
% 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.