# [LON-CAPA-users] coding a customresponse problem using &cas()

Justin Gray jgray at math.sfu.ca
Tue May 26 22:02:03 EDT 2015

```Hi Gerd,

This seems to work as expected for square matrices. However, the example
below accepts ([2,-2,-4],[-1,3,4]) as an answer, even though
&cas('maxima','rank(matrix'.\$submission.'^^2-matrix'.\$submission.')')
should generate an error in MAXIMA:

(%i1) A:matrix([2,-2,-4],[-1,3,4]);                               [  2
- 2  - 4 ]
(%o1)                          [               ]
[ - 1   3    4  ]
(%i2) rank(A^^2 - A);
MULTIPLYMATRICES: attempt to multiply nonconformable matrices.
-- an error. To debug this try: debugmode(true);

Justin

Justin Gray | Senior Lecturer
Department of Mathematics | Simon Fraser University
8888 University Drive, Burnaby | V5A 1S6 | Canada
Tel: +1 778.782.4237

On Tue, May 26, 2015 at 4:32 AM, Gerd Kortemeyer <kortemey at msu.edu> wrote:

> 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'; }
>
>     <textline readonly="no" spellcheck="none" size="80" />
> </customresponse>
>
> </problem>
>
>
> - Gerd.
>
>
>
>
> > On May 25, 2015, at 9:49 PM, Justin Gray <jgray at 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 at 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/
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.lon-capa.org/pipermail/lon-capa-users/attachments/20150526/d9958b9f/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SFU_2012_email_sig.jpg
Type: image/jpeg
Size: 8910 bytes
Desc: not available
URL: <http://mail.lon-capa.org/pipermail/lon-capa-users/attachments/20150526/d9958b9f/attachment.jpg>
```