0% found this document useful (0 votes)
24 views4 pages

Math1020 Lab 6

This document outlines Laboratory Session 6 for MATH1020 Calculus for Engineers, focusing on using the Symbolic Toolbox for differentiation and implicit differentiation. It provides examples of differentiating expressions and functions, calculating higher-order derivatives, and performing implicit differentiation with MATLAB commands. The session concludes with exercises for students to practice their skills in finding derivatives and tangent lines using the Symbolic Toolbox.

Uploaded by

jajafirst663
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views4 pages

Math1020 Lab 6

This document outlines Laboratory Session 6 for MATH1020 Calculus for Engineers, focusing on using the Symbolic Toolbox for differentiation and implicit differentiation. It provides examples of differentiating expressions and functions, calculating higher-order derivatives, and performing implicit differentiation with MATLAB commands. The session concludes with exercises for students to practice their skills in finding derivatives and tangent lines using the Symbolic Toolbox.

Uploaded by

jajafirst663
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

MATH1020 Calculus for Engineers

Laboratory Session 6

Learning outcomes for this session


At the end of this session, you will be able to
1. Use the Symbolic Toolbox to differentiate functions and plot the graphs of derivatives.
2. Use the Symbolic Toolbox to perform implicit differentiation.

Overview
1. (Again) functions converted from expressions with symfun
2. Differentiation of functions, Symbolic Toolbox function diff
3. Implicit Differentiation.

Differentiation
diff
We begin by repeating that expressions and functions differ. Refer back to Laboratory
Session 2 or ask your tutor if you need clarification on this. The diff function is used
in both cases. We begin with its use to differentiate an expression with respect to any
variable contained within the expression. The result is another expression, of course, and
not a function. Here is example code:

syms t gExpr
% First consider expressions:
gExpr = tan(5*t^3+2)
dgExpr = diff(gExpr,t) % the output is an expression

Examples involving functions are as follows. When diff operates on a function, its output
is a function.

1
syms t gsymFun
gsymFun = symfun(tan(5*t^3+2),t)
% argnames and formula are functions to use on a symfun
dgsymFun = diff(gsymFun) % produces a function
%To evaluate the derivative at a particular value of its argument,
% for example, g’(2), we would type
dgsymFun(2)

Next, note that we can easily calculate higher order derivatives as well. In the diff
command, this is achieved as follows. For example, the second derivative is given by

d2gExpr = diff(gExpr,t,2) % the output is an expression


d2gsymFun = diff(gsymFun,2) % the output is a function

More on derivatives.
As this is standard material, there is a lot on the internet. At this stage of your experience
with MATLAB you might be interested in the presentation possibilities of MATLAB’s
livemath formats. If you look at
https://au.mathworks.com/matlabcentral/fileexchange/65834-essential-calculus-lectures-with-matlab
and choose Examples from the bar near the top, and within that Chapter4 Derivatives.mlx
from the list at the left, you will be presented with a matlab livemath document. This
covers material appropriate to this lab.

Implicit differentiation
Expression with more than one variable name can be differentiated with respect to each
of those variables individually. Further, any variable that we are not differentiating with
respect to is treated as a constant, unless it has previously been assigned a value by
another command. In other words, the Symbolic Toolbox treats all unassigned names
in an expression as constants for the purpose of differentiation. However, we can make
it believe that one or more of the variable names are dependent on others within the
expression. Enter the following commands

2
clear all
syms x y
diff(y,x) % 0
clear all
syms x y(x)
diff(y(x),x)
pretty(ans)

and note the Symbolic Toolbox’s response. In the first diff command, y is treated simply
as a constant. In the second diff command, the Symbolic Toolbox is able to interpret the
intended meaning of the y(x), i.e. that we would like to regard y as a function of x and so
it realizes that there is a meaning to the derivative with respect to x. With this in mind,
we can easily perform implicit differentiation in the Symbolic Toolbox. Enter the following
commands to see how it works.
clear all
syms x Y y(x)
eq1 = x*Y^2+5*x^2*Y+Y^3==0
eq2 = subs(eq1,Y,y(x))
deq2 = diff(eq2,x)
syms Yp
deq3 = subs(deq2,diff(y(x),x),Yp)
ypSol = solve(deq3,Yp)
yp = subs(ypSol,y(x),Y)
% yp = -(Y^2 + 10*x*Y)/(3*Y^2 + 2*Y*x + 5*x^2)

We have used yp and Yp to denote y 0 = dy/dx. Note how this series of commands replicates
exactly the same steps that we would have used to find the implicit derivative by hand!
There is, of course, an easier way of performing implicit differentiation. Try the following:

syms F; F = lhs(eq1)
ypF = -diff(F,x)/diff(F,Y)
check = simplify(yp - ypF) % 0 as it should be

Unfortunately, MATLAB does not contain a nice predefined function to perform implicit
differentiation. In the above we have used a workaround, but you’ll have to wait until
you’ve studied partial derivatives and a more sophisticated version of the chain rule (both
of which are not covered in this Unit) for the theoretical justification of this workaround. If

3
we write the equation in the form F (x, y) = 0, the derivative dy/dx of the implicitly defined
function is the negative of the quotient of the so-called partial derivatives of F (with the
x partial in the numerator and the y partial in the denominator). So in MATLAB treat x
and y as independent variables. Try another example: find dy/dx given y 4 −4y 2 = x4 −9x2 :

clear all
syms x y F
F = y^4 - 4*y^2 - x^4 + 9*x^2
-diff( F, x )/diff( F, y )
pretty(ans)

Have a look at
Examples/Symbolic/DiffExample/DiffExample.mlx
(though some of this is more appropriate to Lab 8 on optimization).

Exercises
You may work in pairs and learn from one another for these exercises. Ask your tutor if
you get stuck.
1. Use the Symbolic Toolbox to find the derivative of f (x) = 5x5 − 14x3 + 13x + 6. Plot
the graph of f 0 (x) and determine all points where the derivative of the function is
equal to zero.
2. Use the Symbolic Toolbox to find dy/dx, given the implicit equation

x6 y 2 + tan(x2 y) + sin(xy 2 ) = 0.

3. Find the equation of the tangent line to the curve 3xy = x3 + y 3 at x = 1, where y
is in the interval [0, 1]. Plot the tangent line and the implicit equation on the same
axes.

You might also like