Castigliano's theorem and stiffness matrices