Difference between revisions of "ExtractingCoordinatesFromPoint"

From WeBWorK_wiki
Jump to navigation Jump to search
m
Line 2: Line 2:
   
 
<!-- 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;">
  +
<em>This code snippet shows the essential PG code to evaluate antderivative and general antiderivative formulas. Note that these are <b>insertions</b>, not a complete PG file. This code will have to be incorporated into the problem file on which you are working.</em>
  +
</p>
   
 
<p style="background-color:#eeeeee;border:black solid 1px;padding:3px;">
 
<p style="background-color:#eeeeee;border:black solid 1px;padding:3px;">
Line 23: Line 27:
 
<td style="background-color:#ddffdd;border:black 1px dashed;">
 
<td style="background-color:#ddffdd;border:black 1px dashed;">
 
<pre>
 
<pre>
loadMacros("any macros files that are needed");
+
loadMacros("MathObjects.pl");
 
</pre>
 
</pre>
 
</td>
 
</td>
 
<td style="background-color:#ccffcc;padding:7px;">
 
<td style="background-color:#ccffcc;padding:7px;">
<p>
+
<p>
To do ..(what you are doing)........., we don't have to change the
+
In the initialization section, we need to include the macros file <code>MathObjects.pl</code>.
tagging and documentation section of the problem file.
 
In the initialization section, we need to include the macros file <code>-------.pl</code>.
 
 
</p>
 
</p>
 
</td>
 
</td>
Line 45: Line 49:
 
($d1, $d2) = ($point[0] - $point[1])->value; # $d1 = x1 - x2, $d2 = y1 - y2
 
($d1, $d2) = ($point[0] - $point[1])->value; # $d1 = x1 - x2, $d2 = y1 - y2
   
# Need to put () around $d1 and $d2 because if $d1 = -6, then -6^2 = -36, not 36, as desired.
 
  +
 
$length = Compute("sqrt( ($d1)^2+($d2)^2 )");
 
$length = Compute("sqrt( ($d1)^2+($d2)^2 )");
 
$mid = ( $point[1] + $point[0] ) / 2;
 
$mid = ( $point[1] + $point[0] ) / 2;
Line 52: Line 56:
 
<td style="background-color:#ffffcc;padding:7px;">
 
<td style="background-color:#ffffcc;padding:7px;">
 
<p>
 
<p>
We don't use <code>Context("Vector") and <code>norm( $point[0] - $point[1] )</code>
+
In the problem setup section of the file, we don't use the Vector context and <code>norm( $point[0] - $point[1] )</code>
to determine length because we don't want to accept an answer like <code>|<5,7>-<7,8>|</code> You could use <code>$length=norm( $point[0] - $point[1] );</code> with the Vector context if you didn't care about accepting answers that are valid in the Vector context.
+
to determine length because we don't want to accept an answer like <code>|<5,7>-<7,8>|</code> You could use <code>$length=norm( $point[0] - $point[1] );</code> with the Vector context if you didn't care about accepting answers that are valid in the Vector context. (such as the absolute value of a vector.)
 
</p>
 
</p>
 
<p>
 
<p>
Notes: on using this and related Contexts.
 
  +
We need to put parentheses around <code>$d1</code> and <code>$d2</code> because if <code>$d1</code> = -6, then -6^2 = -36, not 36, as desired. However, if the code is <code>($d1)^2</code> then that evaluates as (-6)^2 = 36, as desired.
 
</p>
 
</p>
 
 
</td>
 
</td>
 
</tr>
 
</tr>

Revision as of 21:51, 13 June 2008

Your title here: PG Code Snippet


This code snippet shows the essential PG code to evaluate antderivative and general antiderivative formulas. Note that these are insertions, not a complete PG file. This code will have to be incorporated into the problem file on which you are working.

This wiki page is under construction as of 6/13/08.

Problem Techniques Index

PG problem file Explanation
loadMacros("MathObjects.pl");

In the initialization section, we need to include the macros file MathObjects.pl.

Context( "Point" );

push( @point, Point( random(1,5,1) , random(-5,-1,1) ) );
push( @point, Point( random(5,10,1) , random(6,11,1) ) );

($d1, $d2) = ($point[0] - $point[1])->value; # $d1 = x1 - x2, $d2 = y1 - y2


$length = Compute("sqrt( ($d1)^2+($d2)^2 )");
$mid = ( $point[1] + $point[0] ) / 2;

In the problem setup section of the file, we don't use the Vector context and norm( $point[0] - $point[1] ) to determine length because we don't want to accept an answer like |<5,7>-<7,8>| You could use $length=norm( $point[0] - $point[1] ); with the Vector context if you didn't care about accepting answers that are valid in the Vector context. (such as the absolute value of a vector.)

We need to put parentheses around $d1 and $d2 because if $d1 = -6, then -6^2 = -36, not 36, as desired. However, if the code is ($d1)^2 then that evaluates as (-6)^2 = 36, as desired.

Context()->texStrings;

BEGIN_TEXT
Consider the two points \( $point[0] \) and \( $point[1] \).
The distance between them is:\{ $length->ans_rule() \}
$BR
The midpoint of the line segment
that joins them is:\{ $mid->ans_rule() \}
$BR
END_TEXT

Context()->normalStrings;

The problem text section of the file is as we'd expect.

ANS( $length->cmp );
ANS( $mid->cmp );

As is the answer.

Problem Techniques Index