x = 0:1:5; % define x array y = exp(x)+x.^4+2*x.^2-x+3; % define y array dx = diff(x); % 1 1 1 1 1 dx has one number less than x dy = diff(y); % -5 -1 -3 -4 -2 slope =
Since slope is computed from two consecutive values, I suggest you take the average betwen consecutive points as the x-axis values for ´slope`:
slope
x
plot((x(1:end-1)+x(2:end))/2,slope, '*',x,z)