Ch09 Differentiation PDF
Ch09 Differentiation PDF
Table of Contents
Using diff ......................................................................................................................
Higher Derivatives ..............................................................................................................
A Different Variable ...........................................................................................................
Wait, that Second Parameter? ...............................................................................................
Plugging Stuff In - Using subs ...........................................................................................
Plotting Derivatives ............................................................................................................
1
1
1
2
2
3
Using diff
What about calculus? Don't worry -- Matlab will not let you down! Suppose you'd like to differentiate
the function log(6*x+2). You could either do it yourself or... just ask Matlab to do it with the diff
command:
syms x
diff(log(6 * x + 2))
ans =
6/(6*x + 2)
Higher Derivatives
What could be easier?
Would you like to find the third derivative of the function log(6*x+2)? That's easy too -- just pass 3
as a second parameter to the diff command:
diff(log(6 * x + 2), 3)
ans =
432/(6*x + 2)^3
A Different Variable
Suppose our expression has two variables and we want the derivative with respect to one of them. As
usual x is the default
syms a x
diff(a^3*x^4)
Differentiation
ans =
4*a^3*x^3
ans =
3*a^2*x^4
ans =
6*a*x^4
ans =
8
So now to take the derivative and then plug in, we simply nest the commands. Here's the second derivative
of x^3+exp(x^2) with x=1 plugged in:
subs(diff(x^3+exp(x^2),2),x,1)
ans =
22.3097
Differentiation
Plotting Derivatives
Likewise we can nest diff inside ezplot. Here's an example, a plot of the derivative of sin(x^2):
ezplot(diff(sin(x^2)))