  We propose an effective and flexible way to implement 2D and 3D elastoplastic
problems in MATLAB using fully vectorized codes. Our technique is applied to a
broad class of the problems including perfect plasticity or plasticity with
hardening and several yield criteria. The problems are formulated in terms of
displacements, discretized by the implicit Euler method in time and the finite
element method in space, and solved by the semismooth Newton method. We discuss
in detail selected models with the von Mises and Prager-Drucker yield criteria
and four types of finite elements. The related codes are available for
download. A particular interest is devoted to the assembling of tangential
stiffness matrices. Since these matrices are repeatedly constructed in each
Newton iteration and in each time step, we propose another vectorized
assembling than current ones known for the elastic stiffness matrices. The main
idea is based on a construction of two large and sparse matrices representing
the strain-displacement and tangent operators, respectively, where the former
matrix remains fixed and the latter one is updated only at some integration
points. Comparisons with other available MATLAB codes show that our technique
is also efficient for purely elastic problems. In elastoplasticity, the
assembly times are linearly proportional to the number of integration points in
a plastic phase and additional times due to plasticity never exceed assembly
time of the elastic stiffness matrix.
