First implementation (dense problem, analytical gradients)