Linear approximation
Download file: LinearApprox.pg
DOCUMENT();
loadMacros(
'PGstandard.pl', 'PGML.pl',
'answerHints.pl', 'parserAssignment.pl',
'PGcourse.pl'
);
Preamble
Load parserAssignment.pl
to require students to enter their answer as an equation of the form
y = .... Load answerHints.pl
to provide customized answer hints, particularly for students who enter
the slope of the line instead of the equation of the line.
Context()->variables->add(y => 'Real');
parser::Assignment->Allow;
$a = random(2, 5);
$aa = $a**2;
$a2 = 2 * $a;
$f = Compute('sqrt(x)');
$answer = Compute("y = $a + (1 / $a2) * (x - $aa)");
$cmp = $answer->cmp()->withPostFilter(AnswerHints(
[ Formula("1 / $a2"), Formula("y = 1 / $a2") ] => [
'Your answer should be an equation for a non-horizontal line.',
replaceMessage => 1
],
));
Setup
Allow assignments in the context by calling
parser::Assignment->Allow.
Answer hints are used to remind students to enter an equation for a line, not just the slope of the line.
BEGIN_PGML
Find the linear approximation of [`f(x) = [$f]`] at [`x = [$aa]`]. Your
answer should be an equation in the variables [`x`] and [`y`].
[_]{$cmp}{10}
END_PGML
Statement
The variable $cmp is used for the answer associated with
the answer rule. It was defined by calling the cmp method
of the $answer in the setup section above.
BEGIN_PGML_SOLUTION Solution explanation goes here. END_PGML_SOLUTION ENDDOCUMENT();
Solution
A solution should be provided here.