In [1]:
%display latex

First, we initialize our variables:

In [2]:
x,y,z=var('x y z')

Then we define our function $f$.

In [3]:
f(x,y,z)=x^2+y^2-z^2+1
f
Out[3]:

Next, we plot $f(x,y,z)=0$. Note that we want to name it something manifold_plot for example...

In [4]:
manifold_plot = implicit_plot3d(f(x,y,z)==0,(x,-5,5),(y,-5,5),(z,-5,5))
show(manifold_plot,viewer='tachyon')

Now, let's choose a point $p=(x_0,y_0,z_0)$ at which to compute the tangent space. It's important that $p$ is on our manifold, so we need $f(x_0,y_0,z_0)=0$.

In [5]:
x0,y0,z0=(0,-sqrt(3),-2)
f(x0,y0,z0)
Out[5]:

Let's add it to our plot, so we can see where it is (we add the options size=5 and color='black' to make it more visible). To do this, we type:

In [6]:
p=point([x0,y0,z0],size=10,color='black')
show(p,viewer='tachyon')

Of course, we'd like to see where it is on our manifold, so we should ask sage to show both the point and the manifold:

In [7]:
show(p+manifold_plot,viewer='tachyon')

Now let's compute our derivatives, $a=\frac{\partial f}{\partial x}\rvert_{(x_0,y_0,z_0)},b=\frac{\partial f}{\partial y}\rvert_{(x_0,y_0,z_0)},c=\frac{\partial f}{\partial z}\rvert_{(x_0,y_0,z_0)}$, evaluated at $(x_0,y_0,z_0)$.

To get the general expression for $\frac{\partial f}{\partial x}$ (written as a function of $(x,y,z)$), we type:

In [8]:
diff(f(x,y,z),x)
Out[8]:

This is the general expression. To evaluate it at $(x_0,y_0,z_0)$, we need to substitute $x=x_0,y=y_0,z=z_0$. We do this by typing:

In [9]:
a=diff(f(x,y,z),x).subs(x=x0,y=y0,z=z0)
a
Out[9]:

To compute all three of the numbers $a,b,c$, we type:

In [10]:
a=diff(f(x,y,z),x).subs(x=x0,y=y0,z=z0)
b=diff(f(x,y,z),y).subs(x=x0,y=y0,z=z0)
c=diff(f(x,y,z),z).subs(x=x0,y=y0,z=z0)
(a,b,c)
Out[10]:

The equation for the tangent space at $(x_0,y_0,z_0)$ is then the zero set of $g(x,y,z)=0$, where $$g(x,y,z)=a(x-x_0)+b(y-y_0)+c(z-z_0).$$

In [11]:
g(x,y,z) = a*(x-x0)+b*(y-y0)+c*(z-z0)
g
Out[11]:

Now let's plot the tangent space. We will make it red by typing the instruction color='red' and semi-transparent by typing the instruction opacity=0.75.

In [12]:
tangent_plane_plot = implicit_plot3d(g(x,y,z)==0,
                                     (x,-5,5),(y,-5,5),(z,-5,5),
                                     opacity=0.75,color='red')
show(tangent_plane_plot,viewer='tachyon')

It's a two dimensional plane! We should be happy, because we showed in class that the tangent space to an $n$-dimensional manifold is $n$-dimensional... so this is the correct number of dimensions! It also looks like a vector space, and we showed that the tangent space is a vector space... Yay!

Ok, but it's a little unsatisfying, because we don't see any direct relationship between it and the manifold. To show them both at the same time, type:

In [13]:
show(tangent_plane_plot+p+manifold_plot,viewer='tachyon')

As you can see, the tangent space touches the manifold at exactly that point..

Ok, now let's try plotting some curves and their tangent spaces. Let's consider the curve: $$\gamma(t)=(\sinh(t),\lambda\frac{\cosh(t)}{\sqrt{1-\lambda^2}},\frac{\cosh(t)}{\sqrt{1-\lambda^2}})$$ for some fixed constant $\lambda$. Let's choose $\lambda=\cos(\pi/6)$, since this will cause the curve to pass through our previously selected point $(x_0=0,y_0=-\sqrt(3),z_0=-2)$ at $t=0$.

In [14]:
t = var('t')
lam=cos(pi/6)
gam(t)=(sinh(t),-lam*cosh(t)/sqrt(1-lam^2),-cosh(t)/sqrt(1-lam^2))
gam
Out[14]:

To plot our curve, we use the command parametric_plot3d, we'll also add the options color='green' and thickness=4 to make it more visible.

In [15]:
gam_plot = parametric_plot3d(gam(t),(t,-1.75,1.75),color='green',thickness=4)
show(gam_plot,viewer='tachyon')

To plot show it along with our manifold and the point $p=(x_0,y_0,z_0)$, we type:

In [16]:
show(gam_plot+manifold_plot+p,viewer='tachyon')

Now let's plot the tangent space to our curve $\gamma(t)=(\gamma_x(t),\gamma_y(t),\gamma_z(t))$ at $t=t_0$, for some fixed time $t_0$ (say $t_0=1$, for instance). To do this, we first need to compute the derivatives $$v_x=\frac{\partial \gamma_x}{\partial t}\rvert_{t=t_0}, v_y=\frac{\partial \gamma_y}{\partial t}\rvert_{t=t_0}, v_z=\frac{\partial \gamma_z}{\partial t}\rvert_{t=t_0}.$$ we do this by typing the following:

In [17]:
t0=1
vx,vy,vz=diff(gam(t),t).subs(t=t0)
(vx,vy,vz)
Out[17]:

The equation for the tangent space to our curve $\gamma(t)$ at $t=1$ is given by $$\sigma(t)=(\gamma_x(t_0)+tv_x,\gamma_y(t_0)+tv_y,\gamma_z(t_0)+tv_z).$$

In [18]:
gamx,gamy,gamz=gam(t0)
sig(t)=(gamx+t*vx,gamy+t*vy,gamz+t*vz)
sig
Out[18]:

Now let's plot the tangent space and the curve at the same time:

In [19]:
tangent_line_plot = parametric_plot3d(sig(t),(t,-1.75,1.75),color='purple',thickness=4)
show(tangent_line_plot+gam_plot,viewer='tachyon')

Now, it so happens that our curve $\gamma(t)$ is actually inside the manifold $M$. Moreover, we made the choices $\lambda=cos(\pi/6)$ and $p=(0,-\sqrt(3),-2)$ so that $\gamma(0)=p$. This means that $\gamma(t)$ represents a vector in $M$ at $p$. To understand what this means, let's plot the tangent space to $M$ at $p=\gamma(0)$ and the tangent space to $\gamma(t)$ at $t=0$. First we need to compute the tangent space to $\gamma(t)$ at $t=0$ by setting $s=0$ in the previous code:

In [20]:
t0=0
vx,vy,vz=diff(gam(t),t).subs(t=t0)
(vx,vy,vz)
gamx,gamy,gamz=gam(t0)
sig(t)=(gamx+t*vx,gamy+t*vy,gamz+t*vz)
tangent_line_plot = parametric_plot3d(sig(t),(t,-5,5),color='purple',thickness=4)

And now let's show both tangent spaces together, along with the point $p$:

In [21]:
show(tangent_line_plot+tangent_plane_plot+p,viewer='tachyon')

As you can see, since the curve $\gamma(t)$ is inside $M$ (i.e. $\gamma(t)\in M$ for every $t$), the tangent space to $\gamma(t)$ at $t=0$ is a subspace of the tangent space to $M$ at $\gamma(t)$. Let's show both tangent spaces, the curve, and the manifold, all at once.

In [22]:
show(tangent_line_plot+tangent_plane_plot+gam_plot+manifold_plot+p,viewer='tachyon')
In [ ]: