## WeBWorK Main Forum

### answer checker for vector multiplication ### answer checker for vector multiplication

by Richard Bayne -
Number of replies: 6
How can I cause an answer checker to demand that the answer to a vector multiplication problem be in vector form rather than in the form of an operation, even though I have the answer in the form of an operation, e.g.,
$ans = Compute("$VectA X $VectB"); Bayne In reply to Richard Bayne ### Re: answer checker for vector multiplication by Michael Gage - This seems to work: loadMacros("contextLimitedVector.pl"); Context("LimitedVector");$A = Compute("<3,5,6>");
$B = Compute("<2,6,7>");$C = $A->cross($B);

ANS($C->cmp); however I believe there is a bug in the code right at the moment which means that the correct answer displayed for$C is not correct (the correct_value is ok so the answer is checked correctly.

You can work around this for now using

$C->with(correct_ans=>$C)->cmp

which overrides the correct answer. (Don't try to make sense of this--I'm quite sure it is a bug. :-) )

Using the ->cross method of the vector object gets around the limitations
imposed on the parser by the LimitedVector context. This work around is
not available in the student answer which always passes through the parser. ### Re: answer checker for vector multiplication

by Davide Cervone -
I was going to suggest something similar:
    loadMacros("contextLimitedVector.pl");

Context("Vector");
$V = Vector("<3,5,6> >< <2,6,7>"); Context("LimitedVector");$V = Vector($V); ... ANS($V->cmp);

Here, we do the computation in Vector context, where it is allowed, and then coerce the result into LimitedVector context, where computations are not allowed.

Note that the cross product is represented by >< not X.

There are several versions of the limited vector context. See

for more.

Davide ### Re: answer checker for vector multiplication

by Davide Cervone -
I think if you ise Vector() rather than Compute in Mike's answer, you will not have the incorrect answer problem that he mentions.

Davide ### Re: answer checker for vector multiplication

by Michael Gage -
Davide --

I checked it -- you are right:

loadMacros("contextLimitedVector.pl");
Context("LimitedVector");
$A = Vector("<3,5,6>"); $B = Vector("<2,6,7>");
$C =$A->cross($B); ANS($C->cmp);



works as you would expect with the correct answer evaluated.

Using Compute instead of vector I saw the same behavior
with ->add, and ->mult so it's not just a feature of the cross product that
the correct answer is inherited from the left operand.

I filed a bug report, but it's possible that this is a "feature" side effect that merely needs to be documented and explained.

-- Mike ### Re: answer checker for vector multiplication

by Michael Gage -
Updating to revision 1.94 of Value.pm also fixes this problem.

loadMacros("contextLimitedVector.pl");
Context("LimitedVector");
$A = Compute("<3,5,6>"); $B = Compute("<2,6,7>");
$C =$A->cross(\$B);

now presents the correct answer you would expect.

Thanks, Davide.
-- Mike 