Optimize finite difference gradients