for j=1:nj if (j==1) z=1; elseif(j==nj) z=H-1; else z=(j-1)*dz; end for k=1:nj if(k==1) a=0; b=dz/2; elseif(k==nj) a=H-dz/2; b=H; else a=(2*k-3)*dz*0.5; b=(2*k-1)*dz*0.5; end end end向量化
时间: 2024-01-15 10:05:49 浏览: 151
欧姆龙CJ系列I_O控制单元_I_O接口单元 CJ1W-IC_II.pdf
以下是向量化后的代码:
```
j = 1:nj;
z = (j-1) * dz;
z(1) = 1;
z(nj) = H-1;
k = 1:nj;
a = zeros(1,nj);
b = zeros(1,nj);
a(k==1) = 0;
b(k==1) = dz/2;
a(k==nj) = H-dz/2;
b(k==nj) = H;
a(~(k==1 | k==nj)) = (2*k(~(k==1 | k==nj))-3)*dz*0.5;
b(~(k==1 | k==nj)) = (2*k(~(k==1 | k==nj))-1)*dz*0.5;
```
阅读全文