Difference between revisions of "DisableFunctions1"
m (Changed incorrect "are not" to "are" in the sentence "This means that students are allowed to type in fractions...") 
Paultpearson (talk  contribs) (PGML example link) 

(5 intermediate revisions by the same user not shown)  
Line 5:  Line 5:  
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. 

</p> 
</p> 

−  * Download file: [[File:DisableFunctions1.txt]] (change the file extension from txt to pg when you save it) 

+  * File location in OPL: [https://github.com/openwebwork/webworkopenproblemlibrary/blob/master/OpenProblemLibrary/FortLewis/Authoring/Templates/Trig/DisableFunctions1.pg FortLewis/Authoring/Templates/Trig/DisableFunctions1.pg] 

−  * File location in NPL: <code>FortLewis/Authoring/Templates/Trig/DisableFunctions1.pg</code> 

+  * PGML location in OPL: [https://github.com/openwebwork/webworkopenproblemlibrary/blob/master/OpenProblemLibrary/FortLewis/Authoring/Templates/Trig/DisableFunctions1_PGML.pg FortLewis/Authoring/Templates/Trig/DisableFunctions1_PGML.pg] 

−  
<br clear="all" /> 
<br clear="all" /> 

Line 67:  Line 66:  
<pre> 
<pre> 

Context("FractionNoDecimals"); 
Context("FractionNoDecimals"); 

+  
+  # Prevent pi from becoming 3.1415... and cos(pi) from 

+  # becoming 1. 

+  Context()>constants>set(pi => {keepName => 1}); 

$f1 = Formula("cos(pi)"); 
$f1 = Formula("cos(pi)"); 

Line 82:  Line 85:  
<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 reenable 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). 
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 reenable 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 162:  Line 168:  
[[Category:Top]] 
[[Category:Top]] 

−  [[Category: 
+  [[Category:Sample Problems]] 
+  [[Category:Subject Area Templates]] 
Latest revision as of 11:34, 13 June 2015
Disabling Functions so Students Must Simplify Answers
This PG code shows how to disable all functions and restrict student answers to fractions.
 File location in OPL: FortLewis/Authoring/Templates/Trig/DisableFunctions1.pg
 PGML location in OPL: FortLewis/Authoring/Templates/Trig/DisableFunctions1_PGML.pg
PG problem file  Explanation 

Problem tagging: 

DOCUMENT(); loadMacros( "PGstandard.pl", "MathObjects.pl", "AnswerFormatHelp.pl", "contextFraction.pl", ); TEXT(beginproblem()); 
Initialization: 
Context("FractionNoDecimals"); # 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 reenable the
Note that 
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: 