Info
この質問は閉じられています。 編集または回答するには再度開いてください。
MPC code efficiency, i would like to know the possibility of improving matrix multiplication efficiency
1 回表示 (過去 30 日間)
古いコメントを表示
Say i have a controlable matrix of full rank A, i want to multiply this matrix in the form of [A,A^2,A^3,A^4........].
Here is my code
A=[0.7637 0.0873 0.0118 0.0003; -4.4281 0.6764 0.2214 0.0086; 0.4444 0.0159 0.9778 0.0621; 7.1286 0.4285 -0.3564 0.3449];
Dim=4;
N=1000000;%Horizon predicition
tic
%%Method1
Y=zeros(Dim*N,Dim);
for i=1:N
Y((i-1)*Dim+1:i*Dim,:)=A^i;
end
toc
%%Method2
tic
Y1=repmat(A,N,1);
for i=2:N
if(i<N)
Y1((i-1)*Dim+1:(i+1)*Dim,:)=repmat((mtimes(Y1((i-1)*Dim+1:i*Dim,:),A)),2,1);
elseif(i==N)
Y1((i-1)*Dim+1:(i)*Dim,:)=repmat((mtimes(Y1((i-1)*Dim+1:i*Dim,:),A)),1,1);
end
end
toc
The second method is much faster, i want to know the possibility of increasing the efficency, would some mathematical decomposition help here?
0 件のコメント
回答 (0 件)
参考
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!