PREP 2015 Question Authoring - Archived

Hard copy print of scaffolded problem

Re: Hard copy print of scaffolded problem

by Davide Cervone -
Number of replies: 0
There are two reasons for the hardcopy problem. First, there is a bug in the scaffold macros that failed to take the hardcopy_is_open value into account properly. The open sections where any sections where all the answer are correct. (I have made a pull request with a patch to fix that problem; you could get the updated scaffold.pl file and put it in your course templates/macros folder.)

Second, for the sections that used BEGIN_TEXT/END_TEXT, you had the ANS() call after the Section::End() call. The scaffold macros tells which answers are in which sections by where the ANS() calls are located. Since yours occur between two sections, they are not part of any section, but are considered to be part of the surrounding get of the problem (like your initial text at the top of the problem). As a consequence, the sections where those answers should have been included had no answers associated with them, and so they are considered to be completely correct (i.e., they have no incorrect student answers and no blank answers), so the hardcopy showed them as open (it wasn't honoring the hardcopy_is_open option).

So the first thing you have to to is put the ANS() calls into the sections where they belong. Note that the Section::Begin() and Section::End() should enclose everything that is part of the section, not just the text. This happens automatically for PGML sections, but not for TEXT sections with ANS() calls. In fact, I would be tempted to do the computations that are need for each section within the section begin and end as well; but that is a matter of preference.

There are a number of other issues with your problem, however, which I discuss below.

First, you don't want the Context()->variables->add() call. The variables in the context are the ones the student is allowed to use in their answers, not the ones that you are using as part of your PG program. So your command would allow students to enter answers that look like 2*ans2+ans13-f, which I'm sure you don't want. You can simply remove that line since you rare not asking students to enter formulas with those variables.

Second, you don't need to use \displaystyle for your integral, since you are already inside [``...``] which does displaystyle automatically. Also, it is customary to put \, before the dx in an integral to improve the spacing (see the TeXbook for details).

Third, You don't need to use [@ a@]*) for the labels in your sections. I know why you have done that (so it doesn't restart at "a" for each one), but there is an easier way to get that. If you use a\) instead, that will prevent the ) from having its usual effect (the backslash "escapes" it).

Fourth, your align=>CENTER should really be align=>"CENTER" or better align=>"center". You should use quotes for string literals even if Perl doesn't require it, as it is much safer in the long run.

Fifth, the code you used to add space in hardcopy is more complicated than necessary. You can do it in one MODES() call, rather than six repeated calls. In fact, you can do it once and store the result in a variable that you insert into the sections at the right places. I don't quite understand why you are doing this at all, however, since you have set hardcopy_is_open => "never" and the space is only for hardcopy output. Perhaps you are planning to change that option later?

Finally, it is possible to use PGML for all the sections, even the ones with the tables. It takes a little cleverness, but I have added some code to your file (see below) that allows you to use PGML within the tables, and insert the tables within PGML. The key is the PGML() function I define near the top of the file that takes an array of PGML strings and processes them using PGML::Format2(). This lets you put PGML inside the rows of your table. The only problems that PGML inserts a paragraph break at the end of the PGML, and that can't occur inside a table in TeX, so that would mess up the hardcopy. So I added another call to fix that. That makes it a bit uglier than I like, but it does do the trick. It also allows you to use PGML for the solution as well.

Here is the updated version, which I have also attached.


# tagging and description section
#---------------------------------------------------------------------------------------------------------------------

# DESCRIPTION
# M4B Worksheet Problem 1
# ENDDESCRIPTION
# Library tagging would go here

#---------------------------------------------------------------------------------------------------------------------
# initialization section
# always include PGcourse.pl as last macro loaded
#---------------------------------------------------------------------------------------------------------------------

DOCUMENT();
loadMacros(
  "PGstandard.pl",
  "MathObjects.pl",
  "PGML.pl",
  "unionTables.pl",
  "scaffold.pl",
  "AnswerFormatHelp.pl",
  "PGcourse.pl"
);

#---------------------------------------------------------------------------------------------------------------------
# problem set-up section
#---------------------------------------------------------------------------------------------------------------------

Context("Numeric");

#
#  Process an array of strings using PGML, but trim off the final \par
#  if we are in hardcopy mode.
#
sub PGML {map {trimPGML(PGML::Format2($_))} @_}
sub trimPGML {
  my $s = shift;
  $s = substr($s,0,len($s)-4)."}" if $displayMode eq "TeX";
  return $s;
}

Scaffold::Begin(
  can_open => "when_previous_correct",
  is_open => "correct_or_first_incorrect",
  hardcopy_is_open => "never",
  instructor_can_open => "when_previous_correct",
  after_AnswerDate_can_open => "always",
);

$a = non_zero_random(-3,-1,1);
$b = -$a;
$c = non_zero_random(1,3,1);
$d = non_zero_random(1,3,1);
$n = 5;
$n1 = 2*$n;

$f = Formula("($c+x)/($d+x^2)");

$ans1 = ($b-$a)/$n;

$a1 = $a+$ans1;
$a2 = $a+2*$ans1;
$a3 = $a+3*$ans1;
$a4 = $a+4*$ans1;

$ans2 = $f->eval(x=>$a);
$ans3 = $f->eval(x=>$a1);
$ans4 = $f->eval(x=>$a2);
$ans5 = $f->eval(x=>$a3);
$ans6 = $f->eval(x=>$a4);
$ans7 = $ans1*($ans2+$ans3+$ans4+$ans5+$ans6);

$ans8 = ($b-$a)/$n1;

$a11 = $a+$ans8;
$a12 = $a+2*$ans8;
$a13 = $a+3*$ans8;
$a14 = $a+4*$ans8;
$a15 = $a+5*$ans8;
$a16 = $a+6*$ans8;
$a17 = $a+7*$ans8;
$a18 = $a+8*$ans8;
$a19 = $a+9*$ans8;

$ans9  = $f->eval(x=>$a);
$ans10 = $f->eval(x=>$a11);
$ans11 = $f->eval(x=>$a12);
$ans12 = $f->eval(x=>$a13);
$ans13 = $f->eval(x=>$a14);
$ans14 = $f->eval(x=>$a15);
$ans15 = $f->eval(x=>$a16);
$ans16 = $f->eval(x=>$a17);
$ans17 = $f->eval(x=>$a18);
$ans18 = $f->eval(x=>$a19);

$ans20 = $ans8*($ans9+$ans10+$ans11+$ans12+$ans13+$ans14+$ans15+$ans16+$ans17+$ans18);

$ans19 = Compute("2*$c*arctan($b/sqrt($d))/sqrt($d)");

#---------------------------------------------------------------------------------------------------------------------
# text section
#---------------------------------------------------------------------------------------------------------------------

$GAP = MODES(HTML=>"",TeX=>"\vskip5\baselineskip");

TEXT(beginproblem());
# anything between BEGIN and END PGML is what students see
BEGIN_PGML
GRADED ONLINE.  PAPER WORKSHEET IS WORKING SPACE ONLY.

    Let [``f(x)=[$f]``]

    We wish to estimate the value of the definite integral of [`f(x)`] from [`x=[$a]`] to [`x=[$b]`]

    [``\int_{[$a]}^{[$b]} [$f]\,dx``]

    using the Riemann Left Hand Sum.
 
END_PGML

#-------------------------------------------------------------------

Section::Begin();
BEGIN_PGML  

    a\) Find the step size, [`\Delta x`], for the Riemann Left Hand Sum for the above integral
    for [`n=[$n]`] subintervals.    

    [$GAP]*    
    [``\Delta x = ``][________________________________________]{$ans1}[@ AnswerFormatHelp("numbers") @]*

END_PGML
Section::End();

#-------------------------------------------------------------------

Section::Begin();
BEGIN_PGML

    b\) Complete the following table for the Riemann Left Hand Sum for
    the above integral for [`n=[$n]`] subintervals.

    [$GAP]*
    [@
      BeginTable(border=>1, tex_border=>"1pt", spacing=>0, padding=>5,center=>1).
      AlignedRow([PGML('[`x`]','[`[$a]`]','[`[$a1]`]','[`[$a2]`]','[`[$a3]`]','[`[$a4]`]')],
        align=>"center", separation=>0).
      AlignedRow([PGML('[``f(x)=\frac{[$c]+x}{[$d]+x^2}``]',
        '[__________]{$ans2}','[__________]{$ans3}','[__________]{$ans4}',
        '[__________]{$ans5}','[__________]{$ans6}')],
        align=>"center", separation=>0).
      EndTable()
    @]*

END_PGML
Section::End();

#-------------------------------------------------------------------

Section::Begin();
BEGIN_PGML

    c\) Find the Riemann Left Hand Sum for the above definite integral for [`n=[$n]`].    

    [$GAP]*
    [________________________________________]{$ans7}[@ AnswerFormatHelp("numbers") @]*

END_PGML
Section::End();

#-------------------------------------------------------------------

Section::Begin();
BEGIN_PGML
 
    d\) Determine [``\Delta x``] for the same definite integral with [`n=[$n1]`] this time.

    [$GAP]*
    [``\Delta x = ``][________________________________________]{$ans8}[@ AnswerFormatHelp("numbers") @]*
 
END_PGML
Section::End();

#-------------------------------------------------------------------

Section::Begin();
BEGIN_PGML

    Make another table to find the Riemann Left Hand Sum for [`n=[$n1]`].

    [$GAP]*
    [@
      BeginTable(border=>1, tex_border=>"1pt", spacing=>0, padding=>5, center=>1).
        AlignedRow([PGML('[`x`]','[`[$a]`]','[`[$a11]`]','[`[$a12]`]','[`[$a13]`]','[`[$a14]`]')],
          align=>"center", separation=>0).
        AlignedRow([PGML('[``f(x)=\frac{[$c]+x}{[$d]+x^2}``]',
          '[__________]{$ans9}','[__________]{$ans10}','[__________]{$ans11}',
          '[__________]{$ans12}','[__________]{$ans13}')],
          align=>"center", separation=>0).
        AlignedRow([PGML('[`x`]','[`[$a15]`]','[`[$a16]`]','[`[$a17]`]','[`[$a18]`]','[`[$a19]`]')],
          align=>"center", separation=>0).
        AlignedRow([PGML('[``f(x)=\frac{[$c]+x}{[$d]+x^2}``]',
          '[__________]{$ans14}','[__________]{$ans15}','[__________]{$ans16}',
          '[__________]{$ans17}','[__________]{$ans19}')],
          align=>"center", separation=>0).
      EndTable()
    @]*

END_PGML
Section::End();

#-------------------------------------------------------------------

Section::Begin();
BEGIN_PGML
    Compute the Riemann Left Hand Sum for the above definite integral for [`n=[$n1]`].    
    [$GAP]*
    [________________________________________]{$ans20}[@ AnswerFormatHelp("numbers") @]*
 
    e\) Use  WolframAlpha to find the exact value of the definite integral and compare the answers.    
 
    Use the syntax [`\verb|int (([$c]+x)/([$d]+x^2)) from [$a] to [$b]|`] in Wolfram Alpha to get the answer.    

    [$GAP]*
    [________________________________________]{$ans19}[@ AnswerFormatHelp("numbers") @]*


END_PGML
Section::End();
Scaffold::End();

#---------------------------------------------------------------------------------------------------------------------
# (answer and) solution section
#------------------------------------------------------------------------------------------------------------------

BEGIN_PGML_SOLUTION

a)  Find the step size, [`\Delta x`], for the Riemann Left Hand Sum
    for the above integral for [`n=[$n]`] subintervals.
   
    [``\Delta x = \frac{[$b]-[$a]}{[$n]} = [$ans1]``]

b)  Complete the following table:
    
    [@
      BeginTable(border=>1, tex_border=>"1pt", spacing=>0, padding=>5,center=>1).
      AlignedRow([PGML('[`x`]','[`[$a]`]','[`[$a1]`]','[`[$a2]`]','[`[$a3]`]','[`[$a4]`]')],
        align=>"center", separation=>0).
      AlignedRow([PGML('[``f(x)=\frac{[$c]+x}{[$d]+x^2}``]','[`[$ans2]`]','[`[$ans3]`]',
        '[`[$ans4]`]','[`[$ans5]`]','[`[$ans6]`]')], align=>"center", separation=>0).
      EndTable()
    @]*

c)  Find the Riemann Left Hand Sum for the above definite integral for [`n=[$n]`].
    
    [`[$ans1] \cdot ([$ans2]+[$ans3]+[$ans4]+[$ans5]+[$ans6]) = [$ans7]`]

d)  Make another table to find the Riemann Left Hand Sum for [`n=[$n1]`].
    
    [``\Delta x = \frac{[$b]-[$a]}{[$n1]} = [$ans8]``]
    
    [@
      BeginTable(border=>1, tex_border=>"1pt", spacing=>0, padding=>5,center=>1).
      AlignedRow([PGML('[`x`]','[`[$a]`]','[`[$a11]`]','[`[$a12]`]','[`[$a13]`]',
        '[`[$a14]`]','[`[$a15]`]','[`[$a16]`]','[`[$a17]`]','[`[$a18]`]','[`[$a19]`]')],
        align=>"center", separation=>0).
      AlignedRow([PGML('[``f(x)=\frac{[$c]+x}{[$d]+x^2}``]','[`[$ans9]`]','[`[$ans10]`]',
        '[`[$ans11]`]','[`[$ans12]`]','[`[$ans13]`]','[`[$ans14]`]','[`[$ans15]`]',
        '[`[$ans16]`]','[`[$ans17]`]','[`[$ans18]`]')],
        align=>"center", separation=>0).
      EndTable()
    @]*
    
    Compute the Riemann Left Hand Sum for the above definite integral for [`n=[$n1]`].
    
    [`[$ans8] \cdot ([$ans9]+[$ans10]+[$ans11]+[$ans12]+[$ans13]+
      [$ans14]+[$ans15]+[$ans16]+[$ans17]+[$ans18]) = [$ans20]`]

e)  Use WolframAlpha to find the exact value of the definite integral and compare the answers.    
   
    Use the syntax  [`\verb|int (([$c]+x)/([$d]+x^2)) from [$a] to [$b]|`] in WolframAlpha
    to get the answer.
   
    [`[$ans19]`]

END_PGML_SOLUTION

ENDDOCUMENT();