Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
    3 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
    Muhammad Ezree Amree bin Amran
 il 4 Gen 2021
  
    
    
    
    
    Commentato: KSSV
      
      
 il 4 Gen 2021
            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.
costI(:,i)=alpha+(beta.*P)+(gamma.*P.*P);
Attached below is my full coding, can you guys help me?
% n all alpha beta gamma min max
d=[1	671	10.100	0.000299 150 455
   2	574	10.200	0.000183 150 455
   3	374	8.8000	0.001126 20  130
   4	374	8.8000	0.001126 20	 130
   5	461	10.400	0.000205 150 470
   6	639	10.100	0.000301 135 460
   7	548	9.8000	0.000364 135 465
   8	227	11.200	0.000338 60	 300
   9	173	11.200	0.000807 25	 162
   10	175	10.700	0.001203 25	 160
   11	186	10.200	0.000371 20	 80
   12	230	9.9000	0.001929 20	 80
   13	225	13.100	0.004447 25	 85
   14   309 12.100  0.001929 15  55
   15   323 12.400  0.004447 15  55];
Pd=2630; %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)')
0 Commenti
Risposta accettata
  KSSV
      
      
 il 4 Gen 2021
        This problem occurs when you try to save more number of elements than it is intialized for. This line:
costI(:,i)=alpha+(beta.*P)+(gamma.*P.*P); 
Check the dimensions/ size of RHS and do the intialization properly. 
Demo:
A = zeros(3,3) ;   % A should be 3X3 matrix 
A(:,1)  = rand(1,3) ;   % no error as you are saving three elements 
A(:,2) = rand(1,4) ;   % error as you are saving more number of elements. 
4 Commenti
  KSSV
      
      
 il 4 Gen 2021
				Thanks is accepting/ voting the answer. 
When you are storing the values from a loop, get the dimensions and initialize the variable properly for good performance of the code. 
Più risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!