Forums

Search results: 135

contextReaction.pl works very nicely...but I have discovered a bit of a problem when entering compounds with complex ions.
Compounds such as Zn(ClO_{3})_{2} are not liked by the macro. Any suggestions? I have included a short sample problem below the error message generated by fixing the choice to a reaction scheme that triggers the error.
It may also be necessary for contextReaction to have a comma put in line 132 between Pb and Bi. I was having lead containing formulae rejected until I changed my copy.
Thanks for all the help.

Error messages

The left-hand side of '_' must be an element, not a compound; see position 17 of formula at line 395 of [TMPL]/macros/contextReaction.pl Died within context::Reaction::BOP::underscore::_check called at line 35 of [PG]/lib/Parser/BOP.pm from within Parser::BOP::new called at line 494 of [PG]/lib/Parser.pm from within Parser::Precedence called at line 381 of [PG]/lib/Parser.pm from within Parser::Close called at line 145 of [PG]/lib/Parser.pm from within Parser::parse called at line 50 of [PG]/lib/Parser.pm from within Parser::new called at line 19 of [PG]/lib/Value/Formula.pm from within Value::Formula::new called at line 64 of [PG]/macros/Parser.pl from within main::Formula called at line 105 of [TMPL]/chem1l2/predicting_products/pred_prod.pg


The file responsible
DOCUMENT();
#
# Predict products of a chemical reaction.
# Student presented with the (balanced) reactants and asked for products.
# Answer must present balanced products.
# If a reaction does not proceed as written the product is NR.
#
loadMacros(
"PG.pl",
"PGbasicmacros.pl",
"PGchoicemacros.pl",
"PGanswermacros.pl",
"PGauxiliaryFunctions.pl",
"MathObjects.pl",
"Parser.pl",
"PGstandard.pl",
"contextReaction.pl");
#
# Normally this hash would be stored under macros and called above
#
%reactions=(
1=>{equation=>"N_{2} + H_{2} \longrightarrow NH_{3}",
class=>"combination",
components=>[
{type=>"reactant", compound=>"N_{2}", coef=>1 },
{type=>"reactant", compound=>"H_{2}", coef=>3 },
{type=>"product", compound=>"NH_{3}", coef=>2 },]},
2=>{equation=>"Cu + Zn(ClO_{3})_{2} \longrightarrow NR",
class=>"single-replacement",
components=>[
{type=>"reactant", compound=>"Cu", coef=>"" },
{type=>"reactant", compound=>"Pb(ClO_{3})_{2}", coef=>"" },
{type=>"product", compound=>"NR", coef=>"" },]},
3=>{equation=>"CuNO_{3} + CuCl \longrightarrow NR",
class=>"double-replacement",
components=>[
{type=>"reactant", compound=>"CuNO_{3}", coef=>"" },
{type=>"reactant", compound=>"CuCl", coef=>"" },
{type=>"product", compound=>"NR", coef=>"" },]},
);
#
Context("Reaction");
Context()->variables->add(NR => $context::Reaction::CONSTANT);
#
# Pick a reaction from the selected database
#
$number_of_reactions = keys %reactions;
@items=(1..$number_of_reactions);
$S = list_random(@items);
#
# Get skeleton equation, type of reaction, then get
# info about coefficients and calculate formula masses
#
$equation = $reactions{$S}{equation};
$type = $reactions{$S}{class};
$i=0;
$j=0;
for $who (@{$reactions{$S}{components}})
{
$kind=$who->{type};
if($kind eq "reactant")
{$n_r =$i;
$react[$i] = $who->{compound};
$react_coef[$i]=$who->{coef};
$i=$i+1;
}
if($kind eq "product")
{$n_p=$j;
$prod[$j] = $who->{compound};
$prod_coef[$j]=$who->{coef};
$j=$j+1;
}
}
#
# Build reactants and products sides of equation
#
$reactants = '';
for ($i=0;$i<=$n_r;$i++)
{ if($i < $n_r)
{$and = ' + ';}
if($i ==$n_r)
{$and = '';}
$r_c = '';
if($react_coef[$i] != 1)
{$r_c = $react_coef[$i]}
$reactants = $reactants.$r_c.$react[$i].$and;
}
$products = '';
for ($i=0;$i<=$n_p;$i++)
{ if($i < $n_p)
{$and = ' + ';}
if($i ==$n_p)
{$and = '';}
$p_c = '';
if($prod_coef[$i] != 1)
{$p_c = $prod_coef[$i]}
$products = $products.$p_c.$prod[$i].$and;
}
#
$react = Formula($reactants);
$prod = Formula($products);
#
Context()->texStrings;
BEGIN_TEXT
For the following problem your answer must be entered in LaTeX format.
as discussed in lecture.
$BR
Predict the products for the $type reaction shown.$BR
If a combination does not react the products should be input as NR.$BR
\($react \longrightarrow\) \{ans_rule(30)\}.
END_TEXT
Context()->normalStrings;
#
ANS($prod->cmp);
ENDDOCUMENT();
Hi Bruce,

I'm not totally clear on what you want, but I think you should be able to modify the code below to get what you want. You may also want to look into two of the ways to write MultiPart questions at

http://webwork.maa.org/wiki/ProvingTrigIdentities1

http://webwork.maa.org/wiki/ProvingTrigIdentities2
http://webwork.maa.org/viewvc/system/trunk/pg/macros/compoundProblem.pl?revision=6387&view=markup

Best Regards,

Paul

##### begin PG code ########

##################
# Initialization

DOCUMENT();

loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"parserMultiAnswer.pl",
"unionTables.pl",
);

TEXT(beginproblem());

##################
# Setup

Context("Numeric");

$a = 2;
$b = 4;
$c = 3;
$d = 9;

$multians = MultiAnswer($a,$b,$c,$d)->with(
singleResult => 0,
allowBlankAnswers => 1,
checker => sub {
my ( $correct, $student, $self ) = @_;
my ( $stu11, $stu12, $stu21, $stu22 ) = @{$student};
my ( $cor11, $cor12, $cor21, $cor22 ) = @{$correct};

if ( (($cor11==$stu11 && $cor12==$stu12) && ($cor21==$stu21 && $cor22==$stu22)) ||
(($cor21==$stu11 && $cor22==$stu12) && ($cor11==$stu21 && $cor12==$stu22)) )
{
return [1,1,1,1];

} elsif ( (($cor11==$stu11 && $cor12==$stu12) || ($cor21==$stu11 && $cor22==$stu12)) ) {

$self->setMessage(3,"Your second answer is incorrect because...");
return [1,1,0,0];

} elsif ( (($cor11==$stu21 && $cor12==$stu22) || ($cor21==$stu21 && $cor22==$stu22)) ) {

$self->setMessage(1,"Your first answer is incorrect because...");
return [0,0,1,1];

} else {
return [0,0,0,0];
}
}
);


#########################
# Main text

Context()->texStrings;
BEGIN_TEXT
Enter the points on the parabola \( y = x^2 \)
with x-coordinates 2 and 3.
\{
BeginTable().
AlignedRow(["\( \big( \)", $multians->ans_rule(10), ",", $multians->ans_rule(10), "\( \big) \)"], separation=>2).
TableSpace(5,25).
AlignedRow(["\( \big( \)", $multians->ans_rule(10), ",", $multians->ans_rule(10), "\( \big) \)"], separation=>2).
EndTable();
\}
END_TEXT
Context()->normalStrings;

#########################
# Answer evaluation

$showPartialCorrectAnswers = 1;

ANS( $multians->cmp() );

ENDDOCUMENT();


##### end PG code ########
Hal,
At WPI we've been using WeBWorK for freshman calculus placement for
several years. The number of students is much smaller - only about
900 per year, but we have implemented some of the features you
are interested in. Below I've responded to your five technical issues.

1, 2. Enrollment of students and assignment.
When a freshman officially enrolls, they get a computer account username
and password. This information is used to automatically enroll the
student in the placement test course and make assignments. This
is done by directly writing information to the WW mysql database. The
programming is in C, and was not done by me but by one of our outstanding computer support people.

3. Reporting results to the student.
The last problem in the placement test has two parts and uses
Davide Cervone's compoundProblem package. Answering the first
part of the problem sets a value in the WW database that says
the student is done. The student can then go on to the second part
of the problem, which contains a link to an external web site. If the
student clicks on the link, external programming is triggered that
collects information from the WW database, generates a recommendation,
and saves information to an external (to WW) database. It also sets
a field in the WW database that indicates the student has been processed.
The recommendation appears on the screen and is also e-mailed to the student.

If a student chooses not to view the recommendation immediately, there
is a chron job that runs early every morning to process students who
are done with the exam but chose not to see the recommendation
immediately. This generates the recommendation e-mail and writes
the information to the external database.

4. Reports to registrar.
Students, faculty, and academic advising staff can use the web site to
view the recommendation for a particular student or generate summary
reports. More complicated reports can be generated by accessing the
mysql database where the placement info is stored.

5. Retiring students
I have a model placement test course that I use to generate the
placement test course each year. After the end of a placement
cycle, the current course is deactivated, meaning that no more
students are added to that course. Before the next cycle begins, I
create a new placement course.

In the external data base, there is a different table for each cycle.


I'm not sure how much of our experience can be translated to your
very different situation, but it does indicate that at least part of
what you are interested in is possible.

Regards,
Bill Farr
Worcester Polytechnic Institute
Hi all,
Before starting typing code I would like to ask you where I can find the documentation regarding the tables of the database and how the 'answer button' works in webwork. Knowing these documents maybe I could figure out why it is not working with moodle and find a better solution to my problem.

Thanks a lot,
Angel
Mike, Angel, Paul,
I would appreciate being informed of everything that is being done with bridge 2. We, at University of New Hampshire, are building an adaptive WeBWorK system for middle school. Initially, we had been working with Matt Leventi to use Moodle to provide parts of the adaptive component that are not available in WeBWorK itself. When
Matt left we decided to make sure that we built adequate
problem libraries so that when bridge 2 began to move again we would be ready to take full advantage of it. Now, it seems that you are making it move and we bless you for that and want to do all we can to cooperate as well as take advantage of your progress.
Ken Appel
I believe you are correct. I know that Matt Leventi who wrote "bridge2" implemented a lot of caching for speed. I will be attending the annual joint math meetings this next week but in about two weeks, after I have the semester's classes started, I'll have some time to look more closely at this.

I'm glad you are interested in working on it.

--Mike
Hi Mike,

I think moodle doesn't refresh the perl code once it has shown it (that's why in compound problems it always shows the first part), I've tested an example to see if the 'score' changes when you submit the correct answer and it's always printing score 0.

Here the example:

$a1 = 10;


BEGIN_TEXT
Write $a1
$BR $BR \{ans_rule(10) \}
$BR
END_TEXT

$ans_eval1 = num_cmp($a1);
$score = $ans_eval1->evaluate()->{score};
BEGIN_TEXT
$score
END_TEXT

ANS($ans_eval1);


I attached the screenshot once I have submitted the correct answer.

Next week I will try the solution about the page break and let you know about it.

Thanks to all,

Angel
Attachment screenshot14.png
Hi Paul,

About the compound problem I have clicked submit button several times (with the checkbox selected) but nothing happens.

Thanks for your information about 'conditional questions'. I've tried the example but it doesn't work. It seems moodle doesn't like the 'NAMED_ANS' or 'NAMED_ANS_RULE' fields.

I've written a simple example, but it is always showing the answer as incorrect.

Thanks

DOCUMENT();
loadMacros(
"PGbasicmacros.pl",
"PGchoicemacros.pl",
"PGanswermacros.pl"
);
TEXT(beginproblem(), $BR,$BBOLD, "Conditional questions example", $EBOLD, $BR,$BR);
$showPartialCorrectAnswers = 1;

$a1 = 10;


BEGIN_TEXT
Write $a1
$BR $BR \{NAMED_ANS_RULE('first_answer',10) \}
$BR
END_TEXT

$ans_eval1 = num_cmp($a1);
NAMED_ANS(first_answer => $ans_eval1);


ENDDOCUMENT();
That sounds like a good idea for now. If it works well we can bake it into the moodle/webwork code so that it is easier to set up. I'm working on a rewrite of the basic underpinnings of webwork (originally written more than 10 years ago) which will take a while to finish -- but it should allow us to customize an output mode specifically for moodle. This should make the bridge2 more robust.

The current version of bridge2 was written under the constraint that nothing was changed on the webwork side so some compromises had to be made. By making some additions to the webwork side I think we can make this connection much stronger.