nf = ones(nnd, nodof); % Initialise the matrix nf to 1 nf(1,2) =0 ; % Prescribed nodal freedom of node 1 nf(6,1)= 0 ; nf(6,2)= 0 ; % Prescribed nodal freedom of node 6 % Counting of the free degrees of freedom n=0; fori=1:nnd forj=1:nodof if nf(i,j) ~= 0 n=n+1; nf(i,j)=n; end end end g=[nf(node_1,1); nf(node_1,2); nf(node_2,1);nf(node_2,2)]
以上代码取自《Matlab与Abaqus有限元分析理论与应用》(汉译版),代码风格的源头是《Programming the Finite Element Method》,特别说明的是:该书是有限元编程的“里程碑”著作,内容非常全面,代码量巨大,免费开源,但是对于我们新手很不友好,代码语言采用Fortran编写,阅读起来十分费劲,后续不断有人在该著作的基础上将代码语言修改为 Matlab 语言,与 Fortran 相比起来,易读性显著提升,可视化更强。好啦好啦,题外话不多说啦,继续我们的正题!