Add _eval_derivative_wrt interface and fix diff wrt MatrixElement

This patch introduces the Expr._eval_derivative_wrt interface (see docstring in the patch for description) and fixes issue #7421.