Sage: Parametric curves and vector fields

This is one in a series of posts containing short snippets of Sage code for my students to use: see my page on Sage.

Vector fields can be plotted using the vector_field command:


vfield = vector([y1+y2,y1-y2])


Sometimes it is convenient to plot the normalized version of the vector field:


vfield = vector([y1+y2,y1-y2])
nfield = vfield/vfield.norm()


Parametric curves can be plotted using the parametric_plot function:


y1(t) = 2*exp(-.1*t)*cos(t)
y2(t) = 2*exp(-.1*t)*sin(t)

parametric_plot([y1(t),y2(t)], (t,0,5*pi))

Here’s a fun example that has a (normalized) vector field as well as a parametric curve that follows the vector field.


vfield = vector([y1+y2,y1-y2])
nfield = vfield/vfield.norm()

nplot = plot_vector_field(nfield,(y1,-2,5),(y2,-2,5))

y1(t) = (1+sqrt(2))*exp(sqrt(2)*t) + (1-sqrt(2))*exp(-sqrt(2)*t)
y2(t) = exp(sqrt(2)*t) + exp(-sqrt(2)*t)

pplot = parametric_plot([y1(t),y2(t)], (t,-1,.5))

nplot + pplot

Related to vector fields are the slope field plots used in the differential equations course. Suppose we have the differential equation

\frac{dy}{dt} = y(1-y).

The corresponding slope field is given by:

plot_slope_field(y*(1-y), (t,0,2), (y,-1,2))

Here is a fun example:

plot_slope_field(y*(1-y)*sin(t), (t,0,10), (y,-1,2))
This entry was posted in Sage, Uncategorized. Bookmark the permalink.

Leave a comment here

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s