WeBWorK Problems

Using the form of " ? {$var}" for plus minus displays results in exponential notation for values greater than 1000?

Using the form of " ? {$var}" for plus minus displays results in exponential notation for values greater than 1000?

by tim Payer -
Number of replies: 1

I am writing solutions for some problems and am using the form of "? {$var}" for a given value within BEGIN_SOLUTION.

I like the form of inserting a question mark "?" before the variable as it anticipates whether the sign of a value is positive or negative, However it has the troubling aspect of displaying values that are larger than 1000 in scientific notation:

That is 1250 is rendered as "1.25e + 03"
or worse 1320x is rendered as "1.32e + 03x"

These type of displays are confusing for the student when reading the step by step solutions. Is there a way to turn off the exponential display for values displayed in BEGIN_SOLUTION? I am assuming I can avoid converting it all to BEGIN_PGML_SOLUTION.

See Line 154 in the code below if you would like to see a reference.

## Calculus: Volumes by Cylindrical Shells

## Tagged by XW

## DBsubject(Calculus - single variable)
## DBchapter(Applications of integration)
## DBsection(Volumes by disks)
## Date(6/5/2005)
## Institution(UVA)
## Author(Jeff Holt)
## Level(4)
## TitleText1('Calculus: Early Transcendentals')
## AuthorText1('Stewart')
## EditionText1('5')
## Section1('6.3')
## Problem1('35')
## TitleText2('Calculus: Early Transcendentals')
## AuthorText2('Stewart')
## EditionText2('6')
## Section2('6.3')
## Problem2('')
## TitleText3('Calculus: Early Transcendentals')
## AuthorText3('Rogawski')
## EditionText3('1')
## Section3('6.4')
## Problem3('9')
## KEYWORDS('calculus', 'integrals', 'volumes', 'cylindrical shells')
## Library/UVA-Stew5e/setUVA-Stew5e-C06S03-VolumesShells/6-3-35

DOCUMENT(); # This should be the first executable line in the problem.


#Context()->{format}{number} = "%.8g";
$showPartialCorrectAnswers = 1;

$a=random(-8, 8,1);
$p1 =$p*(-1);
$s1 = $s*(-1);
$sp1 =$s1*$p1;
#$sp1 =sprintf("%0.0f",$sp);
$ss = $s1*$s1;
$pp =$p1*$p1;
$sps = $s*2;
$ppss = $ss +$p*2;
$sp2 = $sp1*2;
$soln = $PI*(-$a**5/30+$a**4 * $b/6 -$a**3 * $b**2/3 + $a**2 * $b**3/3 -$a*$b**4/6+$b**5/30);
$int1 = ($a +$b)/2;
$ch =floor($int1);
if ($ch == $a)
$int =$int1;
} else {
$int = $ch;
$ii = $int**2;
$b1 =$s*$int;
$ef1 = $ii +$b1+$p;
$aa5 = $a**5;
$aa4 = $a**4;
$aa3 = $a**3;
$aa2 = $a**2;
$bb5 = $b**5;
$bb4 = $b**4;
$bb3 = $b**3;
$bb2 = $b**2;
$cc5 = $bb5 -$aa5;
$cc4 = $bb4 -$aa4;
$cc3 = $bb3 -$aa3;
$cc2 = $bb2 -$aa2;
$cc1 = $b -$a;
$n4 = $cc4*$sps;
$n3 = $cc3*$ppss;
$n2 = $cc2*$sp2;
$n1 = $cc1*$pp;
$m5 = $cc5*12;
$m4 = $n4*15;
$m3 = $n3*20;
$m2 = $n2*30;
$m1 = $n1*60;
$nm = $m1+$m2+$m3+$m4+$m5;
$gc = gcd($nm,60);
if ($gc == 1)
$nm1 = $nm;
$nd1 = 60;
$anj1 = $nm*pi/60;
} else {
$nm1 = $nm/$gc;
$nd1 = 60/$gc;
$anj1 = $nm*pi/60;
$anj2 = sprintf("%0.3f",$anj1);

Find the volume of the solid obtained by rotating the function bounded by the
given curve about the \(x\)-axis.
\[ f(x) =x^2 ? {$s} x ? {$p} \]

Volume = \{ans_rule( 25) \}

To find the volume of the solid that results from a rotation of \(f(x) =x^2 ? {$s} x ? {$p} \) about the \(x\)-axis we must find first find the points of intersection of the function to determine the limits of integration. Then integrate for the square of the function times \(\pi \) over the limits of intersection by applying the general from for the calculation of a solid: $BR
Volume = \( \displaystyle{ \pi \int_{\text{lower bound}}^{\text{ upper bound}} \left( f(x) \right)^2 \, dx} \) $BR
x^2 ? {$s} x ? {$p} & = 0 && \text{Set the function equal to zero and solve for }x.\\
(x -$a)(x - $b) & = 0 && \text{Factor the trinomial. }\\
Then the function \(f(x)\) intersects the \(x\) axis at \( x = $a \) and \( x = $b \).
Accordingly the volume of the bounded region can be found by integrating over the limits of integration: $BR
\(\displaystyle{ Volume = \pi \int_{$a}^{$b} \left( f(x) \right)^2 \, dx}\) $BR
Substitute the functions of \(f(x) \) into the volume equation: $BR
\(\displaystyle{ Volume = \pi \int_{$a}^{$b} \left( \left(x^2 ? {$s} x ? {$p} \right) \right)^2 \, dx}\) $BR
Square the quantity: $BR
\(\displaystyle{ Volume = \pi \int_{$a}^{$b} \left( x^2 ? {$s} x ? {$p} \right) \left( x^2 ? {$s} x ? {$p} \right)\, dx}\) $BR
\(\displaystyle{ Volume = \pi \int_{$a}^{$b} \left( x^4 ? {$s} x^3 ? {$p} x^2 ? {$s} x^3 ? {$ss} x^2 ? {$sp1} x ? {$p} x^2 ? {$sp1} x + {$pp}\right) \, dx}\) $BR
Collect like terms: $BR
\(\displaystyle{ Volume = \pi \int_{$a}^{$b} \left( x^4 ? {$sps} x^3 ? {$ppss} x^2 ? {$sp2}x + {$pp}\right) \, dx}\) $BR

Integrate term by term: $BR
\(\displaystyle{ Volume = \pi \left[ \frac{1}{5} x^5 +\frac{$sps}{4} x^4 +\frac{$ppss}{3} x^3 + \frac{$sp2}{2} x^2 + {$pp} x \right] \Big|_{$a}^{$b} }\) $BR
Evaluate term by term: $BR
\(\displaystyle{ Volume = \pi \left[ \frac{1}{5} \left($b^5-$a^5\right) +\frac{$sps}{4} \left($b^4 - $a^4\right) +\frac{$ppss}{3} \left($b^3 - $a^3\right) + \frac{$sp2}{2} \left($b^2 - $a^2\right) + {$pp} ($b - $a) \right] }\) $BR
Raise each base to its respective power: $BR
\(\displaystyle{ Volume = \pi \left[ \frac{1}{5} \left($bb5-$aa5\right) +\frac{$sps}{4} \left($bb4 - $aa4\right) +\frac{$ppss}{3} \left($bb3 - $aa3\right) + \frac{$sp2}{2} \left($bb2 - $aa2\right) + {$pp} ($b - $a) \right] }\) $BR
Gather terms for each quantity: $BR
\(\displaystyle{ Volume = \pi \left[ \frac{1}{5} \left($cc5\right) +\frac{$sps}{4} \left($cc4\right) +\frac{$ppss}{3} \left($cc3\right) + \frac{$sp2}{2} \left($cc2\right) + {$pp} ($cc1) \right] }\) $BR
Form single fractions: $BR
\(\displaystyle{ Volume = \pi \left[ \frac{$cc5}{5} +\frac{$n4}{4} +\frac{$n3}{3} + \frac{$n2}{2} + $n1 \right] }\)
Form common denominators: $BR
\(\displaystyle{ Volume = \pi \left[ \frac{$cc5}{5} \cdot \frac{12}{12} +\frac{$n4}{4} \cdot \frac{15}{15}+\frac{$n3}{3} \cdot \frac{20}{20} + \frac{$n2}{2} \cdot \frac{30}{30} + $n1 \cdot \frac{60}{60} \right] }\) $BR
Combine fraction factors: $BR
\(\displaystyle{ Volume = \pi \left[ \frac{$m5}{60} +\frac{$m4}{60} +\frac{$m3}{60} + \frac{$m2}{60} +\frac{$m1}{60} \right] }\) $BR
Combine into one fraction: $BR
\(\displaystyle{ Volume = \pi \left[ \frac{$m5 +$m4 +$m3+$m2+$m1}{60} \right] }\) $BR
Simplify the numerator: $BR
\(\displaystyle{ Volume = \pi \left[ \frac{$nm}{60} \right] }\) $BR
Reduce the fraction: $BR
\(\displaystyle{ Volume = \frac{$nm1 \pi}{$nd1} }\) cubic units $BR
\(\displaystyle{ Volume \approx $anj2 }\) cubic units. $BR

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

In reply to tim Payer

Re: Using the form of " ? {$var}" for plus minus displays results in exponential notation for values greater than 1000?

by tim Payer -

I think that converting to the form of BEGIN_PGML_SOLUTION is the best solution for all concerned in regards to errors of sign changes and random scientific notation displays.