X = sym('X', [1,N]);
J = X(end) - X(1);
More generally,
syms f(x)
J = sum(arrayfun(f, x(2:end)-x(1:end-1)))
In earlier MATLAB you might need
temp = arrayfun(f, x(2:end) - x(1:end-1), 'uniform, 0);
J = sum([temp{:}]);
Notice the complete lack of symsum. symsum can never be used to index variables: you need to form the list of definite elements and sum them. symsum is for finding theoretical formula such as symsum(k) being k*(k+1)/2 not for adding definite terms.