How Can I Speed up a loop that solves a pde?

3 ビュー (過去 30 日間)
David Koenig
David Koenig 2014 年 11 月 21 日
コメント済み: Jan 2014 年 11 月 24 日
Hello,
I am solving the 4th order pde for plate vibration and after discretizing the pde and solving for W(x,y,t) or W(k,m,n+1) as a function of W(k,m,n) and W(k,m,n-1) I get a double for loop like
for k=3:K-3
for m=3:M-3
Wnp1(k,m)=coe(1,3)*Wn(k-2,m)...
+ coe(2,2)*Wn(k-1,m-1) + coe(2,3)*Wn(k-1,m) + coe(2,4)*Wn(k-1,m+1)...
+coe(3,1)*Wn(k,m-2) + coe(3,2)*Wn(k,m-1)+coe(3,3)*Wn(k,m)...
+coe(3,4)*Wn(k,m+1)+coe(3,5)*Wn(k,m+2)...
+coe(4,2)*Wn(k+1,m-1)+coe(4,3)*Wn(k+1,m)+coe(4,4)*Wn(k+1,m+1)...
+coe(5,3)*Wn(k+2,m)...
+cNm1*Wnm1(k,m)+SWW(k,m);
end
end
where coe is a 5x5 matrix with several zeros that contains the coefficients in the finite difference approximation to the pde and Wn(k,m) represents the displacement at position k,m at time n.
I was hoping to find a way to use matrix multiplication that might speed things up but I am stumped. Does anyone have any suggestions?
Thanks,
Dave
  1 件のコメント
Jan
Jan 2014 年 11 月 24 日
Do you pre-allocate the output Wnp1?

サインインしてコメントする。

回答 (1 件)

Zoltán Csáti
Zoltán Csáti 2014 年 11 月 24 日
When you did your calculations on paper, you probably wrote the problem as a linear system. Try to create the coefficient matrix in a vectorized manner. Or if you cannot do it, attach an image of the coeff. matrix so that we can see it.

カテゴリ

Help Center および File ExchangeGeometry and Mesh についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by