Skip to content

Commit e0f4d06

Browse files
authored
Merge pull request #1058 from gajennings/main
Fix bug 4770 (last fix was broken), update to PGML
2 parents f56bdef + bb76173 commit e0f4d06

File tree

1 file changed

+22
-35
lines changed

1 file changed

+22
-35
lines changed

OpenProblemLibrary/AlfredUniv/diffeq/modeling/logisticwithemigration.pg

Lines changed: 22 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ DOCUMENT();
2323
loadMacros(
2424
"PGstandard.pl",
2525
"MathObjects.pl",
26+
"PGML.pl",
2627
"PGcourse.pl"
2728
);
2829

@@ -32,55 +33,41 @@ TEXT(beginproblem());
3233
# Show which answers are correct and which ones are incorrect
3334
$showPartialCorrectAnswers = 1;
3435

35-
Context()->variables->{namePattern} = qr/[a-z][a-z0-9_]*'*/i;
36-
Context()->variables->are("t"=>"Real","P"=>"Real","P'"=>"Real","P''"=>"Real","P'''"=>"Real");
37-
3836
##############################################################
3937
#
4038
# Setup
4139
#
42-
#
40+
41+
Context("Numeric");
42+
43+
Context()->variables->{namePattern} = qr/[a-z][a-z0-9_]*'*/i;
44+
Context()->variables->are("t"=>"Real","P"=>"Real","P'"=>"Real","P''"=>"Real","P'''"=>"Real");
45+
4346
$r = Compute(random(2,4));
4447
$C = Compute(random(5000,10000,500));
4548
$e = Compute(random(4,9));
46-
$diffeqn = Formula("P'-$r*($C-P)+$e");
49+
50+
$diffeqn = Compute("P'-$r*($C-P)+$e")->cmp(
51+
checker => sub{
52+
my ( $correct, $student, $self ) = @_;
53+
my $mult = ($student->D('P'))/$r;
54+
if ($mult == Formula(0)) { return 0;}
55+
else { return $student == $mult*$correct; }
56+
}
57+
);
4758

4859
##############################################################
4960
#
5061
# Text
5162
#
52-
#
53-
54-
Context()->texStrings;
55-
BEGIN_TEXT
56-
Before the year 2000 the population of Cook Island was modeled by a logistic equation \(P^\prime=r(C-P)\) with growth rate \(r=$r\) and carrying capacity
57-
\(C=$C\) and time t in years.
58-
$BR
59-
But, starting in the year 2000, $e citizens of Cook Island left every year to become mathematicians, never to return. Now what differential equation models the population P of the island?
60-
61-
$PAR
62-
\(0 = \)\{$diffeqn->ans_rule(25)\}
63-
END_TEXT
64-
Context()->normalStrings;
6563

66-
##############################################################
67-
#
68-
# Answers
69-
#
70-
#
64+
BEGIN_PGML
65+
Before the year 2000 the population of Cook Island was modeled by a logistic equation [`P^\prime=r(C-P)`] with growth rate [`r=[$r]`] and carrying capacity
66+
[`C=[$C]`] and time t in years.
7167

72-
ANS($diffeqn->cmp(checker=>sub {
73-
my ( $correct, $student, $self ) = @_;
74-
my $context = Context()->copy;
75-
$context->flags->set(no_parameters=>0);
76-
$context->variables->add('c0'=>'Parameter');
77-
my $c0 = Formula($context,'c0');
78-
$student = Formula($context,$student);
79-
$correct = Formula($context,"$c0*(P'-$r*($C-P)+$e)");
80-
$zero = Formula($context,"0");
81-
return (($correct == $student)&&($student!=$zero));}));
82-
# relative tolerance --3.1412 is incorrect but 3.1413 is correct
83-
# default tolerance is .01 or one percent.
68+
But, starting in the year 2000, [$e] citizens of Cook Island left every year to become mathematicians, never to return. Now what differential equation models the population [`P`] of the island?
8469

70+
[`0 = `][____]{$diffeqn}{25}
71+
END_PGML
8572

8673
ENDDOCUMENT();

0 commit comments

Comments
 (0)