## WeBWorK Problems

### ijk vector formula checking ### ijk vector formula checking

by Gavin LaRose -
Number of replies: 1
Hi all,

(This is essentially a recap of the discussion in http://webwork.maa.org/moodle/mod/forum/discuss.php?d=2284 that I'm re-initiating to see if any further comments come up. My conclusion here is the same as Paul's there, but it still doesn't seem very satisfying.)

I'm working with some vector formulas, and am having trouble working with student vectors input in ijk format. For example, the following is a fabricated example that illustrates the problems I'm having (I should note that this is really just an example).

  DOCUMENT()
"MathObjects.pl",
Context("Vector");

$vec = Vector( Compute("cos(t)"), Compute("cos(t)"), Formula("0") );$der = $vec->D('t');$vderChk = MultiAnswer( $vec,$der )->with(
singleResult=>0,
checker=>sub {
my ( $c,$s, $ans ) = @_; ## the student's vector and derivative my ($sVec, $sDer) = @{$s};

if ( $sVec->D('t') ==$sDer ) {
return [ 1, 1 ];
} else {
return [ 1, 0 ];
}
}
);

Context()->texStrings;
TEXT(beginproblem());
BEGIN_TEXT
$$\vec v =$$ \{ $vderChk->ans_rule(25) \}$BR
$$\vec v ' =$$ \{ $vderChk->ans_rule(25) \} END_TEXT Context()->normalStrings; ANS($vderChk->cmp() );
ENDDOCUMENT();


If a student enters the first vector with angle brackets, for example, <2t,t,1>, then the problem is marked correctly (a student answer of either <2,1,0> or 2i + j is marked correct).

However, if the student's vector is in ijk format, for example, 2t i + t j + k, we get the error message Operands for '+' must be of the same type, and the problem is marked wrong.

Similarly, if we try to work with the components of the input vectors we also run into trouble. For example, we could change the checker function in the above to the following (ignoring for the moment any question of whether this is a good way to do things).

  sub {
my ( $c,$s, $ans ) = @_; my ($sVec, $sDer ) = @{$s};

# get the components of these vectors
my @sVecComp = $sVec->value; my @sDerComp =$sDer->value;

if ( $sVecComp->D('t') ==$sDerComp &&
$sVecComp->D('t') ==$sDerComp &&
$sVecComp->D('t') ==$sDerComp ) {
return [1,1];
} else {
return [1,0];
}
}


Davide