An introduction to the calculus of variations