MATLAB Answers

Help regarding Lambad iteration - Simple Question

2 views (last 30 days)
Hrishikesh Dalal
Hrishikesh Dalal on 28 Oct 2019
Answered: Vimal Rathod on 31 Oct 2019
Here is a code where in i am doing Lambda Iteration to find economic dispatch. I am not very good with arrays. All i want to do is log the values of lambda for each load (length of load = 1152) so i should have 1152 lambda values. Attachimg whole code as well.
for i=1:1:length(Load)
%step 1 initial value
lambda=(Alpha(1)*(Load(i,1)/2))+Beta(1);
last_lambda = lambda;
vector_lab = [vector_lab lambda];
while e>error
lambda2 = lambda-Beta;
Therta=diag(Alpha);
Powers = inv(Therta)*lambda2';
% P = Powers.*Cm';
% P = max(P,Gmax);
% P = min(P,Gmin);
PL = 0
last_power = total_power;
total_power = sum(Powers);
total_demand_loss = PL + Load;
e=abs(total_power(i)'-total_demand_loss(i));
if (length(vector_lab)<2)
lambda(i)=lambda*increase;
else
lambda=lambda + ((lambda-last_lambda)./(total_power-last_power)).*(total_demand_loss-total_power);
end
vector_lab = [vector_lab lambda(i)];
if (length(vector_lab)>1)
last_lambda = vector_lab(length(vector_lab)-1);
end
%% Powers
P_C11=(lambda-1.31)/(2*0.028);
P_C12=(lambda-1.31)/(2*0.028);
P_C13=(lambda-1.55)/(2*0.036);
P_C14=(lambda-1.31)/(2*0.028);
P_C15=(lambda-1.31)/(2*0.028);
%Bio Unit 1's
P_B11=(lambda-1.10)/(2*0.048);
P_B12=(lambda-1.10)/(2*0.048);
P_B13=(lambda-1.10)/(2*0.048);
P_B14=(lambda-1.10)/(2*0.048);
P_B15=(lambda-1.10)/(2*0.048);
%Coal Unit 2's
P_C21=(lambda-1.55)/(2*0.036);
P_C22=(lambda-1.55)/(2*0.036);
P_C23=(lambda-1.55)/(2*0.036);
P_C24=(lambda-1.55)/(2*0.036);
P_C25=(lambda-1.55)/(2*0.036);
%Nuclear Unit 2
P_N2=(lambda-2.4)/(2*0.028);
% Bio Gas Unit 2's
P_B21=(lambda-1.25)/(2*0.056);
P_B22=(lambda-1.25)/(2*0.056);
P_B23=(lambda-1.25)/(2*0.056);
P_B24=(lambda-1.25)/(2*0.056);
P_B25=(lambda-1.25)/(2*0.056);
%Hydro Unit 2
P_H2=(lambda-1)/(2*0.04);
%Gas Unit 2
P_G21=(lambda-1.8)/(2*0.08);
P_G22=(lambda-1.8)/(2*0.08);
P_G23=(lambda-1.8)/(2*0.08);
P_G24=(lambda-1.8)/(2*0.08);
P_G25=(lambda-1.8)/(2*0.08);
P_G26=(lambda-1.8)/(2*0.08);
P_G27=(lambda-1.8)/(2*0.08);
P_G28=(lambda-1.8)/(2*0.08);
P_G29=(lambda-1.8)/(2*0.08);
P_G210=(lambda-1.8)/(2*0.08);
%Nuclear Unit 1
P_N1=(lambda-2)/(2*0.035);
%Hydro Unit 1
P_H1=(lambda-1.2)/(2*0.05);
%Gas Unit 1
P_G11=(lambda-2.7)/(2*0.075);
P_G12=(lambda-2.7)/(2*0.075);
P_G13=(lambda-2.7)/(2*0.075);
P_G14=(lambda-2.7)/(2*0.075);
P_G15=(lambda-2.7)/(2*0.075);
P_G16=(lambda-2.7)/(2*0.075);
P_G17=(lambda-2.7)/(2*0.075);
P_G18=(lambda-2.7)/(2*0.075);
P_G19=(lambda-2.7)/(2*0.075);
P_G110=(lambda-2.7)/(2*0.075);
Pm = [P_C11,P_C12,P_C13,P_C14,P_C15,P_B11,P_B12,P_B13,P_B14,P_B15,P_C21,P_C22,P_C23,P_C24,P_C25,P_N2,P_B21,P_B22,P_B23,P_B24,P_B25,P_H2,P_G21,P_G22,P_G23,P_G24,P_G25,P_G26,P_G27,P_G28,P_G29,P_G210,P_N1,P_H1,P_G11,P_G12,P_G13,P_G14,P_G15,P_G16,P_G17,P_G18,P_G19,P_G110];
P=Pm.*Cm;
end
end

  0 Comments

Sign in to comment.

Answers (1)

Vimal Rathod
Vimal Rathod on 31 Oct 2019
Hi,
You could declare a variable outside the loop and initialize its values with “length(Load)” number of zeros using zeros function.
Then in the for loop assign lambda value to the variable in each iteration. You can also use save command to save the variable in a specific file.
Refer to the following link for saving workspace variables into files:
Hope this helps!

  0 Comments

Sign in to comment.

Sign in to answer this question.