Skip to content

Commit c68d967

Browse files
authored
Merge pull request openwebwork#1169 from gajennings/main
Fix bug 4837, convert to PGML, add solution
2 parents 3967133 + 6168260 commit c68d967

File tree

1 file changed

+37
-21
lines changed

1 file changed

+37
-21
lines changed

OpenProblemLibrary/NAU/setProbability/ExpValueProbModel1.pg

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,44 +17,60 @@ DOCUMENT(); # This should be the first executable line in the problem.
1717

1818
loadMacros(
1919
"PGstandard.pl",
20-
"PGchoicemacros.pl",
21-
"PGgraphmacros.pl",
20+
"MathObjects.pl",
21+
"PGML.pl",
22+
"niceTables.pl",
2223
"PGcourse.pl"
2324
);
2425

25-
TEXT(beginproblem());
26-
$showPartialCorrectAnswers = 1;
26+
Context("Numeric");
2727

28+
@seq=();
29+
for (0..12){
30+
push @seq, $_/2;
31+
}
32+
33+
@out = random_subset(4,@seq);
2834

29-
@out=();
30-
push @out, random(0,6,.5) foreach 0..3;
3135
@outcome=num_sort(@out);
3236

3337
$a=random(0.05,.40,.05);
3438
$b=random(0.05,.40,.05);
35-
$ans1=1-$a-$b-0.15;
39+
$ans1=Real(1-$a-$b-0.15);
3640
@prob=($a,$b,0.15,$ans1);
3741

3842

39-
$ans=0;
43+
$ans2=0;
4044
for($i=0; $i<4; $i++){
41-
$ans=$ans+$outcome[$i]*$prob[$i];
45+
$ans2=$ans2+$outcome[$i]*$prob[$i];
4246
}
47+
$ans2=Real($ans2);
48+
49+
$tab = DataTable(
50+
[
51+
["Outcome", $outcome[0], $outcome[1], $outcome[2], $outcome[3]],
52+
["Probability", $prob[0], $prob[1], $prob[2], ans_rule(5)]
53+
],
54+
horizontalrules => 1,
55+
texalignment => 'l|c|c|c|'
56+
);
57+
58+
BEGIN_PGML
59+
60+
Below is a partially complete probability model. Enter the probability for the final outcome.
61+
62+
[@ $tab @]*
63+
64+
Find the expected value of the probability model. [__]{$ans1}{30}
65+
END_PGML
4366

44-
BEGIN_TEXT
67+
ANS($ans2->cmp());
4568

46-
Below is a partially complete probability model. Enter the probability for the final outcome. $BR
47-
\{begintable(9)\}
48-
\{row("Outcome", $outcome[0], $outcome[1], $outcome[2], $outcome[3])\}
49-
\{row("Probability", $prob[0], $prob[1], $prob[2], ans_rule(5))\}
50-
\{endtable()\} $BR $BR
51-
Find the expected value of the probability model. $BR $BR
52-
\{ans_rule(30)\}
53-
$BR
54-
END_TEXT
69+
BEGIN_PGML_SOLUTION
70+
The probabilities must add up to 1, so the probability that the outcome equals [$outcome[3]] is 1-([$prob[0]]+[$prob[1]]+[$prob[2]]) = [$ans1] .
5571

56-
ANS(num_cmp($ans1));
57-
ANS(num_cmp($ans));
72+
The expected value is ([$prob[0]])([$outcome[0]])+([$prob[1]])([$outcome[1]])+([$prob[2]])([$outcome[2]])+([$ans1])([$outcome[3]])=[$ans2] .
73+
END_PGML_SOLUTION
5874

5975
ENDDOCUMENT(); # This should be the last executable line in the problem.
6076

0 commit comments

Comments
 (0)