MATLAB: Substitute derivative array function

derivativeMATLAB

I have a function f(x)=e^-x-1+x & I want to differentiate it, so I used the code below which gave me the correct answer, but now I want to substitute x with variables of the array: x=[16.08554; 12.64465; 9.863738; 7.623176; 5.825013; 4.389056]; It gave me the substitution of the original function, not the derivative. The answers should be like this: x=[-19.08553692, -15.4446467710, -12.463738035, -10.023176380, -8.025013499,-6.3890560989];
syms x;
function= exp(-x)-1+x
diff(function)

Best Answer

syms x;
f(x)= exp(-x)-1+x
F(x)= diff(f)
xVal=[16.08554; 12.64465; 9.863738; 7.623176; 5.825013; 4.389056];
Fx=double(F(xVal))