Difference between revisions of "EquationImplicitFunction1"

From WeBWorK_wiki
Jump to navigation Jump to search
(switch to PGML and remove answerFormatHelp.pl macro)
Line 5: Line 5:
 
This PG code shows how to have an answer that is an equation that implicitly defines a function.
 
This PG code shows how to have an answer that is an equation that implicitly defines a function.
 
</p>
 
</p>
* File location in OPL: [https://github.com/openwebwork/webwork-open-problem-library/blob/master/OpenProblemLibrary/FortLewis/Authoring/Templates/Algebra/EquationImplicitFunction1.pg FortLewis/Authoring/Templates/Algebra/EquationImplicitFunction1.pg]
+
<!-- * File location in OPL: [https://github.com/openwebwork/webwork-open-problem-library/blob/master/OpenProblemLibrary/FortLewis/Authoring/Templates/Algebra/EquationImplicitFunction1.pg FortLewis/Authoring/Templates/Algebra/EquationImplicitFunction1.pg] -->
 
* PGML location in OPL: [https://github.com/openwebwork/webwork-open-problem-library/blob/master/OpenProblemLibrary/FortLewis/Authoring/Templates/Algebra/EquationImplicitFunction1_PGML.pg FortLewis/Authoring/Templates/Algebra/EquationImplicitFunction1_PGML.pg]
 
* PGML location in OPL: [https://github.com/openwebwork/webwork-open-problem-library/blob/master/OpenProblemLibrary/FortLewis/Authoring/Templates/Algebra/EquationImplicitFunction1_PGML.pg FortLewis/Authoring/Templates/Algebra/EquationImplicitFunction1_PGML.pg]
   
Line 16: Line 16:
   
 
<tr valign="top">
 
<tr valign="top">
<th> PG problem file </th>
+
<th style="width: 50%"> PG problem file </th>
 
<th> Explanation </th>
 
<th> Explanation </th>
 
</tr>
 
</tr>
Line 42: Line 42:
 
DOCUMENT();
 
DOCUMENT();
   
loadMacros(
 
  +
loadMacros('PGstandard.pl','MathObjects.pl',
"PGstandard.pl",
 
  +
'parserImplicitEquation.pl','PGML.pl','PGcourse.pl');
"MathObjects.pl",
 
"parserImplicitEquation.pl",
 
"AnswerFormatHelp.pl",
 
);
 
 
 
TEXT(beginproblem());
 
TEXT(beginproblem());
 
</pre>
 
</pre>
Line 65: Line 60:
 
<td style="background-color:#ffffdd;border:black 1px dashed;">
 
<td style="background-color:#ffffdd;border:black 1px dashed;">
 
<pre>
 
<pre>
Context("ImplicitEquation");
+
Context('ImplicitEquation');
 
Context()->{error}{msg}{
 
Context()->{error}{msg}{
"Can't find any solutions to your equation"} = " ";
+
"Can't find any solutions to your equation"} = ' ';
 
Context()->{error}{msg}{
 
Context()->{error}{msg}{
"Can't generate enough valid points for comparison"} = " ";
+
"Can't generate enough valid points for comparison"} = ' ';
   
 
Context()->variables->set(
 
Context()->variables->set(
Line 79: Line 74:
 
$b = random(1,5,1);
 
$b = random(1,5,1);
 
$r = random(2,5,1);
 
$r = random(2,5,1);
  +
$p = Compute("($a,$b)");
   
 
$answer = ImplicitEquation(
 
$answer = ImplicitEquation(
 
"(x-$a)^2 + (y-$b)^2 = $r^2",
 
"(x-$a)^2 + (y-$b)^2 = $r^2",
solutions=>[
+
solutions=>[
 
[$a,$b+$r],
 
[$a,$b+$r],
 
[$a,$b-$r],
 
[$a,$b-$r],
Line 95: Line 91:
 
<p>
 
<p>
 
<b>Setup:</b>
 
<b>Setup:</b>
We quash some error messages by redefining them to be a blank string <code>" "</code> (notice the space). Since the circle will always be contained in a rectangle with two opposite corners at <code>(-4,-4)<code> and <code>(10,10)</code>, we set the limits for the variables x and y to be outside of this rectangle. The <code>ImplicitEquation</code> object allows us to specify as many solutions as we like, and doing so should improve the accuracy of the answer evaluator.
+
We quash some error messages by redefining them to be a blank string <code>" "</code> (notice the space). Since the circle will always be contained in a rectangle with two opposite corners at <code>(-4,-4)</code> and <code>(10,10)</code>, we set the limits for the variables x and y to be outside of this rectangle. The <code>ImplicitEquation</code> object allows us to specify as many solutions as we like, and doing so should improve the accuracy of the answer evaluator.
 
</p>
 
</p>
 
<p>
 
<p>
Line 108: Line 104:
 
<td style="background-color:#ffdddd;border:black 1px dashed;">
 
<td style="background-color:#ffdddd;border:black 1px dashed;">
 
<pre>
 
<pre>
Context()->texStrings;
 
  +
BEGIN_PGML
BEGIN_TEXT
 
  +
Enter an equation for a circle in the [`xy`]-plane
Enter an equation for a circle in the xy-plane
 
  +
of radius [` [$r] `] centered at [` [$p] `].
of radius \( $r \) centered at \( ($a,$b) \).
 
  +
$BR
 
  +
[________________________]{$answer}
$BR
 
  +
\{ ans_rule(40) \}
 
  +
[@ helpLink('equation') @]*
\{ AnswerFormatHelp("equation") \}
 
  +
END_PGML
END_TEXT
 
Context()->normalStrings;
 
 
</pre>
 
</pre>
 
<td style="background-color:#ffcccc;padding:7px;">
 
<td style="background-color:#ffcccc;padding:7px;">
 
<p>
 
<p>
 
<b>Main Text:</b>
 
<b>Main Text:</b>
</p>
 
</td>
 
</tr>
 
 
<!-- Answer evaluation section -->
 
 
<tr valign="top">
 
<td style="background-color:#eeddff;border:black 1px dashed;">
 
<pre>
 
$showPartialCorrectAnswers = 1;
 
 
ANS( $answer->cmp() );
 
</pre>
 
<td style="background-color:#eeccff;padding:7px;">
 
<p>
 
<b>Answer Evaluation:</b>
 
The answer evaluator used is very sensitive and finicky. We strongly recommended that you read about it at [http://webwork.maa.org/pod/pg/macros/parserImplicitEquation.html parserImplicitEquation.pl]
 
 
</p>
 
</p>
 
</td>
 
</td>
Line 148: Line 125:
 
<td style="background-color:#ddddff;border:black 1px dashed;">
 
<td style="background-color:#ddddff;border:black 1px dashed;">
 
<pre>
 
<pre>
Context()->texStrings;
 
  +
BEGIN_PGML_SOLUTION
BEGIN_SOLUTION
 
${PAR}SOLUTION:${PAR}
 
 
Solution explanation goes here.
 
Solution explanation goes here.
END_SOLUTION
 
  +
END_PGML_SOLUTION
Context()->normalStrings;
 
 
COMMENT("MathObject version.");
 
   
 
ENDDOCUMENT();
 
ENDDOCUMENT();

Revision as of 09:18, 4 April 2023

Answer is an Equation that Implicitly Defines a Function

Click to enlarge

This PG code shows how to have an answer that is an equation that implicitly defines a function.


Templates by Subject Area

PG problem file Explanation

Problem tagging data

Problem tagging:

DOCUMENT();   

loadMacros('PGstandard.pl','MathObjects.pl',
  'parserImplicitEquation.pl','PGML.pl','PGcourse.pl');
TEXT(beginproblem());

Initialization:

Context('ImplicitEquation');
Context()->{error}{msg}{
"Can't find any solutions to your equation"} = ' ';
Context()->{error}{msg}{
"Can't generate enough valid points for comparison"} = ' ';

Context()->variables->set(
  x=>{limits=>[-6,11]},
  y=>{limits=>[-6,11]},
);

$a = random(1,5,1);
$b = random(1,5,1);
$r = random(2,5,1);
$p = Compute("($a,$b)");

$answer = ImplicitEquation(
  "(x-$a)^2 + (y-$b)^2 = $r^2",
  solutions=>[
     [$a,$b+$r],
     [$a,$b-$r],
     [$a+$r,$b],
     [$a-$r,$b],
     [$a+$r*sqrt(2)/2,$b+$r*sqrt(2)/2],
  ]
);

Setup: We quash some error messages by redefining them to be a blank string " " (notice the space). Since the circle will always be contained in a rectangle with two opposite corners at (-4,-4) and (10,10), we set the limits for the variables x and y to be outside of this rectangle. The ImplicitEquation object allows us to specify as many solutions as we like, and doing so should improve the accuracy of the answer evaluator.

If your equation is linear of the form x=3, 4x+3y=12, or 4x+3y+5z=21, or..., you should probably use the [ImplicitPlane1 implicit plane] context and answer evaluator.

BEGIN_PGML
Enter an equation for a circle in the [`xy`]-plane
of radius [` [$r] `] centered at [` [$p] `].

[________________________]{$answer}

[@ helpLink('equation') @]*
END_PGML

Main Text:

BEGIN_PGML_SOLUTION
Solution explanation goes here.
END_PGML_SOLUTION

ENDDOCUMENT();

Solution:

Templates by Subject Area