Calculus of Variations and Finite Elements