Assembly of mass Matrix algorithm

4 views (last 30 days)
Lamour Haithem Firass
Lamour Haithem Firass on 16 May 2021
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

Answers (0)

Categories

Find more on Operating on Diagonal Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!