Hello everyone, can you please help me with this problem? I currently in my project's for Iterative Method. But I can't run the coding because of this problem.
plot(Iteration,totalCost_iteration);
Attached below is my full coding, can you guys help me?
clear clc;% n alpha beta gamma min max
d=[1 550 8.1000 0.00028 0 680 2 309 8.1000 0.00056 0 360 3 307 8.1000 0.00056 0 360 4 240 7.7400 0.00324 60 180 5 240 7.7400 0.00324 60 180 6 240 7.7400 0.00324 60 180 7 240 7.7400 0.00324 60 180 8 240 7.7400 0.00324 60 180 9 240 7.7400 0.00324 60 180 10 126 8.6000 0.00284 40 120 11 126 8.6000 0.00284 40 120 12 126 8.6000 0.00284 55 120 13 126 8.6000 0.00284 55 120];Pd=1800; %Pdemand
alpha=d(:,2);n=d(:,1);beta=d(:,3);gamma=d(:,4);Pmin=d(:,5);Pmax=d(:,6); i=1;Iteration=i;%set Lamda
Lamda(i,1) = 5;%step 2 -- calculate P total
P(:,i)=(Lamda(i,1)-beta)./(gamma*2);P_total(i,1) = sum(P(:,i));costI(:,i)=alpha+(beta.*P(:,i))+(gamma.*P(:,i).*P(:,i));totalCost_iteration(i,1)=sum(costI(:, i));%step 3 -- calculate error//delP
e(i,1) = Pd - P_total(i,1);%step 4 -- find new lambda
if e(i,1) >0L=Lamda(i,1)+(Lamda(i,1))*(0.1); i=i+1;Iteration(i,1)=i; Lamda(i,1) =L;elseif e(i,1) <0L=Lamda(i,1)-(Lamda(i,1))*(0.1);i=i+1; Iteration(i,1)=i; Lamda(i,1) =L;end%calculate P total for second iteration
P(:,i)=(Lamda(i,1)-beta)./(gamma*2);P_total(i,1) = sum(P(:,i));e(i,1) = Pd - P_total(i,1); costI(:,i)=alpha+(beta.*P(:,i))+(gamma.*P(:,i).*P(:,i));totalCost_iteration(i,1)=sum(costI(:, i));%step 5 -- find new lambda and P total until error =0
while abs(e(i,1))>0.00000000001 i=i+1;Iteration(i,1)=i; Lamda(i,1) =((Lamda(i-2,1)*(e(i-1,1)-e(i-2,1)))-(e(i-2,1)*(Lamda(i-1,1)-Lamda(i- 2,1))))./(e(i-1,1)-e(i-2,1));P(:,i)=(Lamda(i,1)- beta)./(gamma*2);P_total(i,1) = sum(P(:,i));e(i,1) = Pd - P_total(i,1);costI(:,i)=alpha+(beta.*P(:,i))+(gamma.*P(:,i).*P(:,i));totalCost_iteration(i,1)=sum(costI(:, i));end%find total cost and total power
cost=alpha+(beta.*P(:,i))+(gamma.*P(:,i).*P(:,i));TotalCost=sum(costI(:,i)); Totalpower= sum(P(:,i));table(d(:,1),P(:,i),cost,'V',{'Unit' 'Power' 'Cost'})display(TotalCost); display(Totalpower);figureplot(Iteration,totalCost_iteration);title('Convergest Graph') xlabel('Number of Iteration') ylabel('Cost(RM/h)')
Best Answer