Difference between revisions of "VectorFields2D"
m (7 revisions: import all default namespace pages from old wiki) 

(No difference)

Latest revision as of 16:19, 14 May 2010
Vector Field Graphs in Two Dimensions
This PG code shows how to plot a vector field in two dimensions.
You may also be interested in Slope Fields, which also provides a different way to graph a vector field.
PG problem file  Explanation 

DOCUMENT(); loadMacros( "PGstandard.pl", "MathObjects.pl", "PGgraphmacros.pl", "VectorField2D.pl", ); TEXT(beginproblem()); $refreshCachedImages = 1; 
Initialization:
We need to include the macros file 
Context()>variables>add(y=>"Real"); # # Create a graph canvas # foreach my $i (0) { $gr[$i] = init_graph(5,5,5,5,grid=>[10,10],axes=>[0,0],pixels=>[400,400]); $gr[$i]>lb('reset'); foreach my $j (1..4) { $gr[$i]>lb( new Label(4.7, $j, $j,'black','center','middle')); $gr[$i]>lb( new Label(4.7, $j,$j,'black','center','middle')); $gr[$i]>lb( new Label( $j,4.7, $j,'black','center','middle')); $gr[$i]>lb( new Label( $j,4.7,$j,'black','center','middle')); } $gr[$i]>lb( new Label(4.7,0.2,'x','black','center','middle')); $gr[$i]>lb( new Label(0.2,4.7,'y','black','center','middle')); } VectorField2D( graphobject => $gr[0], Fx => Formula("x/(x^2+y^2)"), Fy => Formula("y/(x^2+y^2)"), xvar => "x", yvar => "y", xmin => 5, xmax => 5, ymin => 5, ymax => 5, xsamples => 10, ysamples => 10, vectorcolor => "blue", vectorscale => 1.5, vectorthickness => 2, xavoid=>0, yavoid=>0, ); 
Setup:
We create a blank graph canvas and add labels to it. Then, using the 
BEGIN_TEXT This is a velocity vector field for an explosion at the origin that decreases in speed the farther the distance is from the origin. $PAR $BCENTER \{ image(insertGraph($gr[0]),width=>400,height=>400,tex_size=>700) \} $ECENTER END_TEXT 
Main Text: The problem text section of the file is as we'd expect. 
$showPartialCorrectAnswers = 1; ENDDOCUMENT(); 
Answer Evaluation: We didn't ask any questions, so this is uninteresting. 
It is also possible, though not recommended, to plot a two dimensional vector field using LiveGraphics3D.
PG problem file  Explanation 

DOCUMENT(); loadMacros( "PGstandard.pl", "MathObjects.pl", "parserVectorUtils.pl", "PGcourse.pl", "LiveGraphicsVectorField2D.pl", ); TEXT(beginproblem()); 
Initialization: 
Context("Numeric"); Context()>variables>are(x=>"Real",y=>"Real",z=>"Real"); $plot = VectorField2D( Fx => Formula("y"), Fy => Formula("x"), xvar => 'x', yvar => 'y', xmin => 1, xmax => 1, ymin => 1, ymax => 1, xsamples => 4, ysamples => 4, axesframed => 1, xaxislabel => "X", yaxislabel => "Y", vectorcolor => "RGBColor[1.0,0.0,0.0]", vectorscale => 0.25, vectorthickness => 0.01, outputtype => 4, ); 
Setup:
The 
Context()>texStrings; BEGIN_TEXT $BCENTER \{ Live3Ddata( $plot, image => "coolvectorfield.png", size => [400,400], tex_size => 600, tex_center => 1, scale => 1.5, Live3D => [MOUSE_DRAG_ACTION => "NONE"] ); \} $ECENTER END_TEXT Context()>normalStrings; 
Main Text:
This is just like plotting a three dimensional vector field using the 
$showPartialCorrectAnswers = 1; ENDDOCUMENT(); 
Answer Evaluation: 