Direction Field

Vector Calculus: graph of a 2D direction field

Complete Code

Download file: DirectionField.pg

POD for Macro Files

PG problem file

Explanation

DOCUMENT();
loadMacros('PGstandard.pl', 'PGML.pl', 'PGtikz.pl', 'PGcourse.pl');

Preamble

The macro PGtikz.pl is used to produced the direction field.

$graph = createTikZImage();
$graph->texPackages(['ifthen']);
$graph->BEGIN_TIKZ
\filldraw[
    draw=LightBlue,
    fill=white,
    rounded corners=10pt,
    thick,use as bounding box
] (-6,-6) rectangle (6,6);
\draw[dotted] (-5,-5) grid (5,5);
\draw[->] (-5,0) -- (5.25,0) node[above right] {\(x\)};
\foreach \x in {-5,...,-1,1,2,...,5} \draw(\x,-5) node [below] {\x};
\draw[->] (0,-5) -- (0,5.25) node[above right] {\(y\)};
\foreach \y in {-5,...,-1,1,2,...,5} \draw(-5,\y) node [left] {\y};
\foreach \x in {-4.5,-4,...,4.5} {
    \foreach \y in {-4.5,-4,...,4.5} {
        \ifthenelse{\equal{\x}{0} \AND \equal{\y}{0}}{}{
            \draw[thick, blue,->] (\x,\y) --
                ({\x+0.4*\y/sqrt(\x*\x+\y*\y)},{\y-0.4*\x/sqrt(\x*\x+\y*\y)});
            }
        }
    }
END_TIKZ

Setup

A direction field is a vector field where the length of the vectors are constant. We use the same technique as Two-D Vector Field.

The vector field <y,-x> is used and then when the vector is drawn is scaled by its length or sqrt(x^2+y^2). Since this is not defined at the origin, we don’t draw the vector there and use the ifthen package to load the \ifthenelse latex command.

If you want a slope field, where only the slope is draw with no arrow delete the -> in the option of the \draw command inside the \foreach loops.

BEGIN_PGML
This is a direction field for
[``\vec{v} =  \left< y, -x \right>``]

>> [@ image($graph, width=> 400) @]* <<
END_PGML

Statement

This shows the vector field graph.

BEGIN_PGML_SOLUTION
Solution explanation goes here.
END_PGML_SOLUTION

ENDDOCUMENT();

Solution

A solution should be provided here.