フィルターのクリア

Replacing for loop with matrix math to increase computational efficiency.

1 回表示 (過去 30 日間)
Dhruv Thakkar
Dhruv Thakkar 2020 年 5 月 17 日
回答済み: darova 2020 年 5 月 17 日
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

回答 (1 件)

darova
darova 2020 年 5 月 17 日
You can increase for loop step
You are overwriting same values all the time. THere is no need of it

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by