CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
calculuslab

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: calculuslab/Calculus_Lab
Path: blob/main/141-Labs/Lab 06 - Implicit Differentiation.ipynb
Views: 491
Kernel: SageMath 9.2

Lab 06 - Implicit Differentiation

Overview

In this lab, we will learn how to use SageMath to find derivatives of functions defined implicity.

Important SageMath Commands Introduced in this Lab

ParseError: KaTeX parse error: Undefined control sequence: \hfill at position 32: …|l|l|} \hline \̲h̲f̲i̲l̲l̲ ̲\textbf{Command…
Sections 3.7

Example 1

Consider the Folium of Descartes x3+y3=3xyx^3 + y^3 = 3xy. In this example, we will do the following:

  1. Use implicit differentiation to find dydx\dfrac{dy}{dx}

  2. Find the equation of the tangent line to the Folium of Descartes at the point (32,32)\left(\frac{3}{2}, \frac{3}{2}\right)

  3. Graph the curve, the point, and the tangent line

  4. Find all points on the Folium of Descartes which have a horizontal tangent line or a vertical tangent line

First, will use SageMath to find dydx\dfrac{dy}{dx} using implicit differentiation. In order for SageMath to calculate dydx\dfrac{dy}{dx}, we need to use the function(’y’)(x)\textbf{function('y')(x)} command to let SageMath know that yy is a function which depends on xx.

y = function('y')(x)

Next, we will take the derivate with respect to xx of both sides of our equation. Since we made yy a funciton of xx, SageMath will automatically use the chain rule when it takes the derivative of yy.

diff(x^3 + y^3 == 3*x*y,x)

Recall that we can make SageMath display the output in a nicer and more readable way by using the show()\textbf{show}(\dots) command.

show(diff(x^3 + y^3 == 3*x*y,x))

The next thing we need to do is solve this equation for dydx\dfrac{dy}{dx} which we can have SageMath do for us using the solve(expression,variable)\textbf{solve}(\textit{expression}, \textit{variable}) command from Lab 4.

show(solve(diff(x^3 + y^3 == 3*x*y,x), diff(y,x)))

Therefore, we see that dydx=x2yy2x\dfrac{dy}{dx} = -\dfrac{x^2 - y}{y^2 - x}.

Now, we will find the equation of the tangent line of the Folium of Descartes at the point (32,32)\left(\frac{3}{2}, \frac{3}{2}\right). (Note: This is a point on the graph of the Folium of Descartes since if we replace both xx and yy with 32\frac{3}{2} in the equation, we get a true statement.) We already know the xx-value and yy-value of the point, so the only thing we have left to find is dydx(32,32).\dfrac{dy}{dx}\biggr \rvert_{\left(\frac{3}{2},\frac{3}{2}\right)}. We can do this in SageMath by first creating the function dydx\dfrac{dy}{dx} which, in this example, depends on both xx and yy. Note that when creating this function, we will need to use yy as a variable, however, earlier we made yy a function of xx, so we have to overwrite that by using the var(y)\textbf{var}(`y`) command.

y = var('y') def dydx(x,y): return -(x^2 - y) / (y^2 - x) dydx(3/2, 3/2)

Thus, we see that dydx(32,32)=1.\dfrac{dy}{dx} \biggr \rvert_{\left(\frac{3}{2}, \frac{3}{2}\right)} = -1. It follows that the equation of the tangent line of the Folium of Descartes at the point (32,32)\left(\frac{3}{2}, \frac{3}{2}\right) is y=1(x32)+32    y=x+3.y = -1\left(x - \frac{3}{2}\right) + \frac{3}{2} \implies y = -x + 3.

Now, let us plot the Folium of Descartes, the point (32,32)\left(\frac{3}{2},\frac{3}{2}\right), and the tangent line at (32,32)\left(\frac{3}{2}, \frac{3}{2}\right) all on the same graph. In order to plot them all on the same graph, we will assign each of these three objects to a variable and then use the show()\textbf{show}(\dots) command. To plot the Folium of Descartes, we have to make use of the ParseError: KaTeX parse error: Expected 'EOF', got '_' at position 17: …textbf{implicit_̲plot}(\textit{e… command since it is defined implicitly. To graph the point, we need to make use of the point((x,y))\textbf{point}((x,y)) command. Both of these commands can use some of the options we use in plot, such as color.

p1 = implicit_plot(x^3 + y^3 == 3*x*y, (-5,5), (-5,5), color = "black") p2 = point((3/2, 3/2), color="red", size = 50) p3 = plot(-x+3, xmin=-5, xmax=5, color="orange", linestyle = "--") show(p1 + p2 + p3)

Lastly, we will find all of the points on the Folium of Descartes which have either a horizontal or vertical tangent line. Recall that horizontal tangent lines occur at points where dydx=0\dfrac{dy}{dx} = 0. We will use the solve([equations],variables)\textbf{solve}([\textit{equations}], \textit{variables}) command to determine what points both lie on the Folium of Descartes and satisfy dydx=0.\dfrac{dy}{dx} = 0.

solve([x^3 + y^3 == 3*x*y, dydx(x,y) == 0], x, y)

Note that some of the solutions SageMath gave are imaginary; that is, they involve the imaginary constant I=1I = \sqrt{-1}, so we will disregard these. Therefore, the only two points which are on the Folium of Descartes and have a horizontal tangent line are (0,0)(0,0) and rougly (1.2599,1.5874)(1.2599, 1.5874).

Vertical tangent lines occur at points where dxdy=0\dfrac{dx}{dy} = 0. Note that dxdy\dfrac{dx}{dy} is simply the reciprocal of dydx\dfrac{dy}{dx}. Again, we use the solve()\textbf{solve}(\dots) command to determine which points lie on the Folium of Descartes and make dxdy=0\dfrac{dx}{dy} = 0.

solve([x^3 + y^3 == 3*x*y, 1/dydx(x,y) == 0], x, y)

Again, SageMath gives some imaginary solutions which we will disregard. It follows that the only two points which are on the Folium of Descartes and have a vertical tangent line are (0,0)(0,0) and rougly (1.5874,1.2599)(1.5874, 1.2599).

Example 2

Repeat Example 1 with the function 2(x2+y2)2=25(x2y2)2(x^2 + y^2)^2 = 25(x^2 - y^2) and the point (3,1)(3,1).

Example 3

Repeat Example 1 with the function x2yxy2=2x^2y - xy^2 = 2 and the point (1,1)(-1,1).

Example 4

Repeat Example 1 with the function (x2+y21)3x2y3=0\left(x^{2}+y^{2}-1\right)^{3}-x^{2}y^{3}=0 and the point (1,1).