Gradients of Functions of Large Matrices