Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

Quelques notebooks SAGE / Python. Équations différentielles ou calcul multivariable.

Project: Calcul Libre
Views: 1413
Image: ubuntu2004
Kernel: SageMath 9.0
%display typeset

Differentiability

Two examples

Recall

  • Write r=(x,y),r0=(x0,y0)\mathbf{r} = (x,y), \mathbf{r}_0 = (x_0,y_0) and so on...,

  • Let ff be defined on a region R\mathcal{R} of R2\mathbb{R}^2 containing the point r0=(x0,y0)\mathbf{r}_0 = (x_0,y_0).

  • Its linear approximation at r0\mathbf{r}_0 is T(r)=f(r0)+f(r0)(rr0)T(\mathbf{r}) = f(\mathbf{r}_0) + \nabla f (\mathbf{r}_0)\cdot (\mathbf{r} - \mathbf{r}_0)

  • Upon expanding, one can equivalently (but it is longer to do so) write T(x,y)=f(x0,y0)+fx(x0,y0)(xx0)+fy(x0,y0)(yy0)T(x,y) = f(x_0,y_0) + f_x(x_0,y_0)(x-x_0) + f_y(x_0,y_0)(y-y_0)

Differentiability

The function ff is differentiable at r0\mathbf{r}_0 if the error made by by replacing f(r)f(\mathbf{r}) by T(r)T(\mathbf{r}) is small compared to rr0||\mathbf{r}- \mathbf{r}_0||.

  • This means that near r0\mathbf{r}_0, ff and TT beheave in the same way.

  • So their contour plots should look pretty similar.

  • But since TT is linear, its contour plot is formed by parallel lines (whose common normal vector is precisely f(r0)\nabla f(\mathbf{r}_0) provided it is non zero).

  • Sometimes one refers to differentiability (at a point) as local linearity (near that point)

Example 1

Let us consider the function ff given by f(x,y)=2x2+y2f(x,y) = 2x^2 +y^2, and study its differentiability at (1,1)(1,1).

Below we have the surface and its tangent plane. A direct calculation shows T(x,y)=4x+2y3T(x,y) = 4x+2y-3.

var('x,y') f(x,y) = 2*x^2 + y^2 x0, y0 =1,1 T(x,y) = taylor(f(x,y), (x,x0), (y,y0), 1) Surface = plot3d(f(x,y), (x,0,2), (y,0,2), color = "orange",opacity= 0.65, mesh = 1) Plane = plot3d(T(x,y), (x,0,2), (y,0,2), color = "green",opacity= 0.65, mesh = 1) show(Surface + Plane, aspect_ratio = [4,4,1])

Let us now see the two contour plots, together, with different zoom factors.

Fig1 =contour_plot(f, (x,0,2), (y,0,2), cmap = "Oranges", fill = False, contours = 15) Fig1 += contour_plot(T, (x,0,2), (y,0,2), cmap = "Blues", fill = False, contours = 15) Fig2 =contour_plot(f, (x,0.5,1.5), (y,0.5,1.5), cmap = "Oranges", fill = False , contours = 15) Fig2 += contour_plot(T, (x,0.5,1.5), (y,0.5,1.5), cmap = "Blues", fill = False, contours = 15) Fig3 =contour_plot(f, (x,0.9,1.1), (y,0.9,1.1), cmap = "Oranges", fill = False , contours = 15) Fig3 += contour_plot(T, (x,0.9,1.1), (y,0.9,1.1), cmap = "Blues", fill = False, contours = 15) Array = graphics_array((Fig1, Fig2, Fig3)) Array.show(figsize = 8)
Image in a Jupyter notebook

One clearly sees that the contour plots tend to be pretty much the same. The function is differentiable at (1,1)(1,1)

Warning

  • This interpretation of differentiability heavily relies on the fact that the linear approximation is nonzero at the approximation point.

  • To wit, let us consider the same function ff, but let us now use (0,0)(0,0) as approximation point. We have T(x,y)=0T(x,y) = 0.

  • Below, the surface and the tangent plane.

var('x,y') f(x,y) = 2*x^2 + y^2 x0, y0 =0,0 T(x,y) = taylor(f(x,y), (x,x0), (y,y0), 1) Surface = plot3d(f(x,y), (x,-1,1), (y,-1,1), color = "orange",opacity= 0.65, mesh = 1) Plane = plot3d(T(x,y), (x,-1,1), (y,-1,1), color = "green",opacity= 0.65, mesh = 1) show(Surface + Plane, aspect_ratio = [2,2,1])

A comment on the contour plots

The linear approximation is zero, so its contour plot is something tricky : at level zero, the contour line is the whole plane, whereas all other level curves are empty

Let us now see the contour plots for ff with different zoom factors. We see that near the origin they do not look like the contour lines of its linear approximation TT. Instead, they look like ellipses. However, one can compute limr0f(r)T(r)r=0 \lim_{\mathbf{r} \to \mathbf{0}} \frac{f(\mathbf{r}) - T(\mathbf{r})}{||\mathbf{r}||} = 0

Fig1 =contour_plot(f, (x,-1,1), (y,-1,1), cmap = "Oranges", fill = False, contours = 15) Fig2 =contour_plot(f, (x,-0.5,0.5), (y,-0.5,0.5), cmap = "Oranges", fill = False , contours = 15) Fig3 =contour_plot(f, (x,-0.1,0.11), (y,-0.1,0.1), cmap = "Oranges", fill = False , contours = 15) Array = graphics_array((Fig1, Fig2, Fig3)) Array.show(figsize = 8)
Image in a Jupyter notebook

Example 2

Let us consider the function ff given by f(x,y)=xyxyf(x,y) = ||x| - |y| | - |x| - |y|, and study its differentiability at (0,0)(0,0).

Using the limit definition of the partial derivatives, one can get that, at the origin, T(x,y)=0T(x,y) = 0.

Below we have the surface and its tangent plane. In particular, note that no matter how close one looks at the surface, it does not fit its tangent plane!

var('x,y') f(x,y) = abs(abs(x) - abs(y)) - abs(x) - abs(y) x0, y0 = 0,0 T(x,y) = 0 Surface = plot3d(f(x,y), (x,-1,1), (y,-1,1), color = "orange",opacity= 0.65, mesh = 1) Plane = plot3d(T(x,y), (x,-1,1), (y,-1,1), color = "green",opacity= 0.65, mesh = 1) show(Surface + Plane, aspect_ratio = [2,2,1])

A comment on the contour plots

Same comment as before here!

Let us now see the contour plots for ff with different zoom factors. We see that near the origin they do not look like the contour lines of its linear approximation TT.

Fig1 =contour_plot(f, (x,-1,1), (y,-1,1), cmap = "Oranges", fill = False, contours = 15) Fig2 =contour_plot(f, (x,-0.5,0.5), (y,-0.5,0.5), cmap = "Oranges", fill = False , contours = 15) Fig3 =contour_plot(f, (x,-0.1,.1), (y,-0.1,0.1), cmap = "Oranges", fill = False , contours = 15) Array = graphics_array((Fig1, Fig2, Fig3)) Array.show(figsize = 8)
Image in a Jupyter notebook

In order to show the function is not differentiable at (0,0)(0,0), one has to go by the definition: show that limr0f(r)T(r)r0 \lim_{\mathbf{r} \to \mathbf{0}} \frac{f(\mathbf{r}) - T(\mathbf{r})}{||\mathbf{r}||} \ne 0