Shared07 - Implicit Differentiation Assignment / Implicit Differentiation Notes.sagewsOpen in CoCalc
This material was developed by Aaron Tresham at the University of Hawaii at Hilo and is Creative Commons License
licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Prerequisites:

  • Intro to Sage
  • Tangent Lines
  • Differentiation

Implicit Differentiation

In this lab we will explore implicit functions (of two variables), including their graphs, derivatives, and tangent lines.

An example of an implicit function is given by the equation x2+y2=25x^2+y^2=25. This equation provides an implicit relation between xx and yy. Compare this to the equation y=x225\displaystyle y=\sqrt{x^2-25}, which gives yy explicitly in terms of xx.

Graphing

Graphing an implicit function is fairly simple in Sage using the implicit_plot command. This command requires three arguments: an equation (using double equal sign), a plot range for the first variable, and a plot range for the second variable. I will add the optional "axes=true" and "frame=false" so that axes will be plotted instead of a frame.

Example 1

Graph x2+y2=25x^2+y^2=25 (circle of radius 5 centered at the origin).

#Do not forget to declare variables
%var y
implicit_plot(x^2+y^2==25,(x,-5,5),(y,-5,5),axes=true,frame=false)
#Note the double equal sign
#Notice that x and y both take values from -5 to 5

Example 2

Graph x(x2+y2)+(2xy)y=0x(x^2+y^2)+(2x-y)y=0.

%var y
implicit_plot(x*(x^2+y^2)+(2*x-y)*y==0,(x,-2,2),(y,-2,2),axes=true,frame=false)  #do not forget the double equal sign

Derivatives

Now that we can graph these functions, we want to compute the derivative of yy with respect to xx. This assumes that yy is a function of xx, so we need to tell Sage to assume this as well:

y=function('y')(x)

Now we can take the derivative.

Example 3

Find dydx\frac{dy}{dx} if x2+y2=25x^2+y^2=25.

First, we take the derivative of the whole equation, then we'll solve for dydx\frac{dy}{dx}.

derivative(x^2+y^2==25,x)
show(_)
2*y(x)*diff(y(x), x) + 2*x == 0
2y(x)xy(x)+2x=0\displaystyle 2 \, y\left(x\right) \frac{\partial}{\partial x}y\left(x\right) + 2 \, x = 0

The diff(y(x),x) is the derivative dydx\frac{dy}{dx}.

The curvy-looking "d" you get when you use show is the symbol for a partial derivative (you'll learn about those in Calc 3). Since this is Calc 1, you should just think of those as a regular "d."

Now we can solve for the derivative:

solve(derivative(x^2+y^2==25,x),derivative(y,x))
show(_)
[diff(y(x), x) == -x/y(x)]
[xy(x)=xy(x)\displaystyle \frac{\partial}{\partial x}y\left(x\right) = -\frac{x}{y\left(x\right)}]

This tells us that dydx=xy\displaystyle\frac{dy}{dx}=-\frac{x}{y}. [Note: Sage is treating yy as a function of xx, so it uses function notation y=y(x)y=y(x). We usually write just yy.]

Example 4

Find dydx\frac{dy}{dx} when x(x2+y2)+(2xy)y=0x(x^2+y^2)+(2x-y)y=0.

y=function('y')(x)
solve(derivative(x*(x^2+y^2)+(2*x-y)*y==0,x),derivative(y,x)) #do not forget the ==
show(_)
[diff(y(x), x) == -1/2*(3*x^2 + y(x)^2 + 2*y(x))/((x - 1)*y(x) + x)]
[xy(x)=3x2+y(x)2+2y(x)2((x1)y(x)+x)\displaystyle \frac{\partial}{\partial x}y\left(x\right) = -\frac{3 \, x^{2} + y\left(x\right)^{2} + 2 \, y\left(x\right)}{2 \, {\left({\left(x - 1\right)} y\left(x\right) + x\right)}}]

So dydx=3x2+y2+2y2((x1)y+x)\displaystyle\frac{dy}{dx}=-\frac{3x^2+y^2+2y}{2((x-1)y+x)}.

Tangent Lines

Now that we can find the derivative of an implicit function, we can also find tangent lines.

Recall that the line tangent to a function ff at the point (x0,f(x0))(x_0,f(x_0)) has equation y=f(x0)+f(x0)(xx0)y=f(x_0)+f'(x_0)(x-x_0).

Example 5

Find an equation for the line tangent to the circle given by x2+y2=25x^2+y^2=25 at the point (3,4)(3,4).

Above we found dydx=xy\displaystyle\frac{dy}{dx}=-\frac{x}{y}. So the slope of the tangent line at (3,4)(3,4) is 34-\frac{3}{4}.

Thus, an equation for the tangent line is y=434(x3)y=4-\frac{3}{4}(x-3).

Let's graph the implicit function and the tangent line.

#Before plotting, we need to "reset" the variable y
%var y
implicit_plot(x^2+y^2==25,(x,-5,5),(y,-5,5),axes=true,frame=false)+plot(4-(3/4)*(x-3),xmin=-5,xmax=6,ymax=6,color='red')+point((3,4),color='black',size=25)

Example 6

Find an equation for the tangent line to the graph of x(x2+y2)+(2xy)y=0x(x^2+y^2)+(2x-y)y=0 at the point (1,12)(1,-\frac{1}{2}).

We found the derivative above: dydx=3x2+y2+2y2((x1)y+x)\displaystyle\frac{dy}{dx}=-\frac{3x^2+y^2+2y}{2((x-1)y+x)}.

Now we need to substitute x=1x=1 and y=12y=-\frac{1}{2}.

I will copy and paste this derivative from the calculation above, and then I will replace x with 11 and y(x) with 12-\frac{1}{2}.

-1/2*(3*1^2 + (-1/2)^2 + 2*(-1/2))/((1 - 1)*(-1/2) + 1)   #notice the parentheses around -1/2
-9/8

Now that we have the slope, we can find an equation of the tangent line: y=1298(x1)y=-\frac{1}{2}-\frac{9}{8}(x-1).

Let's check our answer by graphing:

%var y
implicit_plot(x*(x^2+y^2)+(2*x-y)*y==0,(x,-2,2),(y,-2,2),axes=true,frame=false)+plot(-1/2-9/8*(x-1),xmin=-1,xmax=2,color='red')+point((1,-1/2),color='black',size=25)

Example 7 (follow this example for your assignment)

Here is one final example that puts all the pieces together.

Consider (x2+y2)2+12x2y=(32y)3\displaystyle\left(x^2+y^2\right)^2+12x^2y=\left(\frac{3}{2}y\right)^3

Find the derivative, find the tangent line at (a,b)=(0.5832,2)(a,b)=(0.5832,2), and graph the curve and tangent line.

First, we find the derivative.

y=function('y')(x)
solve(derivative((x^2+y^2)^2+12*x^2*y==(3/2*y)^3,x),derivative(y,x))
show(_)
[diff(y(x), x) == -32*(x^3 + x*y(x)^2 + 6*x*y(x))/(32*x^2*y(x) + 32*y(x)^3 + 96*x^2 - 81*y(x)^2)]
[xy(x)=32(x3+xy(x)2+6xy(x))32x2y(x)+32y(x)3+96x281y(x)2\displaystyle \frac{\partial}{\partial x}y\left(x\right) = -\frac{32 \, {\left(x^{3} + x y\left(x\right)^{2} + 6 \, x y\left(x\right)\right)}}{32 \, x^{2} y\left(x\right) + 32 \, y\left(x\right)^{3} + 96 \, x^{2} - 81 \, y\left(x\right)^{2}}]

Now we define "a" and "b," copy and paste the derivative, and replace x with a and y(x) with b.

a=0.5832   #x-coordinate of point of tangency
b=2        #y-coordinate of point of tangency
-32*(a^3 + a*b^2 + 6*a*b)/(32*a^2*b + 32*b^3 + 96*a^2 - 81*b^2)
22.4547850705957

Next we define the tangent line, using the answer above for the slope.

TL(x)=b+22.4547850705957*(x-a)
TL(x)
22.4547850705957*x - 11.0956306531714

Finally, we plot the original function and the tangent line (remember to "reset" y using %var y before graphing).

%var y
implicit_plot((x^2+y^2)^2+12*x^2*y==(3/2*y)^3,(x,-5,5),(y,-5,5),axes=true,frame=false)+plot(TL,xmin=-5,xmax=5,ymin=-5,ymax=5,color='red')+point((a,b),color='black',size=25)

3D Examples

Sage can also plot an implicit function of three variables. We won't need this for our assignment, but here are a few examples.

[Note: you can make it bigger or smaller with the mouse wheel; click and drag to rotate]

Sphere of radius 5:

%var x,y,z
implicit_plot3d(x^2+y^2+z^2==25,(x,-5,5),(y,-5,5),(z,-5,5))
3D rendering not yet implemented

This one is a little more interesting:

%var x,y,z
implicit_plot3d(sin(x^2+y^2+z^2-36),(x,-3,3),(y,-3,3),(z,-3,3))
3D rendering not yet implemented

One more:

[This example is from a Sage tutorial available here. It is licensed under the Creative Commons Attribution-ShareAlike 3.0 license (CC BY-SA).]

%var x,y,z
T = golden_ratio
p = 2 - (cos(x + T*y) + cos(x - T*y) + cos(y + T*z) + cos(y - T*z) + cos(z - T*x) + cos(z + T*x))
r = 4.78
show(implicit_plot3d(p, (x, -r, r), (y, -r, r), (z, -r, r), plot_points=50))
3D rendering not yet implemented