[英]Add values to specific points in MATLAB
In order to create the global stiffness matrix of a truss, I need to overlay the stiffness matrix to the global one. 为了创建桁架的整体刚度矩阵,我需要将刚度矩阵叠加到整体框架上。 I started by creating a zero matrix
我首先创建一个零矩阵
K=zeros(6,6); %Empty global stiffness matrix
And then I want to overlay a 4x4 matrix (Ke) to the correct position. 然后,我想将4x4矩阵(Ke)覆盖到正确的位置。 For example:
例如:
Ke(1,1)->K(1,1)
Ke(1,2)->K(1,2)
Ke(1,3)->K(1,5)
Ke(1,4)->K(1,6)
Ke(2,1)->K(2,1)
Ke(2,2)->K(2,2)
Ke(2,3)->K(2,5)
Ke(2,4)->K(2,6)
etc.
I found a piece of code that would work but I'm afraid I can't understand why. 我发现了一段有效的代码,但我怕我不明白为什么。 Here it is:
这里是:
sctr = [2*n1-1 2*n1 2*n2-1 2*n2];
K(sctr,sctr) = K(sctr,sctr) + Ke;
Following my above example n1
, n2
should be n1=1
and n2=3
. 按照我上面的示例
n1
, n2
应该为n1=1
和n2=3
。 The n1 and n2 correspond to the start and finish node of the element. n1和n2对应于元素的开始和结束节点。 Of course this would be inside a loop that will calculate the stiffness matrix of each element and overlay it to the global matrix.
当然,这将在循环内部,该循环将计算每个元素的刚度矩阵并将其覆盖到全局矩阵。
For the given values of n1
and n2
, sctr
is 对于给定的
n1
和n2
值, sctr
为
sctr = [1 2 5 6];
This corresponds with the row and column indices you want to change. 这与您要更改的行和列索引相对应。
K(sctr,sctr)
selects the 4x4 submatrix of K
. K(sctr,sctr)
选择K
的4x4子矩阵。 Matlab selects one element for each possible combination of the elements in sctr
. Matlab为
sctr
元素的每种可能组合选择一个元素。 So, for each selected row (ie which have their index in sctr
) the columns with their index in sctr
are selected. 因此,对于每个选定的行(即,其索引在
sctr
),将选择其索引在sctr
中的列。 See matrix indexing for more information. 有关更多信息,请参见矩阵索引 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.