Forums

Search results: 133

I’ve now modified the relevant page. But:

The template you showed doesn't appear on the page you gave, and doesn't work the way you suggested. That MediaWiki page also provided an Obsolete template, so I tried that, but it also doesn’t work according to their documentation.

So I added both those tags/templates, as well as a separate paragraph redirecting the user. Finally, on the Problem Techniques page I added a “see also”.

Let me know if that was OK, or if any of it should change.
It's ok to edit -- in fact we encourage it. Pages are versioned so you can always back out if necessary. It also doesn't hurt to ask before or during edits if you have questions. That may save some time.

One template that might help you with the redirection task is this MediaWiki construction -- (you can google it for more information) or https://www.mediawiki.org/wiki/Category:Alert_templates

{{Historical|Foo [[test]] foo.}}

Which produces a banner about this being a historical document. The second part of the entry gives a link to follow for a more up-to-date information and some explanation.

The only reason this hasn't been done is lack of person-hours. Your help would be very useful.

There are also compoundProblems2.pl, etc as well as sequentialProblems.pl. The development of the right mechanism took many iterations of development over about 10 years.


The current version is quite powerful and could use a full length blog post about how to use it creatively. (That could be placed on the wiki or sometimes it gets more publicity if it's contributed to the blog aggregator reached by the "blogs" link in the left margin of the wiki. ) It's most lack of time that keeps documentation from being higher priority. :-)


Glad this is now working well for you and I look forward to the problems you produce while experimenting with it. I think scaffolded.pl problems have a lot of potential that is only beginning to be investigated. Thanks for letting us know how things turned out.





You aren’t kidding. I just wrote three problems using scaffold.pl, and it worked great! The only downside is that I now have to go back and rewrite my old problems.

That said, the natural place to go looking for help on this is (as far as I know) the Problem Techniques Wiki, and the only techniques listed that obviously apply to multi-part problems are “Compound (Multi-part, sequential) Problems” and “Multi-Part, Sequential Problems”. Both link to a page that has nothing about scaffold.pl. I can edit that page with a note that the techniques listed there are considered obsolete, adding a link to the page on Scaffolding. Is that OK? I’m leery about rushing in; for all I know, there’s a reason it hasn't already been done.


Mike is right, the compundProblem.pl macros are very old and no longer supported, and the scaffold.pl macros are much better and easier to use. In particular, you don't have to keep track to the number of problems, as you did with compoundProblem.pl.

You don't give enough of your problem code to really check what you are doing, but compoundProblem isn't designed to do what you are trying to do (you can't have the same answer rules show up in more than one part, as you appear to be doing, or they will count as answers in both parts, and I'm not sure that will be graded correctly even if you do.

Fortunately, the scaffold macros are set up to provide more flexibility, and you can have previous parts open when later parts are being displayed.

Here is an example of what I think you are after:


loadMacros(
  "scaffold.pl",
  "parserPopUp.pl",
  "parserMultiAnswer.pl",
);

Context("Numeric");
Context->strings->are(yes=>{}, no=>{});

Scaffold::Begin(is_open => 'correct_or_first_incorrect');

$a = random(2,5,1);
$b = random(3,7,1);
$x = random(1,5,1);
$y = random(2,6,1);
$c = $a * $x + $b * $y;

$p = PopUp(["?","yes","no"],"yes");

$ma = MultiAnswer($x,$y)->with(
  checker => sub {
    my ($C, $S) = @_;
    my ($x, $y) = @$S;
    return $a * $x + $b * $y == $c && $x == int($x) && $y == int($y);
  }
);

Section::Begin("Part 1: The Equation");

BEGIN_TEXT
Does the following Diophantine equation have integer solutions?
$PAR
\[ $a x + $b y = $c \]
\{ $p->menu \}
END_TEXT

ANS($p->cmp);

Section::End();
    
Section::Begin("Part 2: The Solution");

BEGIN_TEXT
Good! What is one possible solution?
$PAR
\(x\equiv\) \{ $ma->ans_rule(5) \} and \(y\equiv\) \{ $ma->ans_rule(5) \}
END_TEXT

ANS($ma->cmp);

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

You should be able to start with this and modify it to your needs. See the scaffold.pl documentation for details.

Hi John,

This isn't directly a reply to your question, but you should be aware that
compoundProblem.pl is deprecated (it is being kept around for backwards compatibility) and it is better to use scaffold.pl

and

which is more flexible and probably easier to use.
(There is also http://webwork.maa.org/wiki/CompoundProblem5 but again this is an older implementation of the scaffolding model.)

Hope this helps.






WeBWorK Problems -> curious behavior of compoundProblem.pl

by John Perry -
I wrote a WW problem using compoundProblem.pl. I didn’t want to rewrite the text to the first part in subsequent parts, so I formatted the problem as follows:
Does the following Diophantine equation have integer solutions?
\[ $a x + $b y = c \]
\{ $has_solution->menu() \} # $has_solution is a PopUp
END_TEXT Context->normalStrings;
ANS( $has_solution->cmp() );
if ( $part >= 2 ) {
Context->texStrings;
BEGIN_TEXT
Good! What is one possible solution?
$PAR
\(x\equiv\) \{ ans_rule(5) \}
END_TEXT
Context->normalStrings;
# and so forth
The key here is that
  • I have no guard to print the introduction and its answer field for the first part; i.e., no if ($part == 1), and
  • I have if ($part >= 2) rather than the documentation’s if ($part == 2) because there’s a third part, too, and I wanted the text in part 2 to stick around there, as well.
As I say, there were three parts total. The upshot is that the answer field for part 1 is counted 3 times (once for part 1, once again for part 2, and a third time for part 3), while the answer field for part 2 was counted twice (once for part 2, and once again for part 3).

So the correct value of totalAnswers when declaring this compoundProblem was 6, not 3 as I originally expected. I say this because when the student gets the answers right, setting totalAnswers to 3 leads to a score of 200% and a mysterious-looking X on the student’s progress page, as well as problems with the student score, whereas setting totalAnswers to 6 leads to a 100% and the expected 100 on the student’s progress page.

I want to make sure this is the desired behavior. It took me a couple of hours to figure out what was going on, so I’d be happy to add a note to the Wiki for the other rare birds like myself who try to do something like this. If this is not the desired behavior, but rather a bug, then of course I’d much prefer to change the problems now so that I do not have to worry about surprises in the future.

I’m trying to code a compound interest problem A=P(1+r/n)^(nt) asking students to find the least value of n, the number of times interest is compounded, to attain a specific value A (when the initial principal P, interest rate r, and number of years t are fixed).

I defined a function that seems to evaluate correctly when asked for values of A for n = 1, 2, 12, 52, and 365.

I then tried to use a do-until loop for WeBWorK to determine a desired value of n. My code seemed to work ok to find n for a value of A attained at n=16. But I got an incorrect value of n=33 when the desired value of A should have required n=30; I got an incorrect value of n=69 when the correct value was n=59, and WeBWorK timed out in another case when n should have been 553.

Here’s a partial version I’ve been trying to debug.

DOCUMENT();

loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"PGML.pl",
"PGchoicemacros.pl",
"niceTables.pl",
);

Context()->flags->set( reduceConstants => 0, reduceConstantFunctions => 0 );
Context()->variables->add( n => "Real" );
Context()->flags->set(limits=>[1,365]);

$p0 = 1000;
$t = 5;
$r0 = 12;
$r = $r0/100;
$f = Formula("$p0*(1 + $r/n)^($t*n)");

#######################################################
### this is just trying to find my error in defining f
$a = $f->eval(n=>(15));
$b = $f->eval(n=>(16));
$one = $f->eval(n=>(30));
$two = $f->eval(n=>(31));
$three = $f->eval(n=>(58));
$four = $f->eval(n=>(59));
$five = $f->eval(n=>(552));
$six = $f→eval(n=>(553));
### or maybe limitations in WeBWorK’s evaluating f
################################################


# here is a loop trying to find a value of n
$p1 = 1818;
$n1 = 12;
do{
$temp1 = $f->eval(n=>($n1+2));
$n1 = $n1+1;
} until ( $temp1 > $p1 );

# here is a loop trying to find a value of n
$p2 = 1820;
$n2 = $n1;
do{
$temp2 = $f->eval(n=>($n2+2));
$n2 = $n2+1;
} until ($temp2 >$p2);

# here is a loop trying to find a value of n
$p3 = 1821; #want 1822 but get timeout
$n3 = $n2;
do{
$temp3 = $f->eval(n=>($n3+2));
$n3 = $n3+1;
} until ($temp3 > $p3);

Context()->{format}{number} = "%.6f#";

BEGIN_PGML

[`n=15`] gives [$a], [`n=16`] gives [$b]

[`n=30`] gives [$one], [`n=31`] gives [$two], [`n=58`] gives [$three], [`n=59`] gives [$four],

[`n=552`] gives [$five], [`n=553`] gives [$six],


Use the formula for compound interest,
>>[``A=P\left(1+\dfrac{r}{n} \right)^{nt} ``]<<

Suppose you invest $[$p0] at [$r0]% annual interest for [$t] years. In this problem, we will investigate how the number of compounding periods, [`n`], affects the amount, [`A`].
c.
What value of [` n `] is necessary to produce an amount [` A\gt [$p1]`]? [`n=`][___] To produce [` A\gt [$p2] `]? [`n=`][___] To produce [` A\gt [$p3] `]? [`n=`][___]

END_PGML

ANS(Compute("$n1")->cmp( tolType => 'absolute', tolerance => .5,) );
ANS(Compute("$n2")->cmp( tolType => 'absolute', tolerance => .5,) );
ANS(Compute("$n3")->cmp( tolType => 'absolute', tolerance => .5,) );

ENDDOCUMENT(); # This should be the last executable line in the problem.
Generally monovalent ions are just given the charge without a number, e.g. Cl^{-}, Na^{+}, instead of Cl^{-1}, Na^{+1}.

Yes, I wondered about that. Doing that may be difficult to accomplish, as the MathObjects parser expects an operator to have at least one operand (and plus and minus need to be operators in order to handle negative numbers and adding two compounds). It might be possible to subclass something to override that, but I haven't looked into that.

There is also some variation as to the ordering of charge information...Pb^{+2} or Pb^{2+}, Cl^{1-}

That might be able to be handled as well, but I will have to look into it further.
I am attempting to write a problem that takes a student answer for the ions resulting when a compound dissolves.
Students are given a compound. e.g.
BeF_{2}(aq) and asked to give the answer
Be^{+2}(aq) + 2F^{-1}(aq).
I have stored the correct answer in a List as Be^{+2}(aq),2F^{-1}(aq).
I have tried a custom answer checker that I hoped removed white-space and changed )+ to a comma.
Basically, I want to check the results without having to make the students give products in any order.
The code does give the correct list when checking 'correct answers, but does not appear to parse the student input.
What have I missed? (Tons probably, but I'm used to that.)
Thanks.

#
#Show products of aqueous ionization
#
DOCUMENT();
loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"contextArbitraryString.pl",
"parserFunction.pl",
"unionLists.pl",
"PGcourse.pl"
);

#
#identify number of ions in a formula name
#
%compounds=(
1=>{name=>"Beryllium Fluoride",
formula=>"BeF_{2}",
sol=>"insoluble",
ions=>[{ion=>"Be^{+2}", name=>"beryllium", count=>1},
{ion=>"F^{-1}", name=>"fluoride", count=>2}],
composition=>[
 {atom=>4, count=>1},
 {atom=>9, count=>2},]},
);

TEXT(&beginproblem);
Context("ArbitraryString");
$showPartialCorrectAnswers = 1;
#
#Get info from database
#
$count=keys %compounds;
@items=(1..$count);
$S = list_random(@items);
$name = $compounds{$S}{name};
$form = $compounds{$S}{formula};
$i=0.;
for $who (@{$compounds{$S}{ions}})
 {$n=$i;
  $ion_at[$i]=$who->{ion};
  $N_ion[$i] = $who->{count};
  $i=$i+1;
  }
$i=0;
#
# answers for dissolved compound
#
$cation = $N_ion[0].$ion_at[0]."(aq)";
$anion = $N_ion[1].$ion_at[1]."(aq)";
$answer=List($cation,$anion);
#
#Students are given examples of expected TeX input of formulae
#
BEGIN_TEXT
For this question you must enter your symbol/formula in LaTeX format.$BR
Examples are shown in the table below.$BR
\{image("LaTeX_formulae.png")\}$BR
Complete the following. You must balance properly.$BR
(Enter your answer with the appropriate state designation.)

\($form(aq) \longrightarrow \) \{ans_rule(20)\}

END_TEXT

ANS(List($answer)->cmp(
list_checker => sub {
my ($correct,$student,$ansHash,$value) = @_;
my $n = scalar(@$student); # number of student answers
my $score = 0; # number of correct student answers
for ($i = 0; $i < $n; $i++) {
$cor = $correct ->[$i];
$stu= $student->[$i];
$stu=~ s/ //g; # remove whitespace
$stu=~ s/~~)+/,/g; # remove )+ and replace with ,
if($cor eq $stu){$score++;}
}
return $score;
}
));

ENDDOCUMENT();