assemble global stiffness matrix
조회 수: 11 (최근 30일)
이전 댓글 표시
I am trying to assemble a matrix in which I would like to put small matrices into a big one but I don't know how to do that,
I know that I have to define the big matrix first and then show put the small ones inside
for example I have k1=[1 -1; -1 1] , K2=[1 -1; -1 1] and the define bigK in which bigK=zeros(3,3) and in the end I want it to be like bigK = [ 1 -1 0; -1 2 -1; 0 -1 1]
in which the small matrices will assemble in diagonal way
how I can do it using a for loop ?
댓글 수: 0
채택된 답변
John D'Errico
2018년 10월 12일
K = zeros(10,10);
k = [1 -1; -1 1];
for n = 1:9;
rind = n + [0 1];
cind = rind;
K(rind, cind) = K(rind, cind) + k;
end
There are better ways to do this in terms of pure efficiency. But the above will suffice. First learn how to write at least decent code that solves the task at hand. Only when you decide if the code is a problem do you want to worry about optimizing it for speed.
댓글 수: 5
Torsten
2018년 10월 12일
k=[1 -1; -1 1];
n=5;
K=zeros(n+1);
for i=1:n
K(i:i+1,i:i+1)=K(i:i+1,i:i+1)+k;
end
K
추가 답변 (3개)
Torsten
2018년 10월 12일
k1 = [1 -1; -1 1];
k2 = k1;
K = zeros(3,3)
K(1:2,1:2) = k1;
K(2:3,2:3) = K(2:3,2:3) + k2;
K
댓글 수: 0
Samba Dumbuya
2022년 12월 1일
Hello,
I have computed the following stiffness matrix by hand;
[2/3 -1/6 -1/6 -1/3; -1/6 2/3 -1/3 -1/6;-1/6 -1/3 2/3 -1/6; -1/3 -1/6 -1/6 2/3]
Can someone please with codes that assemble the stiffness matrix into global matrix. The domain is discritize to square elemen.
thanks
참고 항목
카테고리
Help Center 및 File Exchange에서 Linear Least Squares에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!