0

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. 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. The n1 and n2 correspond to the start and finish node of the element. Of course this would be inside a loop that will calculate the stiffness matrix of each element and overlay it to the global matrix.

1 Answer 1

1

For the given values of n1 and n2, sctr is

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. Matlab selects one element for each possible combination of the elements in sctr. So, for each selected row (i.e. which have their index in sctr) the columns with their index in sctr are selected. See matrix indexing for more information.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.