Vary the gravitational volume factor and use part (a)(ii):
Twice applying integration by parts moves both derivatives in from the compactly supported onto . Combining the result with the stated matter variation and requiring every coefficient of to vanish gives the f(R) gravity equation
Therefore