wrote derivation for gradient of quadratic form.