Maple Grading Issues: Grading Matrix Answers

 

Define your matrix in the algorithmic section:

$A=maple("Matrix(n,m,[a11,a12,....,amn])");

or:

$A=maple("<<a11|a12|..>,<a21|a22|..>..<an1|...>>)");

(or even in the grading code itself) where m and n are your matrix dimensions and here I assume n>1 (see below how to handle vectors). The aij are just your matrix values, entered row then column. For example the matrix would be entered as:

$A=maple("Matrix(3,3,[1,2,3,4,5,6,7,8,9])");


Vector case:
A vector like cannot be treated as a 3x1 matrix, Maple distinguishes between vectors and matrices. To grade against such an object use the following code:

 

$A = maple("Vector[column]([1,2,3])");

 

The grading code is the same for both cases. You CAN mark vectors as matrices if necessary, the code for doing so is given at the end of this document.

 

You need to use Maple grading set to "Maple Syntax" to enable and grade such questions. This code will grade a matrix or vector $A against the response field:

 

LinearAlgebra[Equal]($A,$RESPONSE);

 

Notice that this is "all or none" marking. If they enter one incorrect entry, they get 0. For part-marks grading, see the next section.

You can display a nice answer with:

printf(MathML[ExportPresentation]($A));

 

However this displays the answer with (round brackets). To convert to square brackets use the following code in the $ANSWER field:

printf(StringTools[Substitute](MathML[ExportPresentation]($A),"mfenced","mfenced open=[ close=]"));

 

Partial Grading

The following code will assign a fractional mark if the student fails to answer all matrix entries correctly. Here the correct matrix $Ans is 2x3 :

M:=0;

for i from 1 to 2 do
  for j from 1 to 3 do
    if is($RESPONSE[i,j]=$Ans[i,j]) then
        M:=M+1;
    end if;   end do;
end do;

M/6.0;

That "6.0" is essential, if you use "6" it will not work.

Grading a vector as a matrix

If you must grade a vector as a matrix, the following code will do so. It will also allow transposes. You will need to change it to fit your variables. (Courtesy of Maplesoft)

Equivalent := proc( U :: anything, V :: anything, { allowtranspose :: truefalse := true } )  

local X, Y;  

try

    X := Matrix( U );

    Y := Matrix( V );

catch:

    return false;  

end try;  

 

if LinearAlgebra:-Equal( X, Y ) then

    return true;   

elif allowtranspose and LinearAlgebra:-Equal( X, LinearAlgebra:-Transpose( Y ) ) then

    return true;   

else

    false;   

end if;

end proc:

# Example of using the procedure

A := Matrix( [ [ 1 ], [ 2 ] ] );

B := Vector[row]( [ 1, 2 ] );

C := [ 1, 2 ];

Equivalent( A, B ); # true

Equivalent( A, C ); # true

Vectors vs Ordered Pairs

In lower dimensions answers may be entered as column vectors or as ordered pairs. Here is code that can mark either. It uses the fact that a vector answer is returned as a string with the word "Vector" within it. An ordered pair (a,b) is just returned as two values a,b. To mark that enclose it in [brackets] to make it a list.

M:=0;
B0:="$RESPONSE";

if (searchtext("Vector",B0)=0) then
A:=[$RESPONSE];
else
A:=$RESPONSE;
end if;

if evalb(A[1]=Ans[1]) then M:=0.5; end if;
if evalb(A[2]=Ans[2]) then M:=M+0.5; end if;

M;


 

Maple Grading Issues Index

Main Index

Last updated: 02/09/2023 SS/DAG