Vector Field Plot

Use the plots.pl macro to generate a vector/direction field.

Complete Code

Download file: VectorFieldPlot.pg

POD for Macro Files

PG problem file

Explanation

DOCUMENT();

loadMacros('PGstandard.pl', 'PGML.pl', 'plots.pl', 'PGcourse.pl');

Preamble

The macro plots.pl is used to create the plot.

$plot = Plot(xlocation => 'bottom', ylocation => 'left');

$plot->add_vectorfield(
    Fx        => 'sin(y)',
    Fy        => 'cos(x)',
    xvar      => 'x',
    yvar      => 'y',
    xmin      => -4,
    xmax      =>  4,
    ymin      => -4,
    ymax      =>  4,
    xsteps    =>  20,
    ysteps    =>  15,
    color     => 'blue',
    scale     => 0.5,
    normalize => 1,
);

$altText =
    'The direction field graph of <sin(x), cos(x)> which look a '
    . 'clockwise swirl centered at (pi/2,0), and two counterclockwise '
    . 'swirls at (-pi/2,pi) and (-pi/2,-pi) among others.  The plotting '
    . 'window is [-4,4] x [-4,4]';

Setup

This problem generates the vector field <sin y, cos x>. First, create a Plot object where the axes are placed in the bottom left corner (instead of the origin).

The vector field is created with the add_vectorfield method. Most of the attributes shown are required. The scale attribute gives a relative size of the arrows and normalize will make a direction field (the length of all vectors are equal).

BEGIN_PGML

The following is a vector field plot of [`\langle \sin x, \cos x \rangle`] on
the domain [`[-4,4] \times [-4,4]`].

>>[![$altText]!]{$plot}{400}<<

END_PGML

Statement

This is the problem statement in PGML.
BEGIN_PGML_SOLUTION
Solution explanation goes here.
END_PGML_SOLUTION

ENDDOCUMENT();

Solution

A solution should be provided here.