PREP 2014 Question Authoring - Archived

How dynamic can a question be?

How dynamic can a question be?

by Murphy Waggoner -
Number of replies: 2
Can the answer by a student for one question be used to determine the format of another?  There are time when I want to lead the student to an answer because of the format of the answer.

a)  How many solutions does z2 = 1 have?
b)  What are those solutions?    

And two blanks are given for question b) because the student answered 2 to the first question.

There are other ways to get around the question above, but I'm thinking about linear algebra.  Like in this example.  


a)  What size is the coefficient matrix for the system above (where the system is given)?
b)  What is that matrix?
In reply to Murphy Waggoner

Re: How dynamic can a question be?

by Davide Cervone -
For your first example, the usual approach is to use a list for part (b) so that the student enters the solutions as a comma-separated list of complex numbers. This is easier to code in a number of ways, and it can automatically provide the student with some hints about what is wrong (these can be controlled by the problem author). So I'd stick with that approach there.

For your second example, it would be possible to do that using a multi-part (sometimes referred to as a "compound") problem. This is an advanced technique that will not be covered in detail in this workshop. The tools for doing this are still actively being developed.

One option that doesn't require multi-part problems would be to allow the student to enter the array in a single large rectangle either using the MathObject matrix notation (brackets around comma-separated entries for the rows, with rows separated by commas and enclosed in brackets), or as an array of numbers separated by spaces and newlines that you turn into an array by hand within a custom answer checker. The latter would require a little extra work, but is probably preferable.

Here's one version that might do what you need:

    $A = Matrix([1,2,3],[4,5,6]);
    \($A\) = \(\Bigg[\) \{ans_box(4,12)\} \(\Biggr]\)
    ANS(Compute("1 2 3~~n4 5 6")->cmp(checker => sub {
      my ($correct,$student,$ans) = @_;
      my $M = $student->value;
      $M =~ s/  +/ /g;                                 # remove multiple spaces
      $M =~ s/(~~n|^) /~~1/g; $M =~ s/ (~~n|$)/~~1/g;  # remove leading and trailing spaces
      $M =~ s/~~n~~n+/~~n/g;                           # remove blank lines
      $M =~ s/^~~n+//; $M =~ s/~~n+$//;                # remove leading and trailing blank lines
      my @M = map {[split(/ /,$_)]} split(/~~n/,$M);   # break into an array of arrays
      $M = Matrix(@M);                                 # form MathObject matrix
      $ans->{preview_latex_string} = $M->TeX;          # format the answer preview
      $ans->{correct_ans_latex_string} = $A->TeX;      # format the correct answer 
      return $A == $M;                                 # check the answers
You can paste this into the Interactive Problem Lab to see how it works (or insert it into a problem file ad add the problem to a set). The main idea is that you get the student's answer as a string and then manipulate that string to form a MathObject Matrix. That will already perform some error checking (like that the rows are the same length and that the entries are numbers).

In any case, this is a starting point for that type of answer.

In reply to Murphy Waggoner

Re: How dynamic can a question be?

by Arnold Pizer -

Mike Gage just gave a talk on WeBWorK at HKUST and for that he created 3 demo courses which illustrate many of the problem techniques that can be used.  For example using flash applets (your previous post) and sequential problems which may be relevant to your current post. Take a look at

and also HKUST102 and HKUST103.  Login instructions on on the first page.