I'm new to WeBWorK and I'd like some guidance in writing a problem. I would like to evaluate a function a particular point p. The point p is to be expressed in terms of pi, say pi / 4, and the answer to the problem computed in terms of p.
From there, I would like to display the question as follows:
Find f(p) = [______]
or
Find sin(p) = [______]
where p is displayed as its exact value, \frac {\pi} 4, and not as a decimal
I understand how I could solve this problem if I wrote out everything explicitly, but I would like the code to be robust enough to let me define p at the beginning and have the rest of the code remain unchanged.
My current solution displays the point p as decimal and I cannot figure out how to replace sin(x) with sin(p) without computing sin(p) directly. Can anyone offer any advice?
###########################
# Initialization
DOCUMENT();
loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"contextFraction.pl",
"AnswerFormatHelp.pl",
"PGML.pl",
"PGcourse.pl",
);
TEXT(beginproblem());
$showPartialCorrectAnswers = 1;
###########################
# Setup
Context("Numeric");
$f = Formula("sin(x)");
$p = PI();
$answer = $f -> eval(x => $p);
$point = $f -> substitute(x => $p);
Context()->functions->disable("Trig");
###########################
# Main text
BEGIN_PGML
Let [` f(x) = [$f] `].
Then
[`f([$p])`] = [_______________]{$answer->cmp()}
[`[$point]`] = [_______________]{$answer->cmp()}
END_PGML
ENDDOCUMENT();