PREP 2015 Question Authoring - Archived

Number with units/Checking solutions with units/Link to help students with format

Number with units/Checking solutions with units/Link to help students with format

by Regina Souza -
Number of replies: 7

i) Below is a problem students had a hard time with last semester on the College Algebra final exam. I'm stumped at "adding units" to the answer (A pedagogical question: is it worth requiring units in webwork problems?) I commanded out the attempts I made, which were:
a) Loading "parserNumberWithUnits.pl";
b) Attempted to define my $t1 and $t2 as number with units
c) Attempt to put help for students:
help(units) [@ AnswerFormatHelp("units") @]*

ii) I noticed the file "PGML.pl" in the "sample problem". What is it doing? Do we need it?

iii) What should be in "PGcourse.pl"? My fear is that once I put the problems I wrote in my regular courses, they will behave differently than how they behave now.

------------------------------------------------------------------------------------


# DESCRIPTION
# From half-life to formula for an exponential; solve an exp equation
# ENDDESCRIPTION
# Homework/Workshop3/Souza/problem1.pg

#---------------------------------------------------------------------------------------------------------------------
# initialization section
#---------------------------------------------------------------------------------------------------------------------

DOCUMENT();

loadMacros("PGstandard.pl",
"MathObjects.pl",
# "parserNumberWithUnits.pl";
"PGML.pl",
"PGcourse.pl");

Context("Numeric");
Context()->variables->add(t => "Real");

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

$A = random(120,240,10);
$T = random(8,12,1);
$t1 = 2*$T;
#$g1 = NumberWithUnits("$A/2 g");
$g1 = $A/4;

# $n is an integer amount of substance left after about 3.4 half-lives
$n = ceil($A*0.5**(3.4*$T));
$g2 = random($n,$n+6,1);

#$t2 = NumberWithUnits($T*log($g2/$A)/log(0.5) hr");
$t2 = $T*log($g2/$A)/log(0.5);
$f = Formula("$A*0.5^(t/$T)");
$k = ln(0.5)/ $T;
#---------------------------------------------------------------------------------------------------------------------
# text section
#---------------------------------------------------------------------------------------------------------------------

TEXT(beginproblem());

BEGIN_PGML

The half-life of a radioactive substance is [` [$T] `] hours. The amount of [` [$A] `] grams of the substance is present at [` t=0 `].

a. How much of the substance remains after [` [$t1] `] hours? [______]{$g1}.

[% Include units. Need to figure out how to use "units". It looked like the help to students looked like help(units) [@ AnswerFormatHelp("units") @]* %]

b. Write a formula for [` f(t) `] which gives the amount of substance remaining after [` t `] hours. [` f(t) = `] [_________]{$f}.

c. When will there be [` [$g2] `] grams of the substance left? Include units. [_________]{$t2} . [% Include units. Need to figure out how to use "units" %]

END_PGML

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

BEGIN_PGML_SOLUTION

*SOLUTION*

a. Since we start with [` [$A] `] grams of the substance, and every [` [$T] `] days half of the substance is gone, after [` [$t1] `] days, [` 0.25([$A]) `] grams of the substance will be left.

b. If we use base [`` \frac{1}{2} ``] and the fact the half-life is [$T] we easily get the formula [` f(t) = [$f] `].

We can also get a formula with base [` e `]. By solving the equation [`` 0.5([$A]) = [$A]e^{k[$T]} ``] we obtain
[`` f(t) = [$A]e^{kt} ``] where [` k=\frac{\ln(0.5)}{ [$T] } = [$k] `].

c. By solving the equation [`` [$g2] = [$A]\Big(0.5^{t/[$T]} \Big) ``] we obtain
[` t =[$T]*\Big( \frac{\log([$g2])}{[$A]} \Big) /\log(0.5) = [$t2] `].

END_PGML_SOLUTION

ENDDOCUMENT();

In reply to Regina Souza

Re: Number with units/Checking solutions with units/Link to help students with format

by Daniele Arcara -
I copied and pasted your code, removed the '#', and tried it out. It actually worked for me. The only mistake was a missing double quote in your command defining $t2. It should be 

$t2 = NumberWithUnits("$T*log($g2/$A)/log(0.5) hr");

But, besides that missing double quote, it all worked out for me… here is the full code I ended out with (It is Problem 8 in Arcara-Homework3, if you want to see it in action):

DOCUMENT();

loadMacros("PGstandard.pl",
"MathObjects.pl",
"parserNumberWithUnits.pl",
#"parserFormulaWithUnits.pl",
"PGML.pl",
"PGcourse.pl");

Context("Numeric");
Context()->variables->add(t => "Real");

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

$A = random(120,240,10);
$T = random(8,12,1);
$t1 = 2*$T;
$g1 = NumberWithUnits("$A/2 g");
#$g1 = $A/4;

# $n is an integer amount of substance left after about 3.4 half-lives 
$n = ceil($A*0.5**(3.4*$T));
$g2 = random($n,$n+6,1);

$t2 = NumberWithUnits("$T*log($g2/$A)/log(0.5) hr");
#$t2 = $T*log($g2/$A)/log(0.5);
$f = Formula("$A*0.5^(t/$T)");
$k = ln(0.5)/ $T; 
#---------------------------------------------------------------------------------------------------------------------
# text section
#---------------------------------------------------------------------------------------------------------------------

TEXT(beginproblem()); 

BEGIN_PGML

The half-life of a radioactive substance is [` [$T] `] hours. The amount of [` [$A] `] grams of the substance is present at [` t=0 `].

a. How much of the substance remains after [` [$t1] `] hours? [______]{$g1}. 

[% Include units. Need to figure out how to use "units". It looked like the help to students looked like help(units) [@ AnswerFormatHelp("units") @]* %] 

b. Write a formula for [` f(t) `] which gives the amount of substance remaining after [` t `] hours. [` f(t) = `] [_________]{$f}.

c. When will there be [` [$g2] `] grams of the substance left? Include units. [_________]{$t2} . [% Include units. Need to figure out how to use "units" %]

END_PGML

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

BEGIN_PGML_SOLUTION

*SOLUTION*

a. Since we start with [` [$A] `] grams of the substance, and every [` [$T] `] days half of the substance is gone, after [` [$t1] `] days, [` 0.25([$A]) `] grams of the substance will be left.

b. If we use base [`` \frac{1}{2} ``] and the fact the half-life is [$T] we easily get the formula [` f(t) = [$f] `]. 

We can also get a formula with base [` e `]. By solving the equation [`` 0.5([$A]) = [$A]e^{k[$T]} ``] we obtain 
[`` f(t) = [$A]e^{kt} ``] where [` k=\frac{\ln(0.5)}{ [$T] } = [$k] `].

c. By solving the equation [`` [$g2] = [$A]\Big(0.5^{t/[$T]} \Big) ``] we obtain 
[` t =[$T]*\Big( \frac{\log([$g2])}{[$A]} \Big) /\log(0.5) = [$t2] `].

END_PGML_SOLUTION

ENDDOCUMENT();
In reply to Daniele Arcara

Re: Number with units/Checking solutions with units/Link to help students with format

by Regina Souza -
Awesome! I didn't think I was that close! Thanks!

By the way, for the record, there was a mistake on $g1 (I fixed
on "my original" but forgot to fix it on the NumberWithUnits line.
It should be "$A/4 g".

Also, I think there is a place where "days" are mentioned. It should be hours (I had a change of heart about units and ended up not being consistent.)

The command [@ AnswerFormatHelp("units") @]* with the link for the students worked after I loaded "AnswerFormatHelp.pl",

Question: What is the best policy regarding units? Some answers are bound to be grammatically incorrect as in "5.2 day" (since the abbreviation for "days" is "day"). Do we simply ignore it?
In reply to Regina Souza

Re: Number with units/Checking solutions with units/Link to help students with format

by Gavin LaRose -
Hi Regina,

Regarding your question about "day" vs. "days," my inclination is to grin and bear it. In most cases the abbreviation for the unit (e.g., "min") makes the issue of singularity or plurality moot.

Gavin
In reply to Gavin LaRose

Re: Number with units/Checking solutions with units/Link to help students with format

by tim Payer -
I had a calculus problem with an answer that uses units that I would like to use in webwork but it uses the units of mg/cm^3. I looked at the format for permissible units and noticed that while grams are represented by g and centimeters are represented by cm, but there is no representation for milligrams such as mg. Does this mean i would have to ask the students to enter g*10^(-3)?  This seems problematic to require this form. 
In reply to tim Payer

Re: Number with units/Checking solutions with units/Link to help students with format

by Davide Cervone -
you don't make a link to the list of units you looked at, but mg is valid, and mg/cm^3 works fine. If this was a wiki page, please let us know where it is so it can be updated.
In reply to Regina Souza

Re: Number with units/Checking solutions with units/Link to help students with format

by Davide Cervone -
Since you have the units worked out, I wanted to answer some of the other questions:

ii) I noticed the file "PGML.pl" in the "sample problem". What is it doing? Do we need it?

This loads the PGML language into your problems. Without it, you would get an error when you used BEGIN_PGML/END_PGML,. So yes, you need it if you are using PGML.

iii) What should be in "PGcourse.pl"? My fear is that once I put the problems I wrote in my regular courses, they will behave differently than how they behave now.

This file is empty by default (the copy in pg/macros is blank), so unless you make a copy in your course's templates/macros directory, you should not see any change in behavior.

The purpose of the file is to allow you to make course-specific modifications to all problems you use in your course at once. So if you have notational differences (like the different vector delimiters that people have asked about), you can use PGcourse.pl to make the needed changes. But that only works if people actually include PGcourse.pl in their problems.

Because I knew that, even if we ask them to, people won't do this consistently, I made a back door (parserCustomization.pl) for the problems that load MathObjects.pl, but not every problem uses MathObjects, so I still prefer PGcourse.pl to be loaded in every problem.

In reply to Davide Cervone

Re: Number with units/Checking solutions with units/Link to help students with format

by Regina Souza -
Thanks (and thanks for your answers the previous week too: they were very helpful!)