Forum archive 2000-2006

Michael Hamm - multiples of a vector

Michael Hamm - multiples of a vector

by Arnold Pizer -
Number of replies: 0
inactiveTopicmultiples of a vector topic started 9/12/2006; 12:05:54 PM
last post 9/13/2006; 7:39:31 PM
userMichael Hamm - multiples of a vector  blueArrow
9/12/2006; 12:05:54 PM (reads: 268, responses: 3)
Hi, all,

I am trying to write problems where students have to enter three answers (three separate ans_rules, let's say, although I don't really care about that), and WW should check whether they are correct up to multiplication by a constant (the *same* constant for all three).

E.g.: If the correct answers are t, 3-t, 2t, and the student enters -2t, 2t-6, -4t, he should be marked correct, but not if he enters t, 3-t, 4t.

Does anyone know a way to do this?


Michael Hamm

<| Post or View Comments |>

userGavin LaRose - Re: multiples of a vector  blueArrow
9/13/2006; 8:06:41 AM (reads: 316, responses: 1)
Hi Michael,

I'm no expert on the Parser, but if you're entering a vector Davide's Parser does this very elegantly. I think the following code should work.

   loadMacros( "" );
$solnVec = Vector( "t", "3-t", "2t" );
Enter a vector parallel to \($solnVec\): \{ ans_rule(25) \}
ANS( $solnVec->cmp(parallel=>1) );


[update: 9/13, 2pm]: The context line might have to be


<| Post or View Comments |>

userDavide P. Cervone - Re: multiples of a vector  blueArrow
9/13/2006; 3:07:26 PM (reads: 368, responses: 0)

Thanks for trying to cover some of the Parser questions. I appreciate the help. Unfortunately, this approach won't work, because the parallel=>1 option is only valid for constant vectors, not vector formulas. it is not entirely clear what parallel should mean in this case: does it mean that the student's vector for each tested t value is parallel to the professor's vector for that t, or do you mean that there is a single multiple that works for all the t's. (This is the classic issue of the change in order of the for-all and there-exists).

In any case, vector formulas don't do the parallel testing. I'll write something as soon as I can that shows how you can do the check that was requested.


<| Post or View Comments |>

userDavide P. Cervone - Re: multiples of a vector  blueArrow
9/13/2006; 7:39:31 PM (reads: 294, responses: 0)
Gavin's suggestion of using the Parser's Vector object is a good one. Here is one way to do what you ask:




$V = Formula("<t,3-t,2t>");
Enter a vector parallel to \($V\): \{ans_rule(25)\}

ANS(custom_cmp($V,sub {
my ($correct,$student) = @_;
return 1 if $correct == $student;
my $cv = $correct->{test_values}[0];
my $sv = $student->{test_values}[0];
my $k = ($sv->extract(1))/($cv->extract(1));
return $k != 0 && $k*$correct == $student;

Here, we use a custom checker to provide out own function that determines if the student's answer is correct. The subroutine is passed the correct and student answers, and the first thing it does is check if the two are equal. If so, it returns 1 (for correct), but the real reason for this is to have the Parser create test points and evaluate the two formulas at those points. The resulting vectors are stored in the {text_values} array in each answer, and so we extract the first one from the professor's and student's answers.

If the two answers are going to be multiples of each other, then every pair of tested points will have the same factor, and we determine that factor by comparing the first coordinates of the student's and professor's first tested vectors. (This assumes that the professor's vector does not have a zero first coordinate. You could set the limits for t to avoid zero for example.)

Finally, we check to see if the student's answer really is this multiple of the professor's answer. We rule out a multiple of zero, otherwise a student's answer of <0,0,0> would always be marked as correct. (Note that since the coordinates of the vectors are Parser Real objects, the $k is as well, and so $k != 0 is a fuzzy check using the usual WeBWorK tolerances, so this will check if $k is sufficiently close to 0.)

Hope that is what you are looking for.


<| Post or View Comments |>