Difference between revisions of "ChemicalReaction1"
Paultpearson (talk | contribs) (PGML example for chemical reactions) |
Paultpearson (talk | contribs) m |
||
Line 100: | Line 100: | ||
<b>Setup:</b> |
<b>Setup:</b> |
||
We create a couple of arrays <code>@reactants</code> and <code>@products</code> and fill them with some examples of balanced chemical equations. The second and third examples show that groupings, such as for <code>(OH)_2</code> are necessary. The third example shows how you could randomize a chemical reaction question. In particular, note that <code>${b}_2</code> is needed instead of <code>$b_2</code> so that Perl interprets the variable as <code>$b</code> with a subscript of 2 instead of a variable named <code>$b_2</code> with no subscript. |
We create a couple of arrays <code>@reactants</code> and <code>@products</code> and fill them with some examples of balanced chemical equations. The second and third examples show that groupings, such as for <code>(OH)_2</code> are necessary. The third example shows how you could randomize a chemical reaction question. In particular, note that <code>${b}_2</code> is needed instead of <code>$b_2</code> so that Perl interprets the variable as <code>$b</code> with a subscript of 2 instead of a variable named <code>$b_2</code> with no subscript. |
||
− | </p> |
||
− | <p> |
||
− | For more details on adding the Heaviside function to the context, see the forum discussion on the [http://webwork.maa.org/moodle/mod/forum/discuss.php?d=458 Heaviside step function] |
||
</p> |
</p> |
||
</td> |
</td> |
Revision as of 13:59, 27 June 2015
Chemical Reactions
This PG code shows how ask questions about chemical reactions.
- PGML location in OPL: FortLewis/Authoring/Templates/Misc/ChemicalReaction1_PGML.pg
PG problem file | Explanation |
---|---|
Problem tagging: |
|
DOCUMENT(); loadMacros( "PGstandard.pl", "PGunion.pl", "MathObjects.pl", "PGML.pl", "contextReaction.pl", "PGcourse.pl", ); TEXT(beginproblem()); # uncomment $showPartialCorrectAnswers = 1; |
Initialization:
Load |
Context("Reaction"); @reactants = (); @products = (); $reactants[0] = Formula("2C_2H_6 + 7O_2"); $products[0] = Formula("4CO_2 + 6H_2O"); $reactants[1] = Formula("6CO_2 + 6O_2"); $products[1] = Formula("C_6 H_12 O_6 + 6 O_2"); $reactants[2] = Formula("3 Ca Cl_2 + 2 Na_3 PO_4"); $products[2] = Formula("Ca_3 (PO_4)_2 + 6 Na Cl"); # variations on 2NaOH + MgCl_2 --> 2NaCl + Mg(OH)_2 $a = list_random('Li','Na','K'); $b = list_random('F','Cl','Br'); # Use ${b}_2 instead of $b_2 below so that Perl knows the # variable name is $b = ${b} and not $b_2 = ${b_2}. $reactants[3] = Formula("2 $a OH + Mg ${b}_2"); $products[3] = Formula("2 $a $b + Mg (OH)_2"); $num_choices = $#reactants; $i = random(0,$num_choices,1); |
Setup:
We create a couple of arrays |
BEGIN_PGML [` [$reactants[ $i ]] \longrightarrow `] [_____________________________]{$products[ $i ]} Enter a subscript using an underscore, such as [| H_2 O |]* for [` \mathrm{H_2 O} `]. END_PGML COMMENT('MathObject version. Uses PGML.'); ENDDOCUMENT(); |
Main Text:
Note that we uses spaces around |