LinearApprox1

From WeBWorK_wiki
Jump to navigation Jump to search
This article has been retained as a historical document. It is not up-to-date and the formatting may be lacking. Use the information herein with caution.

This problem has been replaced with a newer version of this problem


Linear Approximation With Answer Hints

Click to enlarge

This PG code shows how to ask a linear approximation question in which the answer is an equation and students receive customized answer hints.


Templates by Subject Area

PG problem file Explanation

Problem tagging data

Problem tagging:

DOCUMENT(); 

loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"AnswerFormatHelp.pl",
"answerHints.pl",
"parserAssignment.pl",
);

TEXT(beginproblem());

Initialization: We load parserAssignment.pl to require students to enter their answer as an equation of the form y=.... We load answerHints.pl to provide customized answer hints, particularly for those students who enter the slope of the line instead of the equation of the line.

Context("Numeric")->variables->add(y=>"Real");
parser::Assignment->Allow;

$a = random(2,5,1);
$aa = $a**2;
$a2 = 2 * $a;

$f = Compute("sqrt(x)");

$answer = Compute("y = $a + (1/$a2) * (x-$aa)");

Setup: We have to tell the context that we are allowing the assignment of a variable to a formula.

Context()->texStrings;
BEGIN_TEXT
Find the linear approximation to \( f(x) = $f \)
at \( x = $aa \).  Your answer should be an 
equation in the variables \( x \) and \( y \).
$BR
$BR
\{ ans_rule(20) \}
\{ AnswerFormatHelp("equations") \}
END_TEXT
Context()->normalStrings;

Main Text:

$showPartialCorrectAnswers = 1;

ANS( $answer->cmp() 
->withPostFilter(AnswerHints( 
  [Formula("1/$a2"),Formula("y=1/$a2")] => 
  ["Your answer should be an equation for a non-horizontal line.",
  replaceMessage=>1],
))
);

Answer Evaluation: We use answer hints to remind students to enter an equation for a line, not just the slope of the line.

Context()->texStrings;
BEGIN_SOLUTION
Solution explanation goes here.
END_SOLUTION
Context()->normalStrings;

COMMENT("MathObject version.");

ENDDOCUMENT();

Solution:

Templates by Subject Area