WeBWorK Problems

custom answer checker for RadioMultiAnswer

custom answer checker for RadioMultiAnswer

by Alex Jordan -
Number of replies: 1

I am trying to write a RadioMultiAnswer problem for a linear algebra course. The question poses a potential subspace H of R^2, and gives options:

  1. this is a vector subspace
  2. this is not a vector subspace because it does not contain 0
  3. this is not a vector subspace because ___ and ___ are two vectors in H but their sum is outside of H
  4. this is not a vector subspace because ___ is a scalar and ___ is a vector in H, and their product is not in H
The correct option is the last one "D". Students can get it marked correct by entering any valid scalar and vector that demonstrate H failing to be a subspace. Now, if the student answers option C or D using a vector that is not even in H in the first place, I want to give custom feedback. Also if they answer C but the two vectors sum to within H, I want to tell them about that too in special feedback.

I feel like the code below should accomplish all this. But when a user enters any answer that should trigger the special feedback, there is a PG error:
The evaluated answer is not an answer hash : ||.
I haven't been able to track down what is causing this. Can anyone see what the issue is? Either with my code or if there's an issue with the macro?

Here is the problem code.
# WeBWorK problem written by Alex Jordan 
DOCUMENT();

loadMacros(qw(
    PGstandard.pl PGML.pl parserRadioMultiAnswer.pl
));

Context("Vector");

$rma = RadioMultiAnswer([
        ['\(V\) is a vector subspace of \(\mathbb{R}^2\).'],
        ['\(V\) is not a vector subspace of \(\mathbb{R}^2\) because \(\vec{0}\) is not in \(V\).'],
        ['\(V\) is not a vector subspace of \(\mathbb{R}^2\) because for example %s* and %s* are in \(V\), but their sum is not.', ColumnVector(1,0), ColumnVector(0,1)],
        ['\(V\) is not a vector subspace of \(\mathbb{R}^2\) because for example %s is a real number and %s* is in \(V\), but their product is not in \(V\).', -1, ColumnVector(1,1)],
    ],
    3,
    checker => sub {
        my ($cor, $stu, $self, $ans) = @_;
        if ($stu->[0] == 3) {
            # student chose C and entered two vectors
            my ($u, $v) = @{$stu->[3]};
            my @u = $u->value;
            my @v = $v->value;
            Value::Error("At least one of your vectors is not in \(H\)")
                unless ($u[0] >= 0 && $u[1] >= 0 && $v[0] >= 0 && $v[1] >= 0);
            Value::Error("The sum of your vectors is in \(H\)");
        } elsif ($stu->[0] == 4) {
            # student chose D and entered a scalar and a vector
            my ($c, $v) = @{$stu->[4]};
            my @v = $v->value;
            Value::Error("Your vector is not in \(H\)")
                unless ($v[0] >= 0 && $v[1] >= 0);
            Value::Error("The product of your scalar and your vector is still in \(H\)")
                if ($c*$v[0] >= 0 && $c*$v[1] >= 0);
            return 1;
        }
        return 0;
    }
);

BEGIN_PGML
Let [`V`] be the first quadrant of the [`xy`]-plane in [`\mathbb{R}^2`].
In other words [`V=\left\{ \begin{bmatrix}x\\y\end{bmatrix}\mid x,y\geq0\right\}`].
Which of the following is correct?

[_]*{$rma}
END_PGML

ENDDOCUMENT();
In reply to Alex Jordan

Re: custom answer checker for RadioMultiAnswer

by Glenn Rice -

It seems that you can't call Value::Error in a RadioMultiAnswer checker.  You will need to user $self->appendMessage instead.  That doesn't throw an exception, so you will also need to explicitly "return 0".