<div dir="ltr">Hi Peter,<div><br></div><div>Thank you very much for this. I tested it out and it works beautifully. </div><div><br></div><div>I agree that, more generally, a diagonal idempotent matrix could be regarded as a trivial example. The purpose of the exercise that I have in mind is to draw to students' attention that operations on matrices are much different than operations with real numbers. For real numbers, the equation x^2 = x is satisfied only by x = 0 and x = 1, but for matrices the equation A^2 = A has solutions other than the additive and multiplicative identities.</div><div class="gmail_extra"><br></div><div class="gmail_extra">Thanks,</div><div class="gmail_extra">Justin<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 8:46 AM, Peter Dencker <span dir="ltr"><<a href="mailto:dencker@math.uni-luebeck.de" target="_blank">dencker@math.uni-luebeck.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
Hi Justin,<br>
<br>
in my example a diagonal idempotent matrix will be regarded as too trivial.<br>
<br>
- Peter<br>
<br>
<br>
<problem><br>
<br>
<script type="loncapa/perl"><br>
<br>
    sub is_true_but_diagonal {<br>
        my @given = @_;<br>
        # is the matrix diagonal?<br>
        for my $i ( 0 .. $#given ) {<br>
            for my $j ( 0 .. $#{ $given[$i] } ) {<br>
                if ( $i != $j && $given[$i][$j] != 0 ) {<br>
                    return 0;<br>
                }<br>
            }<br>
        }<br>
        # is the diagonal matrix idempotent?<br>
        for my $i ( 0 .. $#given ) {<br>
            if ( $given[$i][$i] != 0 && $given[$i][$i] != 1 ) {<br>
                return 0;<br>
            }<br>
        }<br>
        return 1;<br>
    }<br>
<br>
    $hint = q{};<br>
<br>
</script><br>
<br>
Give a nontrivial example of an idempotent matrix (whose entries are all integers). <br /><br>
<br>
<br>
<customresponse id="0r0"><br>
  <answer type="loncapa/perl"><br>
<br>
       for ($submission) { s{\s}{}gxms; s{\Amatrix}{}gxms; }<br>
<br>
        return 'BAD_FORMULA'<br>
            if $submission !~ /\A[(]\[(.+)\][)]\z/xms;<br>
        my @given<br>
          = map { [ split /,/xms, $_ ]; } split /\],\[/xms, $1;<br>
        for (map { @{$_}; } @given) {<br>
            return 'BAD_FORMULA' if !/\A[-+]?\d+\z/xms;<br>
        }<br>
<br>
        my $n = @{ $given[0] };<br>
        for my $row (@given) { return 'BAD_FORMULA' if @{$row} != $n }<br>
        my $m = @given;<br>
        return 'INCORRECT' if $m != $n;<br>
<br>
        return 'BAD_FORMULA' if is_true_but_diagonal(@given);<br>
<br>
        my $matrix      = "matrix$submission";<br>
        my $maxima_in<br>
          = "is(rank(rat($matrix.$matrix-$matrix))=0)"<br>
          . q{;};<br>
        my $maxima_out = cas( 'maxima', $maxima_in );<br>
        return 'EXACT_ANS'<br>
            if $maxima_out eq 'true';<br>
        return 'INCORRECT'<br>
            if $maxima_out eq 'false';<br>
        return 'BAD_FORMULA';<br>
<br>
    </answer><br>
    <customhint id="0r0h0"><br>
      <answer type="loncapa/perl"><br>
<br>
          for ($submission) { s{\s}{}gxms; s{\Amatrix}{}gxms; }<br>
          if ( $submission !~ /\A[(]\[(.+)\][)]\z/xms ) {<br>
              $hint = '<b>Give a matrix in the required form.</b>';<br>
              return;<br>
          }<br>
          my @given<br>
            = map { [ split /,/xms, $_ ]; } split /\],\[/xms, $1;<br>
          for ( map { @{$_}; } @given ) {<br>
              if ( !/\A[-+]?\d+\z/xms ) {<br>
                  $hint<br>
                    = '<b>Use integer entries for this submission.</b>';<br>
                  return;<br>
              }<br>
          }<br>
          my $n = @{ $given[0] };<br>
          for my $row (@given) {<br>
              if ( @{$row} != $n ) {<br>
                  $hint<br>
                    = '<b>All rows must be the same length.<b>';<br>
                  return;<br>
              }<br>
          }<br>
          my $m = @given;<br>
          if ( $m != $n ) {<br>
              $hint<br>
                = '<b>An idempotent matrix must necessarily'<br>
                . 'be a square matrix!</b>';<br>
              return;<br>
          }<br>
          if ( is_true_but_diagonal(@given) ) {<br>
              $hint<br>
                = '<b>Correct, well, but choose'<br>
                . 'a less trivial example.</b>';<br>
              return;<br>
          }<br>
<br>
      </answer><br>
    </customhint><br>
</customresponse><br>
<br>
<textline /> <br /><br>
$hint <br /><br>
<br>
</problem><span class=""><br>
<br>
<br>
<br>
<br>
Am 05/26/2015 um 03:49 AM schrieb Justin Gray:<br>
</span><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">
I would appreciate it if someone could assist me with coding the following<br>
problem.<br>
<br>
Give an example of an idempotent matrix.<br>
<br>
Ideally, I would like students to input their answer using the format<br>
(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></span>
(A matrix *A* is *idempotent* if *A*^2=*A*.)<span class=""><br>
<br>
If I understand correctly, using a mathresponse problem is problematic in<br>
this case because there is some preprocessing of the students submission<br>
that makes it difficult to use in the answer algorithm, but one way around<br>
this is to use customresponse combined with the &cas() function.<br>
<br>
In order that Maxima understands the students submission, the expression<br>
'matrix' needs to be appended to the front. Also, matrix exponentiation is<br>
denoted by A^^n in Maxima. If it is easier to test a numerical condition,<br>
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<br>
example (excluding the zero matrix and the identity matrix) but that is the<br>
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: <a href="tel:%2B1%20778.782.4237" value="+17787824237" target="_blank">+1 778.782.4237</a><br>
<br>
<br>
<br></span><span class="">
_______________________________________________<br>
LON-CAPA-users mailing list<br>
<a href="mailto:LON-CAPA-users@mail.lon-capa.org" target="_blank">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>
</span></blockquote>
<br>
<br>
-- <br>
Dr. Peter Dencker<br>
    wissenschaftl. Mitarbeiter<br>
<br>
UNIVERSITÄT ZU LÜBECK<br>
    INSTITUT FÜR MATHEMATIK<br>
<br>
    Ratzeburger Allee 160<br>
    23562 Lübeck<br>
<br>
    Tel <a href="tel:%2B49%20451%20500%204254" value="+494515004254" target="_blank">+49 451 500 4254</a><br>
    Fax <a href="tel:%2B49%20451%20500%203373" value="+494515003373" target="_blank">+49 451 500 3373</a><br>
    <a href="mailto:dencker@math.uni-luebeck.de" target="_blank">dencker@math.uni-luebeck.de</a><br>
<br>
    <a href="http://www.math.uni-luebeck.de" target="_blank">www.math.uni-luebeck.de</a><div class="HOEnZb"><div class="h5"><br>
_______________________________________________<br>
LON-CAPA-users mailing list<br>
<a href="mailto:LON-CAPA-users@mail.lon-capa.org" target="_blank">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>
</div></div></blockquote></div><br></div></div>