The finite element method is an efficient numerical method,which is often used to solve various differential equations with the help of computer.Matlab is an interactive environment and programming language for scientific computing,and it is also a matrix language with matrix as the main data type.At present,a lot of research work is based on Matlab as a compiler language to solve the differential equation using finite element method.Therefore,in order to make full use of the features of Matlab language to achieve optimal performance in large-scale problems,we should try our best to reasonably use matrix or vector operations in Matlab programs.In this paper,we propose a vectorized Matlab implementation of assembling the stiffness matrix for solving the problem of the second-order elliptic equations based on a rotated nonconforming quadrilateral element(2D)and a rotated nonconforming pyramid element(3D).Vectorization means that there is no for loop over each element in the operations of assembling the stiffness matrix with Matlab,which is depending on the elements volume,but a form we make according to the features of two rotated nonconforming elements and with the help of the quadrature formulae with little points which can implement on all elements in one time just using matrix or vector products directly with a double loops of constant number(the number is equal to the elements volume).Since the logic of the vectorized code is more consistent with the operation features of Matlab,the calculation cost of our code is greatly reduced.Numerical experiments show that our implementation has a significant improvement in the efficiency of assembling the stiffness matrix with little effect on the global error,compared with the traditional implementation with loops. |