R code for FEM