Parametric Plots

127 days ago by charliet

We first create a variable called t (the computer doesn't know we want to call our parameter t)
t = var('t') 
       
Sage is based on Python, which is an object-oriented language. This means that we can create a plot, and give it a name (here, p1, and p2) and then work with it.
p1 = parametric_plot((-1+2*t,t-1),(t,0,1)) p2 = parametric_plot((1-2*(t-1),2*(t-1)),(t,1,2)) 
       
Typing a question mark after a command will bring up the documentation. Sometimes this helps, other times it is less edifying. Two question marks will bring up the source code.
parametric_plot? 
       

File: /sagenb/sage_install/sage-4.7.2/local/lib/python2.6/site-packages/sage/misc/decorators.py

Type: <type ‘function’>

Definition: parametric_plot(funcs, aspect_ratio=1.0, *args, **kwargs)

Docstring:

Plot a parametric curve or surface in 2d or 3d.

parametric_plot() takes two or three functions as a list or a tuple and makes a plot with the first function giving the x coordinates, the second function giving the y coordinates, and the third function (if present) giving the z coordinates.

In the 2d case, parametric_plot() is equivalent to the plot() command with the option parametric=True. In the 3d case, parametric_plot() is equivalent to parametric_plot3d(). See each of these functions for more help and examples.

INPUT:

  • funcs - 2 or 3-tuple of functions, or a vector of dimension 2 or 3.
  • other options - passed to plot() or parametric_plot3d()

EXAMPLES: We draw some 2d parametric plots. Note that the default aspect ratio is 1, so that circles look like circles.

sage: t = var('t')
sage: parametric_plot( (cos(t), sin(t)), (t, 0, 2*pi))
sage: parametric_plot( (sin(t), sin(2*t)), (t, 0, 2*pi), color=hue(0.6) )
sage: parametric_plot((1, t), (t, 0, 4))

Note that in parametric_plot, there is only fill or no fill.

sage: parametric_plot((t, t^2), (t, -4, 4), fill = True)

A filled Hypotrochoid:

sage: parametric_plot([cos(x) + 2 * cos(x/4), sin(x) - 2 * sin(x/4)], (x,0, 8*pi), fill = True)

sage: parametric_plot( (5*cos(x), 5*sin(x), x), (x,-12, 12), plot_points=150, color="red")

sage: y=var('y')
sage: parametric_plot( (5*cos(x), x*y, cos(x*y)), (x, -4,4), (y,-4,4))

sage: t=var('t')
sage: parametric_plot( vector((sin(t), sin(2*t))), (t, 0, 2*pi), color='green')
sage: parametric_plot( vector([t, t+1, t^2]), (t, 0, 1))

TESTS:

sage: parametric_plot((x, t^2), (x, -4, 4))
Traceback (click to the left of this block for traceback)
...
                                
                            

File: /sagenb/sage_install/sage-4.7.2/local/lib/python2.6/site-packages/sage/misc/decorators.py

Type: <type ‘function’>

Definition: parametric_plot(funcs, aspect_ratio=1.0, *args, **kwargs)

Docstring:

Plot a parametric curve or surface in 2d or 3d.

parametric_plot() takes two or three functions as a list or a tuple and makes a plot with the first function giving the x coordinates, the second function giving the y coordinates, and the third function (if present) giving the z coordinates.

In the 2d case, parametric_plot() is equivalent to the plot() command with the option parametric=True. In the 3d case, parametric_plot() is equivalent to parametric_plot3d(). See each of these functions for more help and examples.

INPUT:

  • funcs - 2 or 3-tuple of functions, or a vector of dimension 2 or 3.
  • other options - passed to plot() or parametric_plot3d()

EXAMPLES: We draw some 2d parametric plots. Note that the default aspect ratio is 1, so that circles look like circles.

sage: t = var('t')
sage: parametric_plot( (cos(t), sin(t)), (t, 0, 2*pi))
sage: parametric_plot( (sin(t), sin(2*t)), (t, 0, 2*pi), color=hue(0.6) )
sage: parametric_plot((1, t), (t, 0, 4))

Note that in parametric_plot, there is only fill or no fill.

sage: parametric_plot((t, t^2), (t, -4, 4), fill = True)

A filled Hypotrochoid:

sage: parametric_plot([cos(x) + 2 * cos(x/4), sin(x) - 2 * sin(x/4)], (x,0, 8*pi), fill = True)

sage: parametric_plot( (5*cos(x), 5*sin(x), x), (x,-12, 12), plot_points=150, color="red")

sage: y=var('y')
sage: parametric_plot( (5*cos(x), x*y, cos(x*y)), (x, -4,4), (y,-4,4))

sage: t=var('t')
sage: parametric_plot( vector((sin(t), sin(2*t))), (t, 0, 2*pi), color='green')
sage: parametric_plot( vector([t, t+1, t^2]), (t, 0, 1))

TESTS:

sage: parametric_plot((x, t^2), (x, -4, 4))
Traceback (most recent call last):
...
ValueError: there are more variables than variable ranges

sage: parametric_plot((1, x+t), (x, -4, 4))
Traceback (most recent call last):
...
ValueError: there are more variables than variable ranges

sage: parametric_plot((-t, x+t), (x, -4, 4))
Traceback (most recent call last):
...
ValueError: there are more variables than variable ranges

sage: parametric_plot((1, x+t, y), (x, -4, 4), (t, -4, 4))
Traceback (most recent call last):
...
ValueError: there are more variables than variable ranges

sage: parametric_plot((1, x, y), 0, 4)
Traceback (most recent call last):
...
ValueError: there are more variables than variable ranges
Here, seeing the plots together is simple.
p1+p2 
       
What about a 3D plot? (I think this needs Java, and may need your browser to be reasonably happy, it crashed mine twice before working) (Use your mouse, scrolling to zoom and moving it to see around it. Nifty, huh?!) [I'm sorry, this appears only to work on an "active" worksheet (rather than just viewing one) - sign up for an account and get sage-ing!]
parametric_plot((cos(t),sin(t),t),(t,-10,10))