WeBWorK Problems

Using Primes in Answers (parserFunctionPrime.pl)

Using Primes in Answers (parserFunctionPrime.pl)

by Ian Delbridge -
Number of replies: 3
Does anyone have an example of how to use parserFunctionPrime.pl? I'm looking at this for help on how to use it, but I have some problems, and I think maybe if I see an example problem using it, then I might be able to work it out. 

This question stems from a larger problem/question I'm having which I will describe as a comment to this post.

Attached is an attempt at using it in a problem (attempting to be a symbolic version of an already existing question).
In reply to Ian Delbridge

Re: Using Primes in Answers (parserFunctionPrime.pl)

by Ian Delbridge -


I'm trying to write a problem on the subject of related rates in differential calculus, and I'd really like to have the capability of having students' answers involve primes. That is, if we have something like A(t) = x(t)+y(t), ask what is A'(t), and the students' answer should be x'(t) + y'(t). I know there are ways of getting around this by stating x'(t) = some constant, and y'(t) = some other constant, but I believe we have the capability of using 'prime' notation. 

I found parserFunctionPrime.pl, which seems to be designed for this sort of use, but something goes wrong when it comes to comparing students' answers. 

So here is what I tried: I want to ask, if A(t) = pi [r(t)]^2, what is A'(t) in terms of r(t) and r'(t)? The answer should just be the derivative with respect to t, A'(t) = 2 pi r(t) r'(t)

I defined t as a new variable, declared r(t) as a function of t(whose actual definition doesn't matter, I think in this case?) and set $dr = r'(t) ; 
As far as I can tell, this is exactly what I am supposed to do , according to the documentation in the link above. Then when I compute these into a formula and use it as the answer, it still seems to work, until I actually compare an answer with it. 

Attached is a screencap of what happens when I try to enter the correct answer.  


If you look at my code in the post above, you'll notice I've commented out the disable line at the bottom, because when I leave it there, I have this error: 
Any help on this would be appreciated.
EnteredAnswer PreviewCorrectResultMessages
2 pi r(t) r'(t)
 
2πr(t)r(t)
incorrectUnexpected character '''

Attachment anotherscreencap.gif
In reply to Ian Delbridge

Re: Using Primes in Answers (parserFunctionPrime.pl)

by Davide Cervone -
It turns out that there is a bug in parserFunctionPrime.pl (and I suspect the macro file has never actually been used except for display purposes, since it affects all uses in answer checking).

I've attached an updated version. The reason you were getting the message you received is that the derivative functions like r' are used as the names of functions, and at one point MathObjects puts that name in single-quotes, producing things like 'r'', which is syntactically invalid (there are an odd number of quotes, leading to the message about missing close quotes.

I will say a little bit about your code shortly.
In reply to Ian Delbridge

Re: Using Primes in Answers (parserFunctionPrime.pl)

by Davide Cervone -
The core of you code was:
Context("Numeric");
parser::FunctionPrime->Enable();
Context()->variables->add(t=> 'Real');
parserFunction("r(t)" => "15");
$r = Formula("r(t)");
$dr = Formula("r'(t)");

$dA = Compute("2 pi $r * $dr");

BEGIN_TEXT
...
\(A'(t) = \)\{ans_rule(30) \}
END_TEXT

ANS($dA->cmp);
Here are a few comments:

First, I'd use

    Context()->variables->are(t=> 'Real');
with are rather than add so that you remove the original variable x that was in the context. Not a big issue, but cleaner.

Next, there is no real need for the variables $r or $dr. You can just do

    $dA = Compute("2 pi r(t) r'(t)");
so that it looks like what you would expect the student to type.

Third, I would not use r(t) = 15 as that means that r'(t) = 0 so an answer of 0 will be a correct answer. (In your case, 2pi r(t) r'(t) does equal 0.) I'd recommend using some function that has a non-zero derivative and unlikely to be reproduced by a student, say r(t) = e^t + cos(3t)/10 (which is positive and not too big on the usual domain) or some such thing.

So a revised version of the problem is

loadMacros("parserFunctionPrime.pl");

Context("Numeric");
parser::FunctionPrime->Enable();
Context()->variables->are(t=>"Real");

parserFunction("r(t)" => "e^t+cos(3t)/10");

$dA = Compute("2pi r(t) r'(t)");

Context()->texStrings;
BEGIN_TEXT
\(A'(t)\) = \{$dA->ans_rule(20)\}
END_TEXT
Context()->normalStrings;

ANS($dA->cmp);

Hope that helps.