The problem is that you are using the numerical diff function that produces outputs that are smaller than the inputs.
A much better solution is to use the gradient (link) function instead. It produces a numeric derivative the same size as the input, eliminating the problem of different-size vectors.
