Vectors must be the same length.

조회 수: 2 (최근 30일)
Muhammad Ezree Amree bin Amran
Muhammad Ezree Amree bin Amran 2021년 1월 4일
답변: Cris LaPierre 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.
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) >0
L=Lamda(i,1)+(Lamda(i,1))*(0.1);
i=i+1;
Iteration(i,1)=i;
Lamda(i,1) =L;
elseif e(i,1) <0
L=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);
figure
plot(Iteration,totalCost_iteration);
title('Convergest Graph')
xlabel('Number of Iteration')
ylabel('Cost(RM/h)')
  댓글 수: 1
Timo Dietz
Timo Dietz 2021년 1월 4일
편집: Timo Dietz 2021년 1월 4일
?? The code works fine for me (Matlab2018a) - no error message, plot is done.

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

채택된 답변

Cris LaPierre
Cris LaPierre 2021년 1월 4일
I suspect the issue is with your opening line. It is currently clearing a variable named clc. I suspect your intent is to clear your workspace and clear you command window. If that is the case, you must either put each command on its own line, or separate the two with a comma or semicolon.
clear
clc
clear, clc
clear; clc
% Not this. The purple text indicates clc is being treated as text
clear clc

추가 답변 (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