Filter löschen
Filter löschen

Assembly of mass Matrix algorithm

3 Ansichten (letzte 30 Tage)
Lamour Haithem Firass
Lamour Haithem Firass am 16 Mai 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

Antworten (0)

Kategorien

Mehr zu Operating on Diagonal Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by