<div dir="ltr">Hi Gerd,<div><br></div><div>This seems to work as expected for square matrices. However, the<span style="color:rgb(0,0,0);font-size:12.8000001907349px"> example below accepts </span><span style="color:rgb(0,0,0);font-size:12.8000001907349px">([2,-2,-4],[-1,3,4]) as an answer, even though  </span><span style="font-size:12.8000001907349px;color:rgb(80,0,80)">&cas('maxima','</span><span style="font-size:12.8000001907349px;color:rgb(80,0,80)">rank(matrix'.$submission.'^^2-</span><span style="font-size:12.8000001907349px;color:rgb(80,0,80)">matrix'.$submission.')') should generate an error in MAXIMA:</span></div><div><div class="gmail_extra" style="color:rgb(0,0,0);font-size:12.8000001907349px"><font color="#500050"><br></font></div><div class="gmail_extra"><pre style="color:rgb(0,0,0);font-size:12.8000001907349px;white-space:pre-wrap;word-wrap:break-word">(%i1) <span style="color:rgb(0,0,255)">A:matrix([2,-2,-4],[-1,3,4]);
</span><span style="font-size:11.6999998092651px">                               [  2   - 2  - 4 ]
(%o1)                          [               ]
                               [ - 1   3    4  ]
(%i2) </span><span style="color:rgb(0,0,255)">rank(A^^2 - A);
</span><span style="font-size:11.6999998092651px">
MULTIPLYMATRICES: attempt to multiply nonconformable matrices.
 -- an error. To debug this try: debugmode(true);</span></pre>Justin</div></div></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><br></div><div style="color:rgb(102,102,102)">Justin Gray | Senior Lecturer</div><span style="color:rgb(102,102,102)">Department of Mathematics | Simon Fraser University</span><br style="color:rgb(102,102,102)"><span style="color:rgb(102,102,102)">8888 University Drive, Burnaby | V5A 1S6 | Canada</span><br style="color:rgb(102,102,102)"><span style="color:rgb(102,102,102)">Tel: +1 778.782.4237</span><br></div><div dir="ltr"><span style="color:rgb(102,102,102)"><br></span></div><div dir="ltr"><img src="cid:0786efd7371599bc51452b5fedd54d152d0fae84@zimbra" style="color:rgb(0,0,0);font-family:verdana,helvetica,sans-serif;font-size:16px"><span style="color:rgb(102,102,102)"><br></span></div></div></div></div></div>
<br><div class="gmail_quote">On Tue, May 26, 2015 at 4:32 AM, Gerd Kortemeyer <span dir="ltr"><<a href="mailto:kortemey@msu.edu" target="_blank">kortemey@msu.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Justin,<br>
<br>
Please see if this works as expected:<br>
<br>
<problem><br>
<br>
<startouttext /><br>
Give an example of an idempotent matrix<br /><br>
<endouttext /><br>
<br>
<customresponse><br>
<br>
<answer type="loncapa/perl"># Get rid of white space<br>
$submission=~s/\s+//gs;<br>
# It's not a matrix if it does not at have parentheses<br>
unless ($submission=~/^\(.+\)$/) { return 'BAD_FORMULA'; }<br>
# Now evaluate something in MAXIMA<br>
$determinant=&cas('maxima','rank(matrix'.$submission.'^^2-matrix'.$submission.')');<br>
# If we get error, there was some syntax problem<br>
if ($determinant=~/Error/i) { return 'BAD_FORMULA'; }<br>
# Test the outcome of the MAXIMA expression<br>
if ($determinant==0) { return 'EXACT_ANS'; }<br>
return 'INCORRECT';</answer><br>
<br>
    <textline readonly="no" spellcheck="none" size="80" /><br>
</customresponse><br>
<br>
</problem><br>
<br>
<br>
- Gerd.<br>
<div><div class="h5"><br>
<br>
<br>
<br>
> On May 25, 2015, at 9:49 PM, Justin Gray <<a href="mailto:jgray@math.sfu.ca">jgray@math.sfu.ca</a>> wrote:<br>
><br>
> I would appreciate it if someone could assist me with coding the following problem.<br>
><br>
> Give an example of an idempotent matrix.<br>
><br>
> 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<br>
> ([2,-2,-4],[-1,3,4],[1,-2,-3]) would both be acceptable answers.<br>
> (A matrix A is idempotent if A^2=A.)<br>
><br>
> 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.<br>
><br>
> 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.<br>
><br>
> Thanks,<br>
> Justin<br>
><br>
> 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.<br>
><br>
><br>
><br>
> Justin Gray | Senior Lecturer<br>
> Department of Mathematics | Simon Fraser University<br>
> 8888 University Drive, Burnaby | V5A 1S6 | Canada<br>
> Tel: +1 778.782.4237<br>
><br>
</div></div>> <SFU_2012_email_sig.jpg><br>
> _______________________________________________<br>
> LON-CAPA-users mailing list<br>
> <a href="mailto:LON-CAPA-users@mail.lon-capa.org">LON-CAPA-users@mail.lon-capa.org</a><br>
> <a href="http://mail.lon-capa.org/mailman/listinfo/lon-capa-users" target="_blank">http://mail.lon-capa.org/mailman/listinfo/lon-capa-users</a><br>
<br>
--<br>
Gerd Kortemeyer, Ph.D.<br>
Associate Professor of Physics<br>
Director, LON-CAPA Project<br>
Michigan State University<br>
<a href="http://www.msu.edu/user/kortemey/" target="_blank">http://www.msu.edu/user/kortemey/</a><br>
<br>
<br>
<br>
<br>
</blockquote></div><br></div>