WeBWorK Problems

Inserting Latex code for Radio pull down answers.

Re: Inserting Latex code for Radio pull down answers.

by tim Payer -
Number of replies: 0
Hello Again,

I have tried your suggestion of using unicode characters instead of Latex code in
PopUp( ) answers, But I am running into some big problems.

Either my execution is wrong or perhaps version 10 does not handle unicode very well?

Any pointers would be much appreciated.

The block of code is below and the errors are removed if I take the unicode characters out.

# DESCRIPTION  11
# Probability
# WeBWorK problem written by Tim payer, <tsp1@humboldt.edu>
# ENDDESCRIPTION

## DBsubject(Probability)
## DBchapter(??)
## DBsection(??)
## Institution(Humboldt State University)
## Author(Tim Payer)
## KEYWORDS(probability, addition, notation)

DOCUMENT();
loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"PGML.pl",
"parserFormulaUpToConstant.pl",
"niceTables.pl",
"PGunion.pl",
"parserPopUp.pl",
);

Context("Numeric");
Context()->flags->set(
  tolerance => 0.0001,
  tolType => "absolute",
);


# \{row("Income $", @z)\}

# Table data generation:
# To switch off the algorithmic table data un-comment the following 5 lines:
# and then Comment (#) the random assignments.
# $r[4] = 12;
# $u[4] = 150;
# $m[4] = 200;
# $l[1] = 200;
# $p[1] = 50;
$r[4] = random(12, 18,1);
$r[3] = $r[4] + 50;
$r[2] = $r[4]*10 + 6;
$r[1] = $r[4]*30 - 7;
$r[0] = $r[4]*55 + 22;
$rsum = $r[4]+$r[3]+$r[2]+$r[1]+$r[0];

$u[4] = random(121, 161,1);
$u[3] = $u[4] + 121;
$u[2] = $u[4]*4 + 6;
$u[1] = $u[4]*17 - 7;
$u[0] = $u[4]*5 + 22;
$usum = $u[4]+$u[3]+$u[2]+$u[1]+$u[0];

$m[4] = random(191, 211,1);
$m[3] = $m[4]*4 + 22;
$m[2] = $m[4]*10 + 17;
$m[1] = $m[4]*6 - 24;
$m[0] = $m[4]*2 + 51;
$msum = $m[4]+$m[3]+$m[2]+$m[1]+$m[0];

$l[0] = random(181, 213,2);
$l[1] = $l[0]*2 + 89;
$l[2] = $l[0]*3 + 17;
$l[3] = $l[0]*10 + 24;
$l[4] = $l[0]*3 + 51;
$lsum = $l[4]+$l[3]+$l[2]+$l[1]+$l[0];

$p[0] = random(41, 58,1);
$p[1] = $p[0] + 22;
$p[2] = $p[0]*2 + 17;
$p[3] = $p[0]*3 - 15;
$p[4] = $p[0]*6 + 51;
$psum = $p[4]+$p[3]+$p[2]+$p[1]+$p[0];

# Column sums:
$c0 = $p[0]+$l[0]+$m[0]+$u[0]+$r[0];
$c1 = $p[1]+$l[1]+$m[1]+$u[1]+$r[1];
$c2 = $p[2]+$l[2]+$m[2]+$u[2]+$r[2];
$c3 = $p[3]+$l[3]+$m[3]+$u[3]+$r[3];
$c4 = $p[4]+$l[4]+$m[4]+$u[4]+$r[4];
$grand = $c0+$c1+$c2+$c3+$c4 +$psum+$lsum+$msum+$usum+$rsum;

$popup1 = PopUp(
["probability notation", "P(86-88)", "P(A)", "P(B)", "P(C)", "P(D)","P(E)"], "P(B)");
$ans1 =$c1/$grand;

$popup2 = PopUp(
["probability notation", "P(B U F)", "P(BF)", "P(B ~~x{2229} F)", "P(B + F)", "P(B x F)"], "P(B ~~x{2229} F)");
$ans2 =$p[1]/$grand;

# Apparently the unicode wont work here?  "~~x{2229}" wont render

BEGIN_TEXT 

$PAR
4.2)  Recent census data has correlated life expectancy with one's income bracket. $BR
Given a small town of \($grand\) individuals, that is loosely based upon the US census data, determine the following probabilities using correct probability notation. Answer with fourth decimal accuracy and use the event variables declared below:
$PAR
Where:  $BR
$PAR

$BLEFT
\{ begintable(7) \}
\{ row( "Life Expectancy", "89-95", "86-88", "81-85","77-80","74-76" ,"Row Sums") \}
\{ row( "Rich:", $r[0], $r[1],$r[2], $r[3], $r[4], $rsum ) \}
\{ row( "Upper Middle Class", $u[0], $u[1],$u[2], $u[3], $u[4], $usum) \}
\{ row( "Middle Class", $m[0], $m[1],$m[2], $m[3], $m[4], $msum) \}
\{ row( "Lower Middle Class", $l[0], $l[1],$l[2], $l[3], $l[4], $lsum) \}
\{ row( "Poor", $p[0], $p[1],$p[2], $p[3], $p[4], $psum) \}
\{ row( "Column Sums:", $c0, $c1,$c2, $c3, $c4, $grand) \}
\{ endtable() \}
$ELEFT


$PAR
\(A \) = Event that an individual has a life expectancy of 89 - 95 years. $BR
\(B \) = Event that an individual has a life expectancy of 86 - 88 years. $BR
\(C \) = Event that an individual has a life expectancy of 81 - 85 years. $BR
\(D \) = Event that an individual has a life expectancy of 77 - 80 years. $BR
\(E \) = Event that an individual has a life expectancy of 75 - 76 years. $BR
\(R \) = Event that an individual is rich. $BR
\(S \) = Event that an individual of the upper middle class $BR
\(M \) = Event that an individual is of the middle class. $BR
\(L \) = Event that an individual is of the lower middle class.$BR
\(F \) = Event that an individual is poor. $BR
END_TEXT


BEGIN_PGML

4.2a)  Find the probability of drawing an individual from the town that has a life expectancy of 86-88 years:  

[_____]{$popup1} = [______]{$ans1}

4.2b)  Find the probability of drawing an individual from the town that has a life expectancy of 86-88 years and is poor:  

[_____]{$popup2} = [______]{$ans2}


END_PGML

BEGIN_PGML_SOLUTION
*SOLUTION*
To simplify the expression to a single term with a rational denominator we first start by splitting the root between the numerator and denominator. Then find a common denominator and rationalize the denominator. 
 
[``\begin{aligned}&\\  
[$c]-\sqrt{\frac{[$am] x}{[$bm]}} &=[$c] -\sqrt{\frac{[$m]\cdot[$a] x}{[$m]\cdot[$b]}} = [$c]  -\frac{\sqrt{[$a] x}}{\sqrt{[$b]}}
&& \text{Cancel the common factor and then split the root.}\\    
&=\frac{[$c]\sqrt{[$b]}}{ \sqrt{[$b]}}-\frac{\sqrt{[$a] x}}{\sqrt{[$b]}} && \text{Create a common denominator.}\\  
&=\frac{[$c]\sqrt{[$b]} -\sqrt{[$a] x}}{\sqrt{[$b]}} && \text{Combine in to a single fraction.}\\    
&=\frac{\left([$c]\sqrt{[$b]} -\sqrt{[$a] x}\right)\sqrt{[$b]}}{\sqrt{[$b]}\cdot\sqrt{[$b]}} && \text{Multiply the numerator and denominator by the denominator.}\\  
&=\frac{\left([$c]\sqrt{[$b]\cdot [$b]}-\sqrt{[$a] \cdot [$b] x}\right)}{[$b]} && \text{Distribute through the numerator and reduce the denominator.}\\  
&=\frac{\left([$c] \cdot [$b] -\sqrt{[$ab] x}\right)}{[$b]} && \text{Reduce the square root factors.}\\  
&=\frac{[$cb] - \sqrt{[$ab] x}}{[$b]} && \text{Combine numerator factors.}  
\end{aligned}``]  


END_PGML_SOLUTION

ENDDOCUMENT();