diff(function,x)
differentiates
function
with respect to the symbolic variable x
.
The main variable of function
is used if x
is not provided. Functions defined by user programs
can often be handled as well.
>> syms a,x >> diff(a*x^3) ans = 3*a*x^2 >> diff(a*x^3,a) ans = x^3 >> diff(3*sqrt(exp(x)+2),x) ans = 1.5*exp(x)/sqrt(exp(x)+2) >> diff(sin(x)) % no variable specified ans = 1 % use z=sin(x) as variable >> diff(sin(x),x) % more reasonable ans = cos(x) >> function y=ttwo(x) y=2*x; end >> diff(ttwo(sin(x)),x) ans = 2*cos(x)