WeBWorK Problems

Using Student Answers to Calculate Subsequent Answers

Using Student Answers to Calculate Subsequent Answers

by Gregory Varner -
Number of replies: 1

This is a bit more of a general question.

I am having students enter the equation of a line (a regression line). Since rounding and different versions of a calculator can give slightly different versions, I give the students an error tolerance. I then have the students answer some subsequent questions using the line. (For instance, plug a value in or set equal to a value and solve.) Unfortunately, even a small error tolerance in the original equation they enter can yield a rather large error threshold later in the problem. It would be much better to base the answer off of the student's input, creating an error threshold that is smaller but dependent on their entered answers.

Is it possible to read in the student's answer as a function so as to pull out the values?

For instance:

The student enters mx+b.

I set $student_slope = m, $student_intercept=b    (possibly as $student_intercept = $student_ans(0))

I ask them to solve for when the line equals c, so I set the answer as ans = (c-student_intercet)/(student_slope).

I can then use the cmp method to calculate and specify the error tolerance I want for their answer.

This is similar to the discussion on using $inputs_ref and $multians, but I am looking for something hopefully simpler. I particularly want to avoid having two boxes where they enter the slope in one box and the intercept in the other (though I may do this in the future).


Thank you

In reply to Gregory Varner

Re: Using Student Answers to Calculate Subsequent Answers

by Danny Glin -

I think the sample problem below covers all of the things that you want to accomplish.  I have also attached the pg file.

Using multiAnswer you can extract the student's equation as a MathObject formula, and then use the 'eval' method to evaluate the student's formula at a specific x-value.  I have also included code for setting the tolerance for a single mathObject, rather than for the entire problem.  Let me know if you have any questions about the code.

Some notes about my code:

  • My approach to extracting the slope of the line (taking the derivative) depends on the student's equation being that of a line.  My custom checker marks all three parts wrong if their equation is wrong, so we can be certain (up to tolerance) that they've entered a linear formula if they get the first part right.  If you wanted to give them credit for getting the last two parts right without getting the equation of the line right, you'd have to think more carefully about how to make sure that the student's formula is linear.
  • When doing comparisons inside a custom checker (e.g. using ==), the tolerance is inherited from the object on the left side of the comparison, so $x2calculated == $x2stu will use the tolerance associated with $x2calculated, whereas $x2stu == $x2calculated will use the tolerance associated with $x2stu.
  • An alternate approach for the last part would be to evaluate the student's equation at the student's x-value (i.e. $linestu->eval(x=>$x2stu)), and then compare this to $y2 using your desired tolerance.


DOCUMENT();

loadMacros(

  "PGstandard.pl",

  "MathObjects.pl",

  "parserMultiAnswer.pl",

  "PGML.pl",

  "PGcourse.pl"

);


################# Setting up the problem goes here.


TEXT(beginproblem());

Context("Numeric");


$m = random(2,6,1);

$b = random(-5,-2,1);


$line = Compute("$m*x+$b")->reduce();


$x1 = random(3,7,1);

$y1 = $line->eval(x=>$x1);


$y2 = random(7,11,1);

$x2 = ($y2-$b)/$m;


$multians = MultiAnswer($line, $y1, $x2)->with(

  singleResult => 0,

  checker => sub {

      my ( $correct, $student, $self ) = @_;

      my ( $linestu, $y1stu, $x2stu ) = @{$student};

      if ($line == $linestu) {

        $result1 = 1;

        $y1calculated = $linestu->eval(x=>$x1);

        if ( $y1calculated == $y1stu ) {

            $result2 = 1;

            } else {

            $result2 = 0;

            }

        $mstu = $linestu->D('x');

        $bstu = $linestu->eval(x=>0);

        $x2calculated = ($y2-$bstu)/($mstu);

        $x2calculated->{tolType}='absolute';

        $x2calculated->{tolerance}=0.5;

        if ($x2calculated == $x2stu) {

            $result3 = 1;

            } else {

            $result3 = 0;

            }

        } else {

        $result1 = 0;

        $result2 = 0;

        $result3 = 0;

        }

        return([$result1,$result2,$result3]);

  });


BEGIN_PGML

Write the equation of [:y= [$line]:].


[:y=:][___________]{$mutians}


When [:x=[$x1]:], predict the value of [:y:].


[:y=:][____]{$multians}


When [:y=[$y2]:], predict the value of [:x:].


[:x=:][____]{$multians}

END_PGML

ENDDOCUMENT();