Skip to content

Commit abe3e59

Browse files
authored
Merge pull request #1437 from dlglin/update-ASU-max-min
Convert problem to PGML
2 parents 3935b96 + 7a5bcb7 commit abe3e59

1 file changed

Lines changed: 43 additions & 98 deletions

File tree

  • OpenProblemLibrary/ASU-topics/setOptimization

OpenProblemLibrary/ASU-topics/setOptimization/4-5-23.pg

Lines changed: 43 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -11,119 +11,64 @@
1111
## Level(4)
1212
## KEYWORDS('Optimization' 'Maximum' 'Minimum')
1313

14-
DOCUMENT(); # This should be the first executable line in the problem.
14+
DOCUMENT(); # This should be the first executable line in the problem.
1515

16-
loadMacros(
17-
"PGstandard.pl",
18-
"PGchoicemacros.pl",
19-
"PGcourse.pl"
20-
);
16+
loadMacros('PGstandard.pl', 'PGML.pl', 'PGcourse.pl');
2117

22-
$at = non_zero_random(-4,4,2);
23-
$a = $at + 5;
24-
$b = 10-$a;
25-
$c0 = random(2,12,1);
26-
$c1 = -3*$a*$b;
27-
$c2 = 3*($b-$a)/2;
28-
$p1 = -$b -1;
18+
$at = non_zero_random(-4, 4, 2);
19+
$a = $at + 5;
20+
$b = 10 - $a;
21+
$c0 = random(2, 12, 1);
22+
$c1 = -3 * $a * $b;
23+
$c2 = 3 * ($b - $a) / 2;
24+
$p1 = -$b - 1;
2925
$p2 = -$b + 2;
3026
$p3 = $a - 1;
3127
$p4 = $a + 1;
3228

29+
$f = Formula("x^3+$c2*x^2+$c1*x+$c0")->reduce();
3330

34-
TEXT(beginproblem());
35-
36-
$showPartialCorrectAnswers = 1;
37-
38-
TEXT(EV2(<<EOT));
39-
Find the
40-
absolute maximum and absolute minimum values of the function
41-
\[ f(x) = x^3 ? {$c2} x^2 ? {$c1} x + $c0 \]
42-
on each of the indicated intervals.
43-
$BR
44-
Enter -1000 for any absolute extrema that does not exist.
45-
$BR
46-
$BR
47-
(A) Interval = \([$p1, 0]\).
48-
$BR
49-
Absolute maximum = \{ans_rule(10)\}
50-
$BR
51-
$BR
52-
Absolute minimum = \{ans_rule(10)\}
53-
54-
$BR
55-
EOT
56-
57-
$ans1 = -($b**3) + $c2*$b**2 - $c1*$b + $c0;
58-
if ($p1**3 + $c2*$p1**2 + $c1*$p1 < 0)
59-
{
60-
$ans2 = $p1**3 + $c2*$p1**2 + $c1*$p1 + $c0;
61-
}
62-
else
63-
{
31+
$ans1 = -($b**3) + $c2 * $b**2 - $c1 * $b + $c0;
32+
if ($p1**3 + $c2 * $p1**2 + $c1 * $p1 < 0) {
33+
$ans2 = $p1**3 + $c2 * $p1**2 + $c1 * $p1 + $c0;
34+
} else {
6435
$ans2 = $c0;
6536
}
66-
@answers = (num_cmp($ans1), num_cmp($ans2));
67-
68-
ANS(@answers);
69-
70-
TEXT(EV2(<<EOT));
71-
$BR
72-
(B) Interval = \([$p2, $p4]\).
73-
$BR
74-
Absolute maximum = \{ans_rule(10)\}
75-
$BR
76-
$BR
77-
Absolute minimum = \{ans_rule(10)\}
78-
79-
$BR
80-
EOT
8137

82-
if ($p2**3 + $c2*$p2**2 + $c1*$p2 < $p4**3 + $c2*$p4**2 + $c1*$p4)
83-
{
84-
$ans1 = $p4**3 + $c2*$p4**2 + $c1*$p4 + $c0;
38+
if ($p2**3 + $c2 * $p2**2 + $c1 * $p2 < $p4**3 + $c2 * $p4**2 + $c1 * $p4) {
39+
$ans3 = $p4**3 + $c2 * $p4**2 + $c1 * $p4 + $c0;
40+
} else {
41+
$ans3 = $p2**3 + $c2 * $p2**2 + $c1 * $p2 + $c0;
8542
}
86-
else
87-
{
88-
$ans1 = $p2**3 + $c2*$p2**2 + $c1*$p2 + $c0;
89-
}
90-
$ans2 = ($a**3) + $c2*$a**2 + $c1*$a + $c0;
91-
92-
@answers = (num_cmp($ans1), num_cmp($ans2));
93-
94-
ANS(@answers);
95-
96-
TEXT(EV2(<<EOT));
97-
$BR
98-
(C) Interval = \([$p1, $p4]\).
99-
$BR
100-
Absolute maximum = \{ans_rule(10)\}
101-
$BR
102-
$BR
103-
Absolute minimum = \{ans_rule(10)\}
43+
$ans4 = ($a**3) + $c2 * $a**2 + $c1 * $a + $c0;
10444

105-
$BR
106-
EOT
107-
108-
if ($p4**3 + $c2*$p4**2 + $c1*$p4 < (-$b)**3 + $c2*$b**2 - $c1*$b)
109-
{
110-
$ans1 = (-$b)**3 + $c2*$b**2 - $c1*$b + $c0;
111-
}
112-
else
113-
{
114-
$ans1 = $p4**3 + $c2*$p4**2 + $c1*$p4 + $c0;
45+
if ($p4**3 + $c2 * $p4**2 + $c1 * $p4 < (-$b)**3 + $c2 * $b**2 - $c1 * $b) {
46+
$ans5 = (-$b)**3 + $c2 * $b**2 - $c1 * $b + $c0;
47+
} else {
48+
$ans5 = $p4**3 + $c2 * $p4**2 + $c1 * $p4 + $c0;
11549
}
116-
if ($p1**3 + $c2*$p1**2 + $c1*$p1 > ($a)**3 + $c2*$a**2 + $c1*$a)
117-
{
118-
$ans2 = ($a)**3 + $c2*$a**2 + $c1*$a + $c0;
119-
}
120-
else
121-
{
122-
$ans2 = $p1**3 + $c2*$p1**2 + $c1*$p1 + $c0;
50+
if ($p1**3 + $c2 * $p1**2 + $c1 * $p1 > ($a)**3 + $c2 * $a**2 + $c1 * $a) {
51+
$ans6 = ($a)**3 + $c2 * $a**2 + $c1 * $a + $c0;
52+
} else {
53+
$ans6 = $p1**3 + $c2 * $p1**2 + $c1 * $p1 + $c0;
12354
}
12455

125-
@answers = (num_cmp($ans1), num_cmp($ans2));
56+
BEGIN_PGML
57+
Find the absolute maximum and absolute minimum values of the function
58+
[``` f(x) = [$f] ```]
59+
on each of the indicated intervals.
12660

127-
ANS(@answers);
61+
Enter 'DNE' for any absolute extremum that does not exist.
62+
63+
a) The interval [`[[$p1],0]`]
64+
* Absolute maximum = [_]{$ans1}{5}
65+
* Absolute minimum = [_]{$ans2}{5}
66+
b) The interval [`[[$p2],[$p4]]`]
67+
* Absolute maximum = [_]{$ans3}{5}
68+
* Absolute minimum = [_]{$ans4}{5}
69+
c) The interval [`[[$p1],[$p4]]`]
70+
* Absolute maximum = [_]{$ans5}{5}
71+
* Absolute minimum = [_]{$ans6}{5}
72+
END_PGML
12873

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

0 commit comments

Comments
 (0)