You need the symbolic toolbox in order to do this, and you need to declare your free variable with either a sym() or syms() call.
Please also note that you cannot take the derivative of a mathematical function over a range.
If you are trying to do numeric derivatives then you should recode as something like:
function df = derivate(f)
x = -20:20;
df = diff(f(x));
end
and you would then call it with a function handle, such as calling
Best Answer