Difference between revisions of "DisableFunctions1"

From WeBWorK_wiki
Jump to navigation Jump to search
(Created page with '<h2>Disabling Functions so Students Must Simplify Answers</h2> <p style="background-color:#eeeeee;border:black solid 1px;padding:3px;"> This PG code shows how to disable all fun…')
 
(PGML example link)
 
(11 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
<h2>Disabling Functions so Students Must Simplify Answers</h2>
 
<h2>Disabling Functions so Students Must Simplify Answers</h2>
   
<p style="background-color:#eeeeee;border:black solid 1px;padding:3px;">
 
  +
[[File:DisableFunctions1.png|300px|thumb|right|Click to enlarge]]
  +
<p style="background-color:#f9f9f9;border:black solid 1px;padding:3px;">
 
This PG code shows how to disable all functions and restrict student answers to fractions.
 
This PG code shows how to disable all functions and restrict student answers to fractions.
<ul>
 
<li>Download file: [[File:DisableFunctions1.txt]] (change the file extension from txt to pg when you save it)</li>
 
<li>File location in NPL: <code>NationalProblemLibrary/FortLewis/Authoring/Templates/Trig/DisableFunctions1.pg</code></li>
 
</ul>
 
 
</p>
 
</p>
  +
* File location in OPL: [https://github.com/openwebwork/webwork-open-problem-library/blob/master/OpenProblemLibrary/FortLewis/Authoring/Templates/Trig/DisableFunctions1.pg FortLewis/Authoring/Templates/Trig/DisableFunctions1.pg]
  +
* PGML location in OPL: [https://github.com/openwebwork/webwork-open-problem-library/blob/master/OpenProblemLibrary/FortLewis/Authoring/Templates/Trig/DisableFunctions1_PGML.pg FortLewis/Authoring/Templates/Trig/DisableFunctions1_PGML.pg]
   
  +
<br clear="all" />
 
<p style="text-align:center;">
 
<p style="text-align:center;">
 
[[SubjectAreaTemplates|Templates by Subject Area]]
 
[[SubjectAreaTemplates|Templates by Subject Area]]
Line 46: Line 46:
 
"MathObjects.pl",
 
"MathObjects.pl",
 
"AnswerFormatHelp.pl",
 
"AnswerFormatHelp.pl",
"contextFractions.pl",
+
"contextFraction.pl",
 
);
 
);
   
Line 67: Line 67:
 
Context("Fraction-NoDecimals");
 
Context("Fraction-NoDecimals");
   
$x = Formula("cos(pi)");
 
  +
# Prevent pi from becoming 3.1415... and cos(pi) from
  +
# becoming -1.
  +
Context()->constants->set(pi => {keepName => 1});
   
$y = Formula("sin(pi/3)");
+
$f1 = Formula("cos(pi)");
  +
$f2 = Formula("sin(pi/3)");
  +
  +
Context()->functions->disable("All");
  +
Context()->functions->enable("sqrt");
  +
  +
$answer1 = Compute("-1");
  +
$answer2 = Compute("sqrt(3)/2");
 
</pre>
 
</pre>
 
</td>
 
</td>
Line 75: Line 77:
 
<p>
 
<p>
 
<b>Setup:</b>
 
<b>Setup:</b>
  +
We choose a context that requires fractions as answers and does not allow decimals. After constructing the formulas involving trig functions, we disable all functions and re-enable the <code>sqrt()</code> function. This means that students are allowed to type in fractions and square roots, but not much else (e.g., they'll get an error message if they type in a trig function).
  +
</p>
  +
<p>
  +
Note that <code>$f1</code> and <code>$f2</code> are MathObject Formulas, which do not get reduced since <code>pi</code> is set to keep its name. If <code>$f1</code> and <code>$f2</code> used Compute instead, then the results would be <code>-1</code> and <code>0.866...</code> instead of <code>cos(\pi)</code> and <code>sin(\pi/3)</code> as desired.
 
</p>
 
</p>
 
</td>
 
</td>
Line 89: Line 95:
 
$BR
 
$BR
 
$BR
 
$BR
\( $x = \)
+
\( $f1 = \)
 
\{ ans_rule(20) \}
 
\{ ans_rule(20) \}
 
\{ AnswerFormatHelp("fractions") \}
 
\{ AnswerFormatHelp("fractions") \}
 
$BR
 
$BR
 
$BR
 
$BR
\( $y = \)
+
\( $f2 = \)
 
\{ ans_rule(20) \}
 
\{ ans_rule(20) \}
 
\{ AnswerFormatHelp("fractions") \}
 
\{ AnswerFormatHelp("fractions") \}
Line 114: Line 120:
 
$showPartialCorrectAnswers = 1;
 
$showPartialCorrectAnswers = 1;
   
ANS( Real($x->eval)->cmp() );
+
ANS( $answer1->cmp() );
   
ANS( Real($y->eval)->cmp() );
+
ANS( $answer2->cmp() );
 
</pre>
 
</pre>
 
<td style="background-color:#eeccff;padding:7px;">
 
<td style="background-color:#eeccff;padding:7px;">
Line 155: Line 161:
   
 
[[Category:Top]]
 
[[Category:Top]]
[[Category:Authors]]
+
[[Category:Sample Problems]]
  +
[[Category:Subject Area Templates]]

Latest revision as of 12:34, 13 June 2015

Disabling Functions so Students Must Simplify Answers

Click to enlarge

This PG code shows how to disable all functions and restrict student answers to fractions.


Templates by Subject Area

PG problem file Explanation

Problem tagging data

Problem tagging:

DOCUMENT();

loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"AnswerFormatHelp.pl",
"contextFraction.pl",
);

TEXT(beginproblem());

Initialization:

Context("Fraction-NoDecimals");

# Prevent pi from becoming 3.1415... and cos(pi) from
# becoming -1.
Context()->constants->set(pi => {keepName => 1}); 

$f1 = Formula("cos(pi)");
$f2 = Formula("sin(pi/3)");

Context()->functions->disable("All");
Context()->functions->enable("sqrt");

$answer1 = Compute("-1");
$answer2 = Compute("sqrt(3)/2");

Setup: We choose a context that requires fractions as answers and does not allow decimals. After constructing the formulas involving trig functions, we disable all functions and re-enable the sqrt() function. This means that students are allowed to type in fractions and square roots, but not much else (e.g., they'll get an error message if they type in a trig function).

Note that $f1 and $f2 are MathObject Formulas, which do not get reduced since pi is set to keep its name. If $f1 and $f2 used Compute instead, then the results would be -1 and 0.866... instead of cos(\pi) and sin(\pi/3) as desired.

Context()->texStrings;
BEGIN_TEXT
Enter your answers as simplified fractions.
$BR
$BR
\( $f1 = \)
\{ ans_rule(20) \}
\{ AnswerFormatHelp("fractions") \}
$BR
$BR
\( $f2 = \)
\{ ans_rule(20) \}
\{ AnswerFormatHelp("fractions") \}
END_TEXT
Context()->normalStrings;

Main Text:

$showPartialCorrectAnswers = 1;

ANS( $answer1->cmp() );

ANS( $answer2->cmp() );

Answer Evaluation:

Context()->texStrings;
BEGIN_SOLUTION
${PAR}SOLUTION:${PAR}
Solution explanation goes here.
END_SOLUTION
Context()->normalStrings;

COMMENT('MathObject version.');

ENDDOCUMENT();

Solution:

Templates by Subject Area