Matrix dimensions must agree.

조회 수: 3 (최근 30일)
Muhammad Ezree Amree bin Amran
Muhammad Ezree Amree bin Amran 2021년 1월 4일
댓글: Alan Stevens 2021년 1월 4일
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.
P=(Lamda-beta)./(gamma*2);
Attached below is my full coding, can you guys help me?
clear clc;
% n all 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);
DelP=Pd; i=1;
Iteration=i;
Lamda=8.35; % assume lambda L(i,1)=Lamda;
while abs(DelP)> 0.00001
P=(Lamda-beta)./(gamma*2);
P=min(P,Pmax); %p=ph if pmax<p//p>pmax //pick pmax bila pmax kecil dri p
P=max(P,Pmin); %p=pl if pmin>p//p<pmin
DelP=Pd-sum(P); Lamda=Lamda+DelP/(sum(1./(2*gamma)));
costI(:,i)=alpha+(beta.*P)+(gamma.*P.*P);
totalCost_iteration(i,1)=sum(costI(:,i));
Iteration(i,1)=i;
Lamda(i,1)=Lamda;
i=i+1;
end
Cost=alpha+(beta.*P)+(gamma.*P.*P); % Costs totalCost=sum(Cost);
totalPower=sum(P); table(d(:,1),P,Cost,'V',{'Unit' 'Power' 'Cost'})
display(totalCost);
display(totalPower);
figure
plot(Iteration,totalCost_iteration)
title('Convergest Graph')
xlabel('Number of Iteration')
ylabel('Cost(RM/h)')

채택된 답변

Alan Stevens
Alan Stevens 2021년 1월 4일
This works
% n all 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);
DelP=Pd; i=1;
Iteration=i;
Lamda=8.35; % assume lambda L(i,1)=Lamda;
while abs(DelP)> 0.00001
P=(Lamda-beta)./(gamma.*2);
P=min(P,Pmax); %p=ph if pmax<p//p>pmax //pick pmax bila pmax kecil dri p
P=max(P,Pmin); %p=pl if pmin>p//p<pmin
DelP=Pd-sum(P); Lamda=Lamda+DelP/(sum(1./(2*gamma)));
costI(:,i)=alpha+(beta.*P)+(gamma.*P.*P);
totalCost_iteration(i,1)=sum(costI(:,i));
Iteration(i,1)=i;
% Lamda(i,1)=Lamda; % This causes a problem during the iterations
i=i+1;
end
Cost=alpha+(beta.*P)+(gamma.*P.*P); % Costs
totalCost=sum(Cost); %%%%%%%%%%%%%%%%%%%
totalPower=sum(P); table(d(:,1),P,Cost,'V',{'Unit' 'Power' 'Cost'})
display(totalCost);
display(totalPower);
figure
plot(Iteration,totalCost_iteration)
title('Convergest Graph')
xlabel('Number of Iteration')
ylabel('Cost(RM/h)')
  댓글 수: 2
Muhammad Ezree Amree bin Amran
Muhammad Ezree Amree bin Amran 2021년 1월 4일
Omg, thank you so much. I'm still wondering which part of it is wrong.
but thank you so much, Sir. Thank you.
Alan Stevens
Alan Stevens 2021년 1월 4일
This was the line causing the probem
Lamda(i,1)=Lamda;

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by