Skip to content

Commit 573adf9

Browse files
committed
Fix bug 4674
1 parent 731cf03 commit 573adf9

File tree

1 file changed

+36
-57
lines changed

1 file changed

+36
-57
lines changed

OpenProblemLibrary/274/Exact/prob5.pg

Lines changed: 36 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,14 @@ loadMacros(
2020
"PGcourse.pl"
2121
);
2222

23+
Context("Numeric");
2324
Context()->variables->add(y=>"Real");
2425

2526
TEXT(beginproblem()) ;
2627
$showPartialCorrectAnswers = 1;
2728

28-
$a= non_zero_random(-4,4,1);
2929
do {$b= non_zero_random(-4,4,1);} until ($b!=-1);
30-
$z = random (1,3);
31-
$k = non_zero_random(-4,4,1);
32-
$c = non_zero_random(-4,4,1);
33-
$d = non_zero_random(-4,4,1);
30+
3431
$n = random(1,6,1);
3532
$n1=$n+1;
3633
do {$m = random(2,6,1);} until ($m!=$n);
@@ -39,81 +36,63 @@ $p = $m1-$n1;
3936
$p1 = $p + 1;
4037
if ($n1-$m1==1) {
4138
$Fxy = Compute("-ln(y)+x/y^$n+$b x");
42-
$r1 = [0,1];
43-
$r2 = [2,5];
4439
} else {
4540
$Fxy = Compute("-y^$p1/$p1+x/y^$n+$b x");
46-
$r1 = [1/$p1/($b+1),1];
47-
$r2 = [20, 3.141592653589793238];
4841
}
4942

50-
$M=Compute("y + $b y^$n1");
51-
$N=Compute("-y^{$m1}-$n x");
43+
$M=Compute("y + $b y^$n1")->reduce;
44+
$minusN = Compute("y^{$m1}+$n x");
45+
$N=-$minusN;
5246

53-
$multians = MultiAnswer($M, $N)->with(
47+
$multians = MultiAnswer($M, $N, $Fxy)->with(
5448
singleResult => 0,
49+
allowBlankAnswers=>1,
50+
checkTypes=>0,
5551
checker => sub {
5652
my ( $correct, $student, $self ) = @_;
57-
my ( $Mstu, $Nstu ) = @{$student};
58-
my ( $M, $N) = @{$correct};
59-
if ( ($M == $Mstu && $N == $Nstu) ||
60-
($M == -$Mstu && $N == -$Nstu) ) {
61-
return [1,1];
62-
} else {
63-
if ($M == $Mstu || $M == -$Mstu) {
64-
return [1,0];
65-
} elsif ($N == $Nstu || $N == -$Nstu) {
66-
return [0,1];
67-
} else {
68-
return [0,0];
69-
}
53+
my ( $Mstu, $Nstu, $Fxystu ) = @{$student};
54+
my ( $M, $N, $Fxycorrect) = @{$correct};
55+
my @score = (0,0,0);
56+
my $mult = Compute("y^$n1");
57+
# check types and values of first two inputs
58+
if ( $M->typeMatch($Mstu) && $N->typeMatch($Nstu) ){
59+
# check values of first two inputs
60+
if ( ($Mstu != Formula(0) || $Nstu != Formula(0)) && $Mstu*$N - $Nstu*$M == Formula(0) ) {
61+
$score[0] = $score[1] = 1;
62+
}
63+
}
64+
else { return [0,0,0]; }
65+
# check type and value of third input
66+
if ( $score[0]==1 && $score[1]==1 && $Fxycorrect->typeMatch($Fxystu) ) {
67+
my $DFx = $Fxystu->D('x');
68+
my $DFy = $Fxystu->D('y');
69+
if ( ($DFx != Formula(0) || $DFy != Formula(0)) && $DFx*$N - $DFy*$M == Formula(0) ){
70+
$score[2]=1;
71+
}
7072
}
73+
return [@score];
7174
}
7275
);
7376

74-
$lpol = nicestring([$b], ["y^${n1}"]);
75-
$rpol = nicestring([$n], ["x"]);
76-
77+
Context()->texStrings;
7778
BEGIN_TEXT
7879

7980
The differential equation
80-
\[ y + $lpol = \left(y^${m1} + $rpol\right)y' \]
81+
\[ $M = \left($minusN \right)y' \]
8182
can be written in differential form:
8283
\[ M(x,y) \, dx + N(x,y) \, dy = 0 \]
8384
where $BR
84-
\(M(x,y)= \) \{$multians->ans_rule(30)\} , and
85-
\(N(x,y)= \) \{$multians->ans_rule(30)\}.
85+
\(M(x,y)= \) \{$multians->ans_rule(30)\} , and $BR
86+
\(N(x,y)= \) \{$multians->ans_rule(30)\}. (To receive credit both answers must be correct.)
8687
$PAR
87-
The term \(M(x,y) \, dx + N(x,y) \, dy\) becomes an exact differential if the left hand side above is divided by \( y^${n1}\). Integrating that new equation, the solution of the differential equation is
88-
\{ ans_rule(45) \} \(= C \).
88+
The term \(M(x,y) \, dx + N(x,y) \, dy\) becomes an exact differential if the left hand side above is divided by \( y^${n1}\). Integrating that new equation we obtain a solution of the differential equation:
89+
\{ $multians->ans_rule(45) \} \(= C \).
8990

9091
END_TEXT
91-
92-
# Can input a root, which defaults to [0,0], and another point
93-
# which defaults to [2,1]
94-
sub lcc {
95-
my ( $correct, $student, $anshash) = @_;
96-
my %ah = %{ $anshash };
97-
my $root = $ah{root};
98-
$root = [0,0] unless defined($root);
99-
my $other = $ah{other};
100-
$other = [2,1] unless defined($other);
101-
my $const = $student->eval(x=>$root->[0], y=>$root->[1]);
102-
$student = $student-$const;
103-
if($student== 0) {
104-
Value::Error("The function cannot be constant");
105-
return 0;
106-
}
107-
my $c1 = $student->eval(x=>$other->[0], y=>$other->[1])/
108-
$correct->eval(x=>$other->[0], y=>$other->[1]);
109-
return 0 if $c1 == 0;
110-
$student = $student/$c1;
111-
return $correct == $student;
112-
}
92+
Context()->normalStrings;
11393

11494

115-
ANS( $multians->cmp() );
116-
ANS( $Fxy->cmp(checker =>~~&lcc, root=> $r1, other=>$r2));
95+
ANS( $multians->cmp(limits => [[-2,2],[.1,10]]) );
11796

11897

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

0 commit comments

Comments
 (0)