matlab:稀疏矩阵分解
我是matlab初学者。我有一个示例代码。我想了解这段代码片段发生了什么。
Sample.m
n=60;%Number of division of length
m=84;%Number of division of time
N=2*m*n+m+n;
A=spalloc(N,N,4*N);
// A is a Matrix
for j=1:m
if(massdot(j)>=0)
i=1:n;
A(((n+1)*(j-1)+i+1-1)*N+(n+1)*(j-1)+i+1)=Nuf(:,j).*kfn(:,j)*as*Ac./((1+Bi(:,j)/5)* (2*Dh))+n*massdot(j)*cfn(:,j)/L;
A(((n+1)*(j-1)+i-1+1-1)*N+(n+1)*(j-1)+i+1)=Nuf(:,j).*kfn(:,j)*as*Ac./((1+Bi(:,j)/5)*(2*Dh))-n*massdot(j)*cfn(:,j)/L;
A(((n+1)*m+n*j+i-1)*N+(n+1)*(j-1)+i+1)=-Nuf(:,j).*kfn(:,j)*as*Ac./((1+Bi(:,j)/5)*(2*Dh));
A(((n+1)*m+n*(j-1)+i-1)*N+(n+1)*(j-1)+i+1)=-Nuf(:,j).*kfn(:,j)*as*Ac./((1+Bi(:,j)/5)*(2*Dh));
B((n+1)*(j-1)+i+1,1)=abs(ff(:,j).*massdot(j)^3/(2*pf^2*Ac^2*Dh)); %Viscous dissipation
i=0;
A((n+1)*(j-1)+i+1,(n+1)*(j-1)+i+1)=1;
B((n+1)*(j-1)+i+1,1)=TH;
...
X=A\B;
for j=1:m
i=0:n;
Tf(:,j)=full(X((n+1)*(j-1)+i+1));
...
请解释一下,第 9、10、11 和 15 行发生了什么? 12.特别是=
左侧的表达式。它位于 ( )
内。
编辑:
更新了代码。我正在尝试找出 Tf
矩阵。我无法共享整个代码,因为这是我的机密项目的代码。
I am a beginner to matlab. I have a sample code. I want to understand what is happening with the piece of code snippet.
Sample.m
n=60;%Number of division of length
m=84;%Number of division of time
N=2*m*n+m+n;
A=spalloc(N,N,4*N);
// A is a Matrix
for j=1:m
if(massdot(j)>=0)
i=1:n;
A(((n+1)*(j-1)+i+1-1)*N+(n+1)*(j-1)+i+1)=Nuf(:,j).*kfn(:,j)*as*Ac./((1+Bi(:,j)/5)* (2*Dh))+n*massdot(j)*cfn(:,j)/L;
A(((n+1)*(j-1)+i-1+1-1)*N+(n+1)*(j-1)+i+1)=Nuf(:,j).*kfn(:,j)*as*Ac./((1+Bi(:,j)/5)*(2*Dh))-n*massdot(j)*cfn(:,j)/L;
A(((n+1)*m+n*j+i-1)*N+(n+1)*(j-1)+i+1)=-Nuf(:,j).*kfn(:,j)*as*Ac./((1+Bi(:,j)/5)*(2*Dh));
A(((n+1)*m+n*(j-1)+i-1)*N+(n+1)*(j-1)+i+1)=-Nuf(:,j).*kfn(:,j)*as*Ac./((1+Bi(:,j)/5)*(2*Dh));
B((n+1)*(j-1)+i+1,1)=abs(ff(:,j).*massdot(j)^3/(2*pf^2*Ac^2*Dh)); %Viscous dissipation
i=0;
A((n+1)*(j-1)+i+1,(n+1)*(j-1)+i+1)=1;
B((n+1)*(j-1)+i+1,1)=TH;
...
X=A\B;
for j=1:m
i=0:n;
Tf(:,j)=full(X((n+1)*(j-1)+i+1));
...
Just explain me, whats happening with lines 9, 10, 11 & 12. especially expression left side to =
. which is inside the ( )
.
Edit:
Updated code. am trying to find out Tf
Matrix. I cannot share entire code, since it is my confidential project's code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
基本上,您将
A
的n
个元素的值设置为某个值。A
的索引(大括号之间的长计算)是一个向量,因为在它的计算中您使用i
,它是从 1 到 n 的所有元素的向量。如果没有一些关于代码应该做什么的背景信息,很难说更多。
Basically, you set the value of
n
elements ofA
to something. The index (that long calculation between braces) toA
is a vector, because in it's calculation you usei
, which is a vector of all the elements from 1 to n.It's hard to say more without having some background information as to what the code is supposed to do.