[英]Nested loop for summation for different values of x and y
我應該對x和y分別為1到5和1到4的值做1到5求和的嵌套循環。 我應該將值表示為矩陣(4,5)。 但是我不能打印矩陣。
for x=1:5
for y=1:4
for n=1:5
Tmat=zeros(5,4)
T=0;
T(x,y)=T+((4*T1)/pi)*sin((2*n-1)*((pi*x)/a))/(2*n-1)*sinh((2*n-1)*((pi*y)/a))/sinh((2*n-1)*((pi*b)/a));
Tmat=T(x,y)
end
end
end
如果我正確理解您的問題,也許這就是您想要的:
T1=1; a=1; b=1;
Tmat=zeros(5,4);
for x=1:5
for y=1:4
for n=1:5
%// Because we're summing, Tmat(x,y) gets increased for each n
Tmat(x,y)=Tmat(x,y) + ((4*T1)/pi)*sin((2*n-1)*((pi*x)/a))/(2*n-1)*sinh((2*n-1)*((pi*y)/a))/sinh((2*n-1)*((pi*b)/a));
end
end
end
請注意,我不知道您想要的T1,a或b值,因此我輸入了虛擬數據。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.