Application Center - Maplesoft

App Preview:

Classroom Tips and Techniques: Plotting Curves Defined Parametrically

You can switch back to the summary page by clicking here.

Learn about Maple
Download Application


 

Image 

Classroom Tips and Techniques: Plotting Curves Defined Parametrically 

 

Robert J. Lopez 

Emeritus Professor of Mathematics and Maple Fellow 

Maplesoft 

Introduction 

 

If the vector representation of a curve is considered to be a parametric representation, then (in Maple) there are at least three ways to graph a curve defined parametrically.  A purely parametric representation (not using vectors) in 2D is graphed with the plot command; in 3D, with the spacecurve command.  A vector representation in 2D is graphed with the SpaceCurve, or PlotPositionVector commands (all in the VectorCalculus packages); in 3D, with the spacecurve and the VectorCalculus commands.  An integral curve of a vector field can be drawn with the FlowLine command in the Student[VectorCalculus] package. 

 

In this article, we compare the options for graphing curves given parametrically in two or three dimensions. 

 

Initializations 

 

restart; 1; with(plots); -1; with(DEtools); -1; with(VectorCalculus); -1; BasisFormat(false); -1; interface(typesetting = extended); -1
restart; 1; with(plots); -1; with(DEtools); -1; with(VectorCalculus); -1; BasisFormat(false); -1; interface(typesetting = extended); -1
restart; 1; with(plots); -1; with(DEtools); -1; with(VectorCalculus); -1; BasisFormat(false); -1; interface(typesetting = extended); -1
restart; 1; with(plots); -1; with(DEtools); -1; with(VectorCalculus); -1; BasisFormat(false); -1; interface(typesetting = extended); -1
restart; 1; with(plots); -1; with(DEtools); -1; with(VectorCalculus); -1; BasisFormat(false); -1; interface(typesetting = extended); -1
restart; 1; with(plots); -1; with(DEtools); -1; with(VectorCalculus); -1; BasisFormat(false); -1; interface(typesetting = extended); -1
 

 

The plot and spacecurve Commands 

 

Figure 1 uses the plot command to graph the parametrically-given curve x = cos(t), y = sin(t). 

 

plot([cos(t), sin(t), t = 0 .. `+`(`*`(2, `*`(Pi)))], labels = [x, y]) 

Plot_2d
 

Figure 1   Parametric plot in 2D 

 

The syntax for the plot command is a list of the form [x(t), y(t), t = a .. b], where, of course, t can be any parameter.  The list must have these three elements, and the range must be inside the list. 

 

Figure 2 uses the spacecurve command to graph one loop of the helix x = cos(t), y = sin(t), z = t. 

 

spacecurve([cos(t), sin(t), t], t = 0 .. `+`(`*`(2, `*`(Pi))), color = red, axes = box, labels = [x, y, z])
spacecurve([cos(t), sin(t), t], t = 0 .. `+`(`*`(2, `*`(Pi))), color = red, axes = box, labels = [x, y, z])
 

Plot
 

Figure 2   Parametric plot of a helix in 3D 

 

The syntax for the spacecurve command is flexible.  The list [x(t), y(t), z(t)] may or may not include the range; the list of three functions can even be a vector! 

 

In 2D, the plot command cannot provide a parametric plot of a curve given parametrically as a vector.  Thus, a number of users have written their own parametric plotting functions that admit a vector in both two and three dimensions.  Perhaps this observation led to the functionalities in the PlotPositionVector, SpaceCurve, and FlowLine commands in the VectorCalculus packages. 

 

The VectorCalculus Commands 

 

The original implementation of the VectorCalculus packages was based on the constructs of the free vector and the VectorField. In Cartesian coordinates, the point x[1], x[2], () .. (), x[n] is identified with the "free" vector `<,>`(x[1], x[2], () .. (), x[n]) whose tail is at the origin and whose head is at the point.  This works fine in Cartesian coordinates where the basis vectors are constant.  (It does not work well in nonCartesian coordinates where the basis vectors change from point to point.) 

 

Figure 3 uses the SpaceCurve command to plot the (Cartesian) free vector  

 

`:=`(V, `<,>`(cos(t), sin(t))) 

`:=`(V, Vector[column](%id = 50479536)) (4.1)
 

 

SpaceCurve(V, t = 0 .. `+`(`*`(2, `*`(Pi)))) 

Plot_2d
 

Figure 3   2D curve defined parametrically by a free vector, graphed with the SpaceCurve command 

 

The SpaceCurve command could equally well have been applied to the free vector `<,>`(cos(t), sin(t), t), thereby producing the graph of a helix.  Thus, the distinction between dimensions has been eliminated.   

 

Updates to the VectorCalculus packages introduced the construct of the PositionVector R = `+`(`*`(x, `*`(i)), `*`(y, `*`(j)), `*`(z, `*`(k))) for defining curves (and surfaces).  The curve graphed in Figures 1 and 3 would be represented by 

 

`:=`(R, PositionVector([cos(t), sin(t)])) 

`:=`(R, Vector[column](%id = 51075340)) (4.2)
 

 

and would be graphed with the PlotPositionVector command as per Figure 4. 

 

PlotPositionVector(R, t = 0 .. `+`(`*`(2, `*`(Pi))), curveoptions = [color = red]) 

Plot_2d
 

Figure 4  PositionVector graphed by PlotPositionVector command 

 

An option to the PlotPositionVector command provides for plotting the arrows of a vector field, and other options provide for plotting the arrows of the tangent, principal normal, and derivative fields for the position vector.  This is illustrated in Figure 5 where tangent vectors are shown in black, and normal vectors are shown in green. 

 

PlotPositionVector(R, t = 0 .. `+`(`*`(2, `*`(Pi))), curveoptions = [color = red], tangent = true, normal = true)
PlotPositionVector(R, t = 0 .. `+`(`*`(2, `*`(Pi))), curveoptions = [color = red], tangent = true, normal = true)
 

Plot_2d
 

 

Figure 5   Drawing tangent and principal normal vectors with the PlotPositionVector command 

 

The VectorField command defines a vector at each point of `^`(real, n).  Figure 6 superimposes ten vectors of the vector field 

 

`:=`(F, VectorField(`<,>`(`+`(`*`(`^`(x, 2)), y), `+`(x, `-`(y))), cartesian[x, y])) 

`:=`(F, Vector[column](%id = 51086152)) (4.3)
 

 

on the curve R in Figure 4. 

 

PlotPositionVector(R, t = 0 .. `+`(`*`(2, `*`(Pi))), curveoptions = [color = red, scaling = constrained], vectorfield = F, vectorfieldoptions = [color = green], vectornum = 10)
PlotPositionVector(R, t = 0 .. `+`(`*`(2, `*`(Pi))), curveoptions = [color = red, scaling = constrained], vectorfield = F, vectorfieldoptions = [color = green], vectornum = 10)
PlotPositionVector(R, t = 0 .. `+`(`*`(2, `*`(Pi))), curveoptions = [color = red, scaling = constrained], vectorfield = F, vectorfieldoptions = [color = green], vectornum = 10)
 

Plot_2d
 

Figure 6   Arrows of the vector field F evaluated along the curve R 

 

The integral of a vector field produces curves called flow lines along which the vectors of the field are tangent. (For example, the flow lines of an electric field are called field lines.)  The FlowLine command in the Student[VectorCalculus] package will draw the flow line emanating from a given point, as illustrated for the field F and Figure 7. 

 

Student[VectorCalculus]:-FlowLine(F, `<,>`(-3, 3), fieldoptions = [grid = [10, 10], arrows = medium, fieldstrength = fixed])
Student[VectorCalculus]:-FlowLine(F, `<,>`(-3, 3), fieldoptions = [grid = [10, 10], arrows = medium, fieldstrength = fixed])
 

Plot_2d
 

Figure 7   The flow line emanating from 1, 1 for the field F 

 

Unfortunately, it is not possible to ask the FlowLine command for more than one flow line in Maple 12.  We hope to see this shortcoming corrected in a future release of Maple.  The alternative is to write the differential equations 

 

`:=`(DEx, diff(x(t), t) = eval(F[1], [x = x(t), y = y(t)])); 1; `:=`(DEy, diff(y(t), t) = eval(F[2], [x = x(t), y = y(t)])) 

 

Typesetting:-mprintslash([`:=`(DEx, diff(x(t), t) = `+`(`*`(`^`(x(t), 2)), y(t)))], [diff(x(t), t) = `+`(`*`(`^`(x(t), 2)), y(t))])
Typesetting:-mprintslash([`:=`(DEy, diff(y(t), t) = `+`(x(t), `-`(y(t))))], [diff(y(t), t) = `+`(x(t), `-`(y(t)))]) (4.4)
 

 

and to integrate them with the DEplot command from the DEtools package.  The result for the initial points 

 

`:=`(inits, [seq([0, 1, k], k = -4 .. 4)]) 

Typesetting:-mprintslash([`:=`(inits, [[0, 1, -4], [0, 1, -3], [0, 1, -2], [0, 1, -1], [0, 1, 0], [0, 1, 1], [0, 1, 2], [0, 1, 3], [0, 1, 4]])], [[[0, 1, -4], [0, 1, -3], [0, 1, -2], [0, 1, -1], [0, 1... (4.5)
 

 

appears in Figure 8. 

 

DEplot([DEx, DEy], [x(t), y(t)], t = 0 .. 3, x = -2 .. 5, y = -4 .. 4, inits, dirgrid = [10, 10], arrows = medium, color = red, linecolor = black, thickness = 2)
DEplot([DEx, DEy], [x(t), y(t)], t = 0 .. 3, x = -2 .. 5, y = -4 .. 4, inits, dirgrid = [10, 10], arrows = medium, color = red, linecolor = black, thickness = 2)
DEplot([DEx, DEy], [x(t), y(t)], t = 0 .. 3, x = -2 .. 5, y = -4 .. 4, inits, dirgrid = [10, 10], arrows = medium, color = red, linecolor = black, thickness = 2)
 

Plot_2d
 

 

Figure 8   Integration of the field F by means of the DEplot command 

 

Task Templates 

 

Maple 12 provides a task template for interactively generating orbits in the phase plane of the autonomous system 

 

diff(x(t), t) = f(x(t), y(t))  

diff(y(t), t) = g(x(t), y(t))  

 

Tools/Tasks/Browse: Differential Equations/ODEs/Phase portrait - Autonomous Systems 

 

Phase Portraits for Autonomous Systems 

Plot Window 

 

Embedded componentEmbedded component,     Embedded componentEmbedded component 

 

Differential Equations 

 

diff(x(t), t) = F(x(t), y) = Embedded component 

diff(y(t), t) = G(x, y(t)) = Embedded component 

 

Equilibrium (Critical) Points 

 

Embedded component 

 

Parameter  

     Embedded componentEmbedded component                      Enter Data 

Embedded component 

 Erase Phase Portrait                Clear All 

 

Clicking on a point in the phase plane generates the orbit through that point. 

 

Since graphing the flow lines of a planar vector field is equivalent to drawing the phase portrait of this same autonomous system, the next version of Maple will have an additional task template (available now from the author): 

 

Tools/Tasks/Browse: Vector Calculus/Integrate Planar Vector Field 

 

Integrate Planar Vector Field 

Plot Window                      Insert Defaults: 

 

Embedded componentEmbedded component,     Embedded componentEmbedded component 

 

Vector Field 

Component 1: Embedded component 

Component 2: Embedded component 

 

Coordinates 

System: Embedded component        Variables: Embedded component 

 

Path Parameter           Insert Defaults: 

 

     Embedded componentEmbedded componentEmbedded component           Enter Data 

Embedded component 

 Erase Graph                Clear All 

Embedded component 

 

This task template is also based on the DEplot command from the DEtools package.  However, the extra steps of converting the components of the vector field to the syntax of differential equations are hidden in the code behind the buttons. 

 

Legal Notice: The copyright for this application is owned by Maplesoft. The application is intended to demonstrate the use of Maple to solve a particular problem. It has been made available for product evaluation purposes only and may not be used in any other context without the express permission of Maplesoft.