FunctionDecomposition1
From WeBWorK
(Difference between revisions)
Paultpearson (Talk  contribs) m 
Paultpearson (Talk  contribs) 

Line 5:  Line 5:  
This PG code shows how to check student answers that are a composition of functions.  This PG code shows how to check student answers that are a composition of functions.  
</p>  </p>  
−  *  +  * File location in OPL: [https://github.com/openwebwork/webworkopenproblemlibrary/blob/master/OpenProblemLibrary/FortLewis/Authoring/Templates/Precalc/FunctionDecomposition1.pg FortLewis/Authoring/Templates/Precalc/FunctionDecomposition1.pg] 
−  +  
Revision as of 22:31, 15 June 2013
Function Decomposition
This PG code shows how to check student answers that are a composition of functions.
 File location in OPL: FortLewis/Authoring/Templates/Precalc/FunctionDecomposition1.pg
PG problem file  Explanation 

Problem tagging: 

DOCUMENT(); loadMacros( "PGstandard.pl", "MathObjects.pl", "answerComposition.pl", "AnswerFormatHelp.pl", ); TEXT(beginproblem()); 
Initialization:
We need to include the macros file 
Context("Numeric"); Context()>variables>add(u=>"Real"); $a = random(2,9,1); $f = Formula("sqrt(u)"); $g = Formula("x^2+$a"); 
Setup: 
Context()>texStrings; BEGIN_TEXT Express the function \( y = \sqrt{ x^2 + $a } \) as a composition \( y = f(g(x)) \) of two simpler functions \( y = f(u) \) and \( u = g(x) \). $BR $BR \( f(u) \) = \{ ans_rule(20) \} \{ AnswerFormatHelp("formulas") \} $BR \( g(x) \) = \{ ans_rule(20) \} \{ AnswerFormatHelp("formulas") \} END_TEXT Context()>normalStrings; 
Main Text: 
$showPartialCorrectAnswers = 1; COMPOSITION_ANS( $f, $g, vars=>['u','x'], showVariableHints=>1); 
Answer Evaluation:
We use the 
Context()>texStrings; BEGIN_SOLUTION ${PAR}SOLUTION:${PAR} Solution explanation goes here. END_SOLUTION Context()>normalStrings; COMMENT('MathObject version.'); ENDDOCUMENT(); 
Solution: 