Derivatives

Last lab, we learned how to calculate limits. Basically we started by invoking the symbolic toolbox

syms x

and then defined a corresponding function f that depends on x. For example to create a function f(x) = x^3 we typed

f = x.^3
 
f =
 
x^3
 

Now, if we want to calculate the derivative of this function at a symbolic point a, we can do this by using the Matlab command limit:

syms a
fpa = limit((subs(f,x,x)-subs(f,x,a))/(x-a), x,a)
 
fpa =
 
3*a^2
 

produces the derivative of f(x) at the point a as being 3a^2. You can also calculate the derivative using the Matlab command diff. For instance,

dfdx = diff(2*x+x^4)
 
dfdx =
 
4*x^3 + 2
 

will create a function dfdx that contains the derivative 4x^3+2. Enjoy!