Difference between revisions of "VectorFields2D"
(New page: <h2>Vector Field Graphs (in two dimensions)</h2> <!-- Header for these sections -- no modification needed --> <p style="background-color:#eeeeee;border:black solid 1px;padding:3px;"> ...) |
(added historical tag and gave updated problem link) |
||
(7 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
− | <h2>Vector Field Graphs (in two dimensions)</h2> |
||
+ | {{historical}} |
||
+ | |||
+ | <p style="font-size: 120%;font-weight:bold">This problem has been replaced with [https://openwebwork.github.io/pg-docs/sample-problems/VectorCalc/VectorFieldGraph2D.html a newer version of this problem]</p> |
||
+ | <h2>Vector Field Graphs in Two Dimensions</h2> |
||
<!-- Header for these sections -- no modification needed --> |
<!-- Header for these sections -- no modification needed --> |
||
<p style="background-color:#eeeeee;border:black solid 1px;padding:3px;"> |
<p style="background-color:#eeeeee;border:black solid 1px;padding:3px;"> |
||
− | <em>This PG code shows how to plot a vector field in two dimensions. |
+ | <em>This PG code shows how to plot a vector field in two dimensions. |
+ | <br /> |
||
+ | <br /> |
||
+ | You may also be interested in [[SlopeFields|Slope Fields]], which also provides a different way to graph a vector field. |
||
+ | </em> |
||
</p> |
</p> |
||
Line 33: | Line 36: | ||
TEXT(beginproblem()); |
TEXT(beginproblem()); |
||
+ | |||
+ | $refreshCachedImages = 1; |
||
</pre> |
</pre> |
||
</td> |
</td> |
||
Line 79: | Line 84: | ||
ysamples => 10, |
ysamples => 10, |
||
vectorcolor => "blue", |
vectorcolor => "blue", |
||
− | vectorscale => |
+ | vectorscale => 1.5, |
vectorthickness => 2, |
vectorthickness => 2, |
||
xavoid=>0, |
xavoid=>0, |
||
Line 89: | Line 94: | ||
<p> |
<p> |
||
<b>Setup:</b> |
<b>Setup:</b> |
||
− | We create a blank graph canvas and add labels to it. Then, using the <code>VectorField2D()</code> subroutine, we specify the formula for the vector field and its parameters. The values for <code>xsamples</code> and <code>ysamples</code> were chosen so that the tails of the vectors would be on lattice points (this routine automatically adds one to the samples values, which is usually what you want since there are 11 integers between -5 and 5 including endpoints). You can uniformly rescale the length of all the vectors in the vector field by setting <code>vectorscale</code> to a different value. You can avoid one point with coordinates (xavoid,yavoid) where the vector field may be undefined. |
+ | We create a blank graph canvas and add labels to it. Then, using the <code>VectorField2D()</code> subroutine, we specify the formula for the vector field and its parameters. The values for <code>xsamples</code> and <code>ysamples</code> were chosen so that the tails of the vectors would be on lattice points (this routine automatically adds one to the samples values, which is usually what you want since there are 11 integers between -5 and 5 including endpoints). You can uniformly rescale the length of all the vectors in the vector field by setting <code>vectorscale</code> to a different value (natural length is 1). You can avoid one point with coordinates (xavoid,yavoid) where the vector field may be undefined. |
</p> |
</p> |
||
</td> |
</td> |
||
Line 130: | Line 135: | ||
<b>Answer Evaluation:</b> |
<b>Answer Evaluation:</b> |
||
We didn't ask any questions, so this is uninteresting. |
We didn't ask any questions, so this is uninteresting. |
||
+ | </p> |
||
+ | </td> |
||
+ | </tr> |
||
+ | </table> |
||
+ | |||
+ | <p style="text-align:center;"> |
||
+ | [[IndexOfProblemTechniques|Problem Techniques Index]] |
||
+ | </p> |
||
+ | |||
+ | [[Category:Problem Techniques]] |
||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | <p style="background-color:#eeeeee;border:black solid 1px;padding:3px;"> |
||
+ | <em>It is also possible, though not recommended, to plot a two dimensional vector field using LiveGraphics3D.</em> |
||
+ | </p> |
||
+ | |||
+ | <p style="text-align:center;"> |
||
+ | [[IndexOfProblemTechniques|Problem Techniques Index]] |
||
+ | </p> |
||
+ | |||
+ | <table cellspacing="0" cellpadding="2" border="0"> |
||
+ | |||
+ | <tr valign="top"> |
||
+ | <th> PG problem file </th> |
||
+ | <th> Explanation </th> |
||
+ | </tr> |
||
+ | |||
+ | <!-- Load specialized macro files section --> |
||
+ | |||
+ | <tr valign="top"> |
||
+ | <td style="background-color:#ddffdd;border:black 1px dashed;"> |
||
+ | <pre> |
||
+ | DOCUMENT(); |
||
+ | |||
+ | loadMacros( |
||
+ | "PGstandard.pl", |
||
+ | "MathObjects.pl", |
||
+ | "parserVectorUtils.pl", |
||
+ | "PGcourse.pl", |
||
+ | "LiveGraphicsVectorField2D.pl", |
||
+ | ); |
||
+ | |||
+ | |||
+ | TEXT(beginproblem()); |
||
+ | </pre> |
||
+ | </td> |
||
+ | <td style="background-color:#ccffcc;padding:7px;"> |
||
+ | <p> |
||
+ | <b>Initialization:</b> |
||
+ | </p> |
||
+ | </td> |
||
+ | </tr> |
||
+ | |||
+ | <!-- Setup section --> |
||
+ | |||
+ | <tr valign="top"> |
||
+ | <td style="background-color:#ffffdd;border:black 1px dashed;"> |
||
+ | <pre> |
||
+ | 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, |
||
+ | ); |
||
+ | </pre> |
||
+ | </td> |
||
+ | <td style="background-color:#ffffcc;padding:7px;"> |
||
+ | <p> |
||
+ | <b>Setup:</b> |
||
+ | The <code>VectorField2D()</code> routine provided by the <code>LiveGraphicsVectorField2D.pl</code> macro is different from the routine by the same name provided by the <code>VectorField2D.pl</code> macro. Its features are the same as for [[VectorFields3D|vector fields in three dimensions]]. |
||
+ | </p> |
||
+ | </td> |
||
+ | </tr> |
||
+ | |||
+ | <!-- Question text section --> |
||
+ | |||
+ | <tr valign="top"> |
||
+ | <td style="background-color:#ffdddd;border:black 1px dashed;"> |
||
+ | <pre> |
||
+ | Context()->texStrings; |
||
+ | BEGIN_TEXT |
||
+ | $BCENTER |
||
+ | \{ |
||
+ | Live3Ddata( |
||
+ | $plot, |
||
+ | image => "cool-vector-field.png", |
||
+ | size => [400,400], |
||
+ | tex_size => 600, |
||
+ | tex_center => 1, |
||
+ | scale => 1.5, |
||
+ | Live3D => [MOUSE_DRAG_ACTION => "NONE"] |
||
+ | ); |
||
+ | \} |
||
+ | $ECENTER |
||
+ | END_TEXT |
||
+ | Context()->normalStrings; |
||
+ | </pre> |
||
+ | <td style="background-color:#ffcccc;padding:7px;"> |
||
+ | <p> |
||
+ | <b>Main Text:</b> |
||
+ | This is just like plotting a three dimensional vector field using the <code>LiveGraphics3D.pl</code> macro, except that |
||
+ | we must specify <code>Live3D => [MOUSE_DRAG_ACTION => "NONE"]</code> so that the graph is immovable. |
||
+ | </p> |
||
+ | </td> |
||
+ | </tr> |
||
+ | |||
+ | <!-- Answer section --> |
||
+ | |||
+ | <tr valign="top"> |
||
+ | <td style="background-color:#eeddff;border:black 1px dashed;"> |
||
+ | <pre> |
||
+ | $showPartialCorrectAnswers = 1; |
||
+ | |||
+ | ENDDOCUMENT(); |
||
+ | </pre> |
||
+ | <td style="background-color:#eeccff;padding:7px;"> |
||
+ | <p> |
||
+ | <b>Answer Evaluation:</b> |
||
</p> |
</p> |
||
</td> |
</td> |
Latest revision as of 09:54, 29 June 2023
This problem has been replaced with a newer version of this problem
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 => "cool-vector-field.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: |