Two-D Vector Field

Vector Calculus: graph of a 2D vector field

Complete Code

Download file: VectorFieldGraph2D.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 vector 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,...,4} {
    \foreach \y in {-4,...,4} {
        \ifthenelse{\equal{\x}{0} \AND \equal{\y}{0}}{}{
            \draw[thick, blue,->] (\x,\y) -- ({\x+\x/(\x*\x+\y*\y)},{\y+\y/(\x*\x+\y*\y)});
            }
    }
}
END_TIKZ

Setup

The vector field is created directly. The vector field is <x/(x2+y2), y/(x2+y2)> which is not defined at the origin. Therefore, we don’t draw the vector there and use the ifthen package to load the \ifthenelse latex command.

The vector is created using the \draw command.

BEGIN_PGML
This is a velocity vector field for an explosion at the origin
that decreases in speed the farther the distance is from the origin.

[``\vec{v} =  \left< \frac{x}{x^2+y^2}, \frac{y}{x^2+y^2} \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.