Replacing for loop with matrix math to increase computational efficiency.
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
I am using the following code to compute the Sx, Su, Sw and Sd matrices. But I have found out them to be very computationally expensive and also I understand there is a better way to do this. Can anyone please suggest how these computations can be done more efficiently? I am also considering converting these matrices to sparce matrices after assignment for the further calculations.
N = pred_horizon/Ts; % N = 500
Sx = zeros(8*(N+1),8);
Su = zeros(8*(N+1),8*(N));
Sw = zeros(8*(N+1),8*(N));
Sd = zeros(8*(N+1),1);
for i=1:(length(Sx)-7)
Sx(i:i+7,:) = power(Ad,(i-1));
end
for i=2:size(Su,1)-7
for j=1:min((i-1),size(Su,2)-7)
Su(i:i+7,j:j+7) = power(Ad,(i-j-1))*Bd;
end
end
for i=2:size(Sw,1)-7
for j=1:min((i-1),size(Sw,2)-7)
Su(i:i+7,j:j+7) = power(Ad,(i-j-1))*Ed;
end
end
for i=2:length(Sd)-7
Sd(i:i+7,:) = power(Ad,i-2)*Dd;
end
0 Commenti
Risposte (1)
darova
il 17 Mag 2020
You can increase for loop step
You are overwriting same values all the time. THere is no need of it
0 Commenti
Vedere anche
Categorie
Scopri di più su String in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!