Assembly of mass Matrix algorithm

7 ビュー (過去 30 日間)
Lamour Haithem Firass
Lamour Haithem Firass 2021 年 5 月 16 日
I have this code, that generate the "Assembly of mass Matrix algorithm" this code deisgned for (3,3) matrix.
The problem is: how can i upgrade this code for (9*9) matrix.
%% assembly of the mass matrix
function M = MassMar2D(p,t)
clear,clc
p = [0 1 2 2 0;
0 0 0 1 1];
t = [1 1 2;
4 2 3;
5 4 4];
np = size(p,2); % number of nodes
nt = size(t,2); % number of elements
M = sparse(5,5); % allocate mass matrix
for K = 1:nt % loop over elements
loc2glb = t(1:3,K) % locate to global map
x = p(1, loc2glb); % node x-coordinates
y = p(2, loc2glb); % y
area = polyarea(x,y); % triangle area
MK = [2 1 1;
1 2 1;
1 1 2]/ 12 * area; % elements mass matrix
M(loc2glb, loc2glb) = M(loc2glb, loc2glb) ...
+ MK; % add element masses to M
end

回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by