WeBWorK Problems

List of matrices as student answer

List of matrices as student answer

by Sean Fitzpatrick -
Number of replies: 2

I'm trying to write a problem (using Library/NAU/setLinearAlgebra/basisTrace0.pg as a starting point) asking students to input a basis for a subspace of a vector space of matrices. My version is attached.

I'd rather not give away the dimension of the subspace in advance, so I'd like the students to enter their answer as a comma-separated list of matrices. (It is slightly annoying to use the [[a,b],[c,d]] syntax when entering a list, but this is for a class where the students do some computational work with Python, so they're used to this.)

The question will work using the original MultiAnswer setup, but then we know the size of the basis based on the number of blanks.

I can get it to work without custom answer-checking, but then students would need to come up with the 'standard' basis for the answer.

I believe something is wrong with how the matrices in the student answer are being read into the custom answer checker, but I can't figure out what it is.

On the editing page, if I try the preview of the problem, entering the correct answer (which is [[1,0],[0,-1]],[[0,0],[1,0]],[[0,1],[0,0]]) results in the correct answer preview, but the message "Matrices must have at least one entry".

If I try the problem from the library browser, the correct answer is marked as correct. But if I replace one of the matrices by a multiple of that matrix, the answer gets marked wrong. (It should not.) None of the error messages in the custom checker show up at any point.

In reply to Sean Fitzpatrick

Re: List of matrices as student answer

by Andrew Parker -

The following line is causing your issue: 

my $s = @{$student};

Here you dereference the student `ARRAY` into a list, but then you store it into a scalar. This causes perl to conclude that you want the length of the list.

Instead, store your dereferenced ARRAY as a list:

my @s = @{$student};

Then everything works as expected?



In reply to Andrew Parker

Re: List of matrices as student answer

by Sean Fitzpatrick -

Oh, jeez... yes.

I am not sure how I introduced that error: it was @s in an earlier verison I was working on.

And now that I look at that earlier version: it failed because I had "$basis_checker => sub" instead of "$basis_checker = sub".

I spotted that mistake and apparently introduced a new one at the same time. (facepalm)

Thanks!