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/macros
folder.
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.