Hi Justin,
in my example a diagonal idempotent matrix will be regarded as too trivial.
- Peter
<problem>
<script type="loncapa/perl">
sub is_true_but_diagonal {
my @given = @_;
# is the matrix diagonal?
for my $i ( 0 .. $#given ) {
for my $j ( 0 .. $#{ $given[$i] } ) {
if ( $i != $j && $given[$i][$j] != 0 ) {
return 0;
}
}
}
# is the diagonal matrix idempotent?
for my $i ( 0 .. $#given ) {
if ( $given[$i][$i] != 0 && $given[$i][$i] != 1 ) {
return 0;
}
}
return 1;
}
$hint = q{};
</script>
Give a nontrivial example of an idempotent matrix (whose entries are all
integers). <br />
<customresponse id="0r0">
<answer type="loncapa/perl">
for ($submission) { s{\s}{}gxms; s{\Amatrix}{}gxms; }
return 'BAD_FORMULA'
if $submission !~ /\A[(]\[(.+)\][)]\z/xms;
my @given
= map { [ split /,/xms, $_ ]; } split /\],\[/xms, $1;
for (map { @{$_}; } @given) {
return 'BAD_FORMULA' if !/\A[-+]?\d+\z/xms;
}
my $n = @{ $given[0] };
for my $row (@given) { return 'BAD_FORMULA' if @{$row} != $n }
my $m = @given;
return 'INCORRECT' if $m != $n;
return 'BAD_FORMULA' if is_true_but_diagonal(@given);
my $matrix = "matrix$submission";
my $maxima_in
= "is(rank(rat($matrix.$matrix-$matrix))=0)"
. q{;};
my $maxima_out = cas( 'maxima', $maxima_in );
return 'EXACT_ANS'
if $maxima_out eq 'true';
return 'INCORRECT'
if $maxima_out eq 'false';
return 'BAD_FORMULA';
</answer>
<customhint id="0r0h0">
<answer type="loncapa/perl">
for ($submission) { s{\s}{}gxms; s{\Amatrix}{}gxms; }
if ( $submission !~ /\A[(]\[(.+)\][)]\z/xms ) {
$hint = '<b>Give a matrix in the required form.</b>';
return;
}
my @given
= map { [ split /,/xms, $_ ]; } split /\],\[/xms, $1;
for ( map { @{$_}; } @given ) {
if ( !/\A[-+]?\d+\z/xms ) {
$hint
= '<b>Use integer entries for this submission.</b>';
return;
}
}
my $n = @{ $given[0] };
for my $row (@given) {
if ( @{$row} != $n ) {
$hint
= '<b>All rows must be the same length.<b>';
return;
}
}
my $m = @given;
if ( $m != $n ) {
$hint
= '<b>An idempotent matrix must necessarily'
. 'be a square matrix!</b>';
return;
}
if ( is_true_but_diagonal(@given) ) {
$hint
= '<b>Correct, well, but choose'
. 'a less trivial example.</b>';
return;
}
</answer>
</customhint>
</customresponse>
<textline /> <br />
$hint <br />
</problem>
Am 05/26/2015 um 03:49 AM schrieb Justin Gray:
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
_______________________________________________
LON-CAPA-users mailing list
LON-CAPA-users@mail.lon-capa.org
http://mail.lon-capa.org/mailman/listinfo/lon-capa-users
--
Dr. Peter Dencker
wissenschaftl. Mitarbeiter
UNIVERSITÄT ZU LÜBECK
INSTITUT FÜR MATHEMATIK
Ratzeburger Allee 160
23562 Lübeck
Tel +49 451 500 4254
Fax +49 451 500 3373
denc...@math.uni-luebeck.de
www.math.uni-luebeck.de
_______________________________________________
LON-CAPA-users mailing list
LON-CAPA-users@mail.lon-capa.org
http://mail.lon-capa.org/mailman/listinfo/lon-capa-users