Function Composition: linking multiple student answers with ParserMultiAnswer.pl.
Jump to navigation
Jump to search
Sometimes one problem depends on multiple student responses. We deal with this by using parserMultiAnswer.pl. The problem below is a typical function decomposition problem that precalc and calc students are assigned.
# In this problem we ask the student to decompose a function in to two functions. # Thus the student answer depends on two inputs. # We will use parserMultiAnswer.pl to link two answer blanks together for this # The student is awarded full points if they provide two function that when you compose them together give the correct function. # Otherwise the student gets 0. ######################################################################## DOCUMENT(); loadMacros( "PGstandard.pl", # Standard macros for PG language "MathObjects.pl", # Standard objects like real numbers, functions etc. "parserMultiAnswer.pl", # Allows us to link multiple answer blanks into one. ); # Print problem number and point value (weight) for the problem. TEXT(beginproblem()); # Show which answers are correct and which ones are incorrect. $showPartialCorrectAnswers = 1; ############################################################## # # Setup # # Context("Numeric"); # Contains almost everything you need for real variable calculus. # Possible correct answers. $firstFunc = Formula("sqrt(x)"); $secondFunc = Formula("5*x^2+3"); # The function the student needs to decompose. $displayFunc = $firstFunc->substitute(x => $secondFunc); ############################################################## # # Text # # Context()->texStrings; BEGIN_TEXT Consider the function \[f(x) = $displayFunc .\] Find two functions \(g(x)\) and \(h(x)\) such that \(f(x) = g(h(x))\). That is, find functions \(g(x)\) and \(h(x)\) such that \[g(h(x)) = $displayFunc .\] \(g(x) = \) \{ans_rule\}. $BR \(h(x) = \) \{ans_rule\}. END_TEXT Context()->normalStrings; ############################################################## # # Answers # # # Link the two answer blanks into one answer checker. # We will return two scores values, one for each answer blank # Blanks answers will not be allowed. # The answer checkers will check the type of objects given by the student before running. $multiAnsCheck = MultiAnswer($firstFunc, $secondFunc)->with(singleResult => 0, allowBlankAnswers => 0, checkTypes => 1, checker => sub { #Get the arrays of correct answers and student answers, and get the answer hash. my ($correctAns, $studentAns, $ansHash) = @_; # Get the student functions from the array of student answers. my ($studentFirstFunc, $studentSecondFunc) = @{$studentAns}; # Array with studetn scores my @scores = (0.0, 0.0); # Compose the student functions. $studentComp = $studentFirstFunc->substitute(x => $studentSecondFunc); # Check if the function composition results in the correct function. if($displayFunc == $studentComp){ $scores[0] = 1.0; $scores[1] = 1.0 } return [ @scores ]; } ); ANS($multiAnsCheck->cmp()); ENDDOCUMENT();
Exercises:
- Modify the problem above to not allow the student to enter the identity function for one of the answers.
- Modify the problem from the first exercise to include helpful messages to the student. You need to use the answer hash here. It is a little different compared to a previous example. Look at parserMultiAnswer.pl for details on how to do this.
- Modify the problem from the second exercise to give partial credit when the student flips the order of composition and include helpful messages.
- Modify the problem from the third exercise to minimize code repetition. Make one procedure that checks if two functions compose to the correct thing and awards points accordingly.
- Modify the problem from the fourth exercise to randomize the constants.
- Modify the problem from the fifth exercise to check for at least two more ways to assign partial credit.
- Modify the problem from the sixth exercise to ask for another decomposition of a function after the first one. That is, the student needs to do the same thing twice for different functions.
- Write an instructor solution to the problem from exercise seven.