From HandWiki


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.

<jc lang="math"> syms a,x y=diff(a*x^3,x); printf('%f',y) </jc>

You can easily plot the result of differentiation as:

<jc lang="math"> syms x % symbolic x y=diff(x*cos(x),x) % differentiate x*cos(x) plot2d('minx=0;maxx=10;miny=-1;maxy=10')  % make canvas draw2d(y) % plot the result </jc>

Let us consider few more example skipping the print statement:

<jc lang="math"> syms a,x y=diff(a*x^3,a); printf('%f',y) </jc>

<jc lang="math"> syms x y=diff(3*sqrt(exp(x)+2),x); printf('%f',y) </jc>

<jc lang="math"> syms x y=diff(sin(x)); printf('%f',y)  % no variable specified </jc>

<jc lang="math"> syms x y=diff(sin(x),x); printf('%f',y)  % more reasonable </jc>

<jc lang="math"> syms x function y=ttwo(x) y=2*x; end y=diff(ttwo(sin(x)),x) printf('%f',y) </jc>