PREP 2014 Question Authoring - Archived

Prime notation in student answers

Prime notation in student answers

by Chrissy Safranski -
Number of replies: 1
I want to have students enter "P'(t)=k * P(t)".

I found this thread by two of our esteemed PREP2014 moderators: http://webwork.maa.org/moodle/mod/forum/discuss.php?d=2816

I downloaded the file parserFunctionPrime.pl found there, put it in the templates/macros folder, and still can't get it to work.  But maybe the problem is somewhere else.  The pink screen of death says something about illegal function name P' though.  I'm trying to do implicit plane and P'(t) and I'm not really sure about either thing.  My backup option is to turn it into multiple choice so that they don't have to enter it.  

Thanks for any help!
---------------------------------------------------

loadMacros(
   "PGstandard.pl",     # Standard macros for PG language
   "MathObjects.pl",
   "AnswerFormatHelp.pl",
 "parserImplicitPlane.pl",
# "parserFunction.pl",
 "parserFunctionPrime.pl",
   #"source.pl",        # allows code to be displayed on certain sites.
   #"PGcourse.pl",      # Customization file for the course
);

##############################################################

TEXT(beginproblem());

$showPartialCorrectAnswers = 1;

##############################################################

$a = random(2,6,1);
$b = random(100,1000,100);
$c = Compute($a*3);

Context("Numeric");


Context()->variables->add(t =>'Real');
Context()->variables->remove("x");

$ans1 = Compute("$b*8");
$ans2 = Compute("$b*2^(t/$a)");
$ans3 = Compute("$b*2^(19/$a)");

Context("ImplicitPlane");

parser::FunctionPrime->Enable();

 Context()->variables->remove("x","y","z");
Context()->variables->add(t =>"Real", k=>"Real", C=>"Real");
parserFunction("P(t)"=>"t**2 + sin(t)");
parserFunction("P'(t)"=>"2 t +cos(t)");
  $diffeq = ImplicitPlane("P'(t) =  k * P(t) ");

##############################################################

Context()->texStrings;
BEGIN_TEXT

The following problem is an example of exponential growth/decay (in this case, growth).  All these types of functions have the general form \(y=Ce^{kt}\), where \(t \) is time, \( C\) is the initial value, \(y\) is the value of the function at any time \(t\), and \(k\) is called the growth (or decay) constant.  (Note that interest compounded continuously has the same form).  $PAR

If we use the more customary variable names for exponential growth problems, \(P(t)=P_0 e^{k t} \), then what differential equation does this function \(P(t) \) satisfy?  Your answer should include some combination of \(P(t), P'(t), k, C, t, e\) and it's an equation, so also \( = \). (You can find this in the first few pages of Section 5.1 in your textbook if you don't remember).
\{ans_rule\} \{AnswerFormatHelp("equations") \}

----------------------------------------------------------------------
# I've redacted unedited stuff from an exponential growth problem in the library, but can but it back in if you want to see it.
-----------------------------------------------------------------------

ANS($diffeq->cmp);

ANS( $ans1->cmp() );
ANS( $ans2->cmp() );
ANS( $ans3->cmp(tolType=>'absolute', tolerance=>1) );


ENDDOCUMENT();        

In reply to Chrissy Safranski

Re: Prime notation in student answers

by Davide Cervone -
There are a number of things involved, here. First of all, there was a bug in parserFunctionPrime.pl, though that is not what is causing the issues for you. In any case, I have made a new version available in this answer, so you might download that and put it in your course templates/macrosfolder.

Aside from that, let's look at your proposed problem. Here is your main code:

$a = random(2,6,1);
$b = random(100,1000,100);
$c = Compute($a*3);

Context("Numeric");
Context()->variables->add(t =>'Real');
Context()->variables->remove("x");

$ans1 = Compute("$b*8");
$ans2 = Compute("$b*2^(t/$a)");
$ans3 = Compute("$b*2^(19/$a)");

Context("ImplicitPlane");
parser::FunctionPrime->Enable();

Context()->variables->remove("x","y","z");
Context()->variables->add(t =>"Real", k=>"Real", C=>"Real");
parserFunction("P(t)"=>"t**2 + sin(t)");
parserFunction("P'(t)"=>"2 t +cos(t)");
$diffeq = ImplicitPlane("P'(t) =  k * P(t) ");
There are some cosmetic issues, and some more serious ones. First, the two statements
Context()->variables->add(t =>'Real');
Context()->variables->remove("x");
can be combined to become one:
Context()->variables->are(t =>'Real');
Using are rather than add automatically removes any existing variables and adds the new ones, so you don't have to do the remove() call yourself. Similarly,
Context()->variables->remove("x","y","z");
Context()->variables->add(t =>"Real", k=>"Real", C=>"Real");
can be replaced by
Context()->variables->are(t =>"Real", k=>"Real", C=>"Real");

Another minor nitpick is that you have used

$c = Compute($a*3);
before you set the context, which is legal but bad form. It would be best to set the context before then.

You mentioned that

parserFunction("P'(t)"=>"2 t +cos(t)");
produced an error message about P' not being a valid function name. That is true. You don't set the value of P'(t) since that is already determined by the value of P(t) itself. Once you have defined P(t), then P'(t) (and P''(t), etc.) are already available. You don't declare them yourself. So you can just drop this line entirely.

Finally, I don't understand this line:

$diffeq = ImplicitPlane("P'(t) =  k * P(t) ");
You are using ImplicitPlane but the expression you give is not the equation of an implicit plane, so that is not going to work. Note that ImplicitPlane() is very specifically for linear equations in n-space, not for arbitrary implicit equations. Also, your equation isn't an implicit equation, it is a differential equation, so even the implicit equation object wouldn't work for it.

I'm assuming that you are trying to use this because you want to ask for an equation and don't want to force the format. (The usual way to ask this question would probably have been to use ask for something like "P'(t) = [_____]" and have them enter "k*P(t)"). I'm not entirely sure how to check the answer for that. It is not enough to ask for a true expression that involves P(t) and P'(t), since 0*P(t) = 0*P'(t) is true, but not what you want, and so is P(t)-Ce^(kt) = P'(t) - kCe^{kt}. So I'm not sure exactly what it means to check for the answer you are looking for other than to look for a specific algebraic form. But MathObjects isn't a computer algebra system, and doesn't really have a way to do that, so such checking is generally tedious and fragile.

Anyway, if you can be more specific about what should constitute the correct answer (and what alternate forms should be allowed), that might make it possible to figure out a way to check it.