Hi Justin,

Please see if this works as expected:

<problem>

<startouttext />
Give an example of an idempotent matrix<br />
<endouttext />

<customresponse>

<answer type="loncapa/perl"># Get rid of white space
$submission=~s/\s+//gs;
# It's not a matrix if it does not at have parentheses
unless ($submission=~/^\(.+\)$/) { return 'BAD_FORMULA'; }
# Now evaluate something in MAXIMA
$determinant=&cas('maxima','rank(matrix'.$submission.'^^2-matrix'.$submission.')');
# If we get error, there was some syntax problem
if ($determinant=~/Error/i) { return 'BAD_FORMULA'; }
# Test the outcome of the MAXIMA expression
if ($determinant==0) { return 'EXACT_ANS'; }
return 'INCORRECT';</answer>

    <textline readonly="no" spellcheck="none" size="80" />
</customresponse>

</problem>


- Gerd.




> On May 25, 2015, at 9:49 PM, Justin Gray <jg...@math.sfu.ca> wrote:
> 
> I would appreciate it if someone could assist me with coding the following 
> problem.
> 
> Give an example of an idempotent matrix.
> 
> Ideally, I would like students to input their answer using the format 
> (row_1,...,row_m) using a matrix of any size, so that ([1,1],[0,0]) and 
> ([2,-2,-4],[-1,3,4],[1,-2,-3]) would both be acceptable answers. 
> (A matrix A is idempotent if A^2=A.)
> 
> If I understand correctly, using a mathresponse problem is problematic in 
> this case because there is some preprocessing of the students submission that 
> makes it difficult to use in the answer algorithm, but one way around this is 
> to use customresponse combined with the &cas() function. 
> 
> In order that Maxima understands the students submission, the expression 
> 'matrix' needs to be appended to the front. Also, matrix exponentiation is 
> denoted by A^^n in Maxima. If it is easier to test a numerical condition, one 
> could verify that rank(A^^2 - A) = 0.
> 
> Thanks,
> Justin
> 
> P.S. Ideally, I would like to stipulate that students provide a nontrivial 
> example (excluding the zero matrix and the identity matrix) but that is the 
> topic of another discussion.
> 
> 
> 
> Justin Gray | Senior Lecturer
> Department of Mathematics | Simon Fraser University
> 8888 University Drive, Burnaby | V5A 1S6 | Canada
> Tel: +1 778.782.4237
> 
> <SFU_2012_email_sig.jpg>
> _______________________________________________
> LON-CAPA-users mailing list
> LON-CAPA-users@mail.lon-capa.org
> http://mail.lon-capa.org/mailman/listinfo/lon-capa-users

--
Gerd Kortemeyer, Ph.D.
Associate Professor of Physics
Director, LON-CAPA Project
Michigan State University
http://www.msu.edu/user/kortemey/




_______________________________________________
LON-CAPA-users mailing list
LON-CAPA-users@mail.lon-capa.org
http://mail.lon-capa.org/mailman/listinfo/lon-capa-users

Reply via email to