我已閱讀過並同意遵守討論區規則, 按這裡檢視討論區規則, 按這裡瞭解引言功能
> for m=2:101
> A(2,m)=1.2;
> end %將裡面100x100矩陣的第一行的值皆令為1.2
A(2,2:101)=1.2*ones(1,100); might work.
> A(:,102)=0;
> A(:,1)=0;
> A(1,:)=0;
> A(102,:)=0; %將第1,102行以及1,102列的值皆令為零
You already assign zeros to them when you use the function "zeros".
> for l=2:101
> A(101,l)=0.1+(0.003*(l-1)); %將裡面100x100矩陣的最後一行的值以等加級數往右邊增加
> end
A(101,2:101)=0.1:0.003:0.3;
> for i=2:101
> for j=2:101
>
> A(i,j)=0.25*(A(i+1,j)+A(i-1,j)+A(i,j+1)+A(i,j-1));
>
> end
> end
Maybe A(2:101,2:101)=A(1:100,2:101)+A(3:102,2:101)+A(2:101,1:100)+A(2:101,3:102); will work better.
Like I said, I haven't use Matlab for a long time. So I cannot guarantee my comments are correct. However, the rule of thumb is "use array operations to replace explicit loops whenever you can because that's Matlab's strength."
MSH
內文搜尋

X