I want to check if some maxima input is of a specific form. For example, I want to check if the answer is of the form A*%e^(B*t)
where A and B are specific real numbers.
If student X gives answer 3*%e^(5*t)
, then it is of this form. If student Y gives answer sin(t)
, or maybe y=3*%e^(5*t)
then I can give this student as feedback that his answer is not yet of the correct form.
I was wondering if there exist something like this in maxima.
Maxima has several pattern-matching functions that operate on expressions (not strings). I think defmatch
is suitable here, e.g.:
(%i8) matchdeclare ([A, B], constantp);
(%o8) done
(%i9) defmatch (match_aexpbt, A*exp(B*t), t);
(%o9) match_aexpbt
(%i10) match_aexpbt (5*exp(3*u), u);
(%o10) [A = 5, B = 3, t = u]
(%i11) match_aexpbt (sqrt(2)*exp(%pi*z), z);
(%o11) [A = sqrt(2), B = %pi, t = z]
(%i12) match_aexpbt (y = 5*exp(3*u), u);
(%o12) false
(%i13) match_aexpbt (5*sin(2*u), u);
(%o13) false
(%i14) match_aexpbt ((1 + %i)*exp(exp(%pi)*v), v);
%pi
(%o14) [A = %i + 1, B = %e , t = v]
In this case I've defined match_aexpbt
which matches expressions which look like A*exp(B*t)
where A
and B
are constants and t
is a variable which is supplied.
See the documentation for defmatch
and matchdeclare
and also defrule
, tellsimp
, and tellsimpafter
. The pattern-matching functions are a little idiosyncratic but actually pretty useful -- I have used them many times.
If you are interested in checking student's answers, there have been projects based on Maxima for that. Take a look at the related projects webpage and see in particular STACK.