WeBWorK Problems

Can't find the bug in this Problem

Can't find the bug in this Problem

by Tim Alderson -
Number of replies: 0
The following was from the OPL. It chokes with seed 1481.

I believe it is related to the constant term $prime_e, but can't see where a division by zero may be occurring (or something along those lines).

Any help in patching this would be appreciated.

## DBsubject(Calculus - single variable)
## DBchapter(Integrals)
## DBsection(Antiderivatives (without trigonometric functions))
## Institution(W.H.Freeman)
## Author(Brian Kell)
## MLT(antideriv_poly_second_order_init_vals)
## Level(3)
## MO(1)
## TitleText1('Calculus: Early Transcendentals')
## AuthorText1('Rogawski')
## EditionText1('2')
## Section1('4.9')
## Problem1('66')
## KEYWORDS('calculus', 'antiderivatives')

DOCUMENT();
loadMacros("PG.pl","PGbasicmacros.pl","PGanswermacros.pl");
loadMacros("Parser.pl");
loadMacros("freemanMacros.pl");

Context()->flags->set(reduceConstants => 0);

$a = non_zero_random(-10,10);
$b = random(-10,10);
$c = random(-10,10);
$d = random(-10,10);

$p = random(-10,10);
$q = random(-10,10);

# the following simplifies things, because reducing formulas with $f->reduce
# doesn't work very well when the coefficients are fractions
$prime_a = bkell_poly_term($a, 4, "x^4");
$prime_b = bkell_poly_term($b, 3, "x^3", "+");
$prime_c = bkell_poly_term($c, 2, "x^2", "+");
$prime_d = bkell_poly_term($d, 1, "x", "+");
$func_a = bkell_poly_term($a, 20, "x^5");
$func_b = bkell_poly_term($b, 12, "x^4", "+");
$func_c = bkell_poly_term($c, 6, "x^3", "+");
$func_d = bkell_poly_term($d, 2, "x^2", "+");
$func_e = bkell_poly_term(12*$p - 3*$a - 4*$b - 6*$c - 12*$d, 12, "x", "+");
($prime_e = $func_e) =~ s/x//;
$func_f = bkell_poly_term(60*$q + 12*$a + 15*$b + 20*$c + 30*$d - 60*$p, 60, "", "+");

$doubleprime = Formula("${a}x^3+${b}x^2+${c}x+${d}")->reduce;
$prime = Formula("$prime_a$prime_b$prime_c$prime_d$prime_e" || "0");
$func = Formula("$func_a$func_b$func_c$func_d$func_e$func_f" || "0");

Context()->texStrings;
BEGIN_TEXT
\{ beginproblem() \}
\{ textbook_ref_exact("Rogawski ET 2e", "4.9", "66") \}
$PAR
First find \( f' \) and then find \( f \).
$PAR
\( f''(x)=$doubleprime\),
$PAR
\( f'(1)=$p\),
$PAR
\(f(1)=$q\).
$PAR
\( f'(x) = \) \{ans_rule()\}
$PAR
\( f(x) = \) \{ans_rule()\}
END_TEXT
Context()->normalStrings;

ANS($prime->cmp);
ANS($func->cmp);

$g = Formula("$prime_a$prime_b$prime_c$prime_d" || "0");
$g_no_x = bkell_simplify_fraction_string($a, 4, "0").
bkell_simplify_fraction_string($b, 3, "+0").
bkell_simplify_fraction_string($c, 2, "+0").
bkell_simplify_fraction_string($d, 1, "+0");
$g_no_x =~ s/^~~+//;
$g_zero = Formula($g_no_x);

($prime_e_noplus = $prime_e) =~ s/~~+//;
$c1 = Formula($prime_e_noplus);
$plus_c1 = bkell_simplify_fraction_string(12*$p-3*$a-4*$b-6*$c-12*$d, 12, "f+0");

$f1_coeff_x5 = bkell_simplify_fraction_string($a, 4, "f1");
if ($f1_coeff_x5 eq "" || $f1_coeff_x5 eq "-") {
$f1_term_x5 = $f1_coeff_x5."{1\over5}x^5";
} elsif ($f1_coeff_x5 eq "0") {
$f1_term_x5 = "";
} else {
$f1_term_x5 = $f1_coeff_x5."\left({1\over5}x^5\right)";
}

$f1_coeff_x4 = bkell_simplify_fraction_string($b, 3, "f+1");
if ($f1_coeff_x4 eq "" || $f1_coeff_x4 eq "+" || $f1_coeff_x4 eq "-") {
$f1_term_x4 = $f1_coeff_x4."{1\over4}x^4";
} elsif ($f1_coeff_x4 eq "0") {
$f1_term_x4 = "";
} else {
$f1_term_x4 = $f1_coeff_x4."\left({1\over4}x^4\right)";
}

$f1_coeff_x3 = bkell_simplify_fraction_string($c, 2, "f+1");
if ($f1_coeff_x3 eq "" || $f1_coeff_x3 eq "+" || $f1_coeff_x3 eq "-") {
$f1_term_x3 = $f1_coeff_x3."{1\over3}x^3";
} elsif ($f1_coeff_x3 eq "0") {
$f1_term_x3 = "";
} else {
$f1_term_x3 = $f1_coeff_x3."\left({1\over3}x^3\right)";
}

$f1_coeff_x2 = bkell_simplify_fraction_string($d, 1, "f+1");
if ($f1_coeff_x2 eq "" || $f1_coeff_x2 eq "+" || $f1_coeff_x2 eq "-") {
$f1_term_x2 = $f1_coeff_x2."{1\over2}x^2";
} elsif ($f1_coeff_x2 eq "0") {
$f1_term_x2 = "";
} else {
$f1_term_x2 = $f1_coeff_x2."\left({1\over2}x^2\right)";
}

$f1_coeff_x = bkell_simplify_fraction_string(12*$p-3*$a-4*$b-6*$c-12*$d, 12, "f+1");
if ($f1_coeff_x eq "0") {
$f1_term_x = "";
} else {
$f1_term_x = $f1_coeff_x."x";
}

$f1 = $f1_term_x5.$f1_term_x4.$f1_term_x3.$f1_term_x2.$f1_term_x;
$f1 =~ s/^~~+//;
$f1 ||= "0";

$eff = bkell_poly_term($a, 20, "x^5").bkell_poly_term($b, 12, "x^4", "+").
bkell_poly_term($c, 6, "x^3", "+").bkell_poly_term($d, 2, "x^2", "+").
bkell_poly_term(12*$p-3*$a-4*$b-6*$c-12*$d, 12, "x", "+");
$f = Formula($eff);

$f_no_x = bkell_simplify_fraction_string($a, 20, "0").
bkell_simplify_fraction_string($b, 12, "0+").
bkell_simplify_fraction_string($c, 6, "0+").
bkell_simplify_fraction_string($d, 2, "0+").
bkell_simplify_fraction_string(12*$p-3*$a-4*$b-6*$c-12*$d, 12, "0+");
$f_no_x =~ s/^~~+//;
$f_zero = Formula($f_no_x);

($func_f_noplus = $func_f) =~ s/~~+//;
$c2 = Formula($func_f_noplus);
$plus_c2 = bkell_simplify_fraction_string(60*$q+12*$a+15*$b+20*$c+30*$d-60*$p, 60, "f+0");

Context()->texStrings;
SOLUTION(EV3(<<'END_SOLUTION'));
$PAR
$SOL
Let \(g(x)=f'(x)\). The problem statement gives us \(g'(x)=$doubleprime\),
\(g(1)=$p\). From \(g'(x)\), we get \(g(x)=$g+C\), and from \(g(1)=$p\), we get
\($p=$g_zero + C\), so that \(C=$c1\). This gives \(f'(x)=g(x)=$g$plus_c1\).
From \(f'(x)\), we get
\[f(x)=$f1+C\]
$PAR
\[=$f+C.\]
From \(f(1)=$q\), we get
\[$f_zero+C=$q,\]
so that \(C=$c2\). Hence,
\[f(x)=$f$plus_c2.\]
END_SOLUTION

ENDDOCUMENT();