## 2017 Problem Authoring Workshop

### Negative variables when squared stay negative?

by tim Payer -
Number of replies: 3
Greetings once again.

I came across an error that was based on my assumption that when we square a negative variable that the negative is also squared but apparently this is not always the case? The only way I could get the negative to square to a positive was to enclose the variable in parentheses?

Given

$b = Real(-6); I would assume that$b**2 = 36, but no $b**2 = -36 .?? Then we must wrap negative variables in parentheses to find that: ($b)**2 = 36

The Interactive PGML Lab from our homework does not have this glitch but this homework does. Please see lines 71 and 73 in which the critical number calculation must have the negative variable $b = -8 wrapped within parentheses in order for the square power to square the negative value. Does this make sense? I might be missing something here? The Code block is below. Thanks for exploring this and letting me know of any misconstrue on my part. Tim ##DESCRIPTION ## Sign Analysis on a 3rd degree Polynomial #11 ##KEYWORDS('sign analysis') ## DBsubject('Precalculus') ## DBchapter('Rational equations and functions') ## DBsection('Asymptotes') ## Date('6/7/2017') ## Author('Tim Payer') # WeBWorK problem written by TimPayer <tsp1@humboldt.edu> # ENDDESCRIPTION DOCUMENT(); loadMacros( "PGstandard.pl", "PGunion.pl", "PGnumericalmacros.pl", "PGstatisticsmacros.pl", "MathObjects.pl", "parserPopUp.pl", "PGML.pl", "unionTables.pl", "niceTables.pl", "PGcourse.pl", "PGchoicemacros.pl", "answerHints.pl", "weightedGrader.pl" ); install_weighted_grader(); #Text(beginproblem()); #uncomment #install_problem_grader(~~&std_problem_grader);$showPartialCorrectAnswers = 1;

Context("Numeric");
Parser::Number::NoDecimals($context); # we want the exact value of critical numbers Context()->flags->set( tolerance => 0.01, tolType => "absolute", ); ############ Start Problem HW 1.8 ################# #$a = non_zero_random(-7,7);
#$c = non_zero_random(-7,7); # do {$b = non_zero_random(-13,13); } until ($b**2 > 3*$a*$c); ## forcing all real domain with 2 cp.$d = non_zero_random(-15,15);

### Testing negative values for a Square within a square root....
$a = Real(2);$b = Real(-8);
$c = Real(-6); ##$sa = Real(0); ## Horizontal Asymptote
$fp0 = Formula("$a*x**3 + $b*x**2 +$c*x + $d")->reduce; # f(x)$fp1 = Formula("3*$a*x**2 + 2*$b*x + $c")->reduce; # first derivative$fp2 = Formula("6*$a*x + 2*$b")->reduce; # second derivative

## f(x) has three critical numbers: A point of inflection at x = 0 will be stradled by
## by two critical points. The concavity will flip based on the sign of $a and$b.
## Accordingly an if-conditional will assign these values as
## critical numbers of $cn1,$cn2, $cn3. The student will have to determine in their sign ## analysis whether they are working with a critical point or a point of inflection. ## ##################################$cn1 = Compute("(-$b -sqrt($b**2 - 3*$a*$c))/(3*$a)"); ## And Yet ($b)**2 will work!
$cn2 = Compute("-$b/(3*$a)");$cn3 = Compute("(-$b + sqrt($b**2 - 3*$a*$c))/(3*$a)"); ## And Yet ($b)**2 will work!

if ( $a > 0 ) {$f1s = "inc";
$f2s = "dec";$f3s = "dec";
$f4s = "inc";$d1s = "+";
$d2s = "-";$d3s = "-";
$d4s = "+";$dd1s = "CD";
$dd2s = "CD";$dd3s = "CU";
$dd4s = "CU"; } else {$f1s = "dec";
$f2s = "inc";$f3s = "inc";
$f4s = "dec";$d1s = "-";
$d2s = "+";$d3s = "+";
$d4s = "-";$dd1s = "CU";
$dd2s = "CU";$dd3s = "CD";
$dd4s = "CD"; } #### Column Header: Critical number ID$cpop1 = PopUp(
["?", 'VA', 'cp', 'poi'], 'cp');

$cpop2 = PopUp( ["?", 'VA', 'cp', 'poi'], 'poi');$cpop3 = PopUp(
["?", 'VA', 'cp', 'poi'], 'cp');

### Row 2, f(x) is incresing or decreasing

$f1 = PopUp( ["?", 'inc', 'dec'],$f1s);
$f2 = PopUp( ["?", 'inc', 'dec'],$f2s);
$f3 = PopUp( ["?", 'inc', 'dec'],$f3s);
$f4 = PopUp( ["?", 'inc', 'dec'],$f4s);

### Row 3, f'(x) is positive or negative
$d1 = PopUp( ["?", '+', '-'],$d1s);
$d2 = PopUp( ["?", '+', '-'],$d2s);
$d3 = PopUp( ["?", '+', '-'],$d3s);
$d4 = PopUp( ["?", '+', '-'],$d4s);

### Row 4, f''(x) is positive with f(x) CU or f''(x) is negative with f(x) CD
$dd1 = PopUp( ["?", 'CU', 'CD'],$dd1s);

$dd2 = PopUp( ["?", 'CU', 'CD'],$dd2s);

$dd3 = PopUp( ["?", 'CU', 'CD'],$dd3s);

$dd4 = PopUp( ["?", 'CU', 'CD'],$dd4s);

#################### Begin Problem...#######################

BEGIN_PGML
*WeBWorK workshop 2017 HW 1.11)
A sign analysis for a third degree polynomial*

*HW 1.11)* Given the rational function [f(x) = [$fp0]], perform a sign analysis for the function and the first and second derivatives. Find all critical points, points of inflection, and asymptotes associated with the function. *1.11a)* Find the first derivative [f'(x)] = [_______]* *1.11b)* Find the second derivative [f''(x)] = [_______]* [@ DataTable( [ ["$BBOLD 1.11c) $EBOLD Complete the table below for a correct sign analysis display. Use the key at the right to enter the correct values for the function. Use ascending order to display the numerical value for each critical number. Indicate whether a given critical number is a critical point, a vertical asymptote or an inflection point."," ","VA = Vertical asymptote.$BR cp = Critical point. $BR poi = Point of inflection$BR inc = \$$f(x)\$$ is increasing. $BR dec = \$$f(x)\$$ is decreasing.$BR + = \$$f(x)\$$ is positive. $BR - = \$$f (x)\$$ is negative.$BR CU = \$$f^{\\prime \\prime}(x) > 0\$$ and \$$f(x)\$$ is concave up. BR CD = \$$f^{\\prime \\prime}(x) < 0\$$ and \$$f(x)\$$ is concave down." ], ], caption => " ", midrules=>1, align => "|p{3in} p{0.2in}|p{3in}|" ); @]*** [@ DataTable( [ ["","BeforeBR the first $BR critical$BR number:","The first $BR critical$BR number $BR is a:$BR".$cpop1->menu."","Before$BR the 2nd $BR critical$BR number:","The 2nd $BR critical$BR number $BR is a:$BR ".$cpop2->menu."","Before$BR the 3rd $BR critical$BR number:", "The 3rd $BR critical$BR number $BR is a:$BR".$cpop3->menu."", "After$BR the 3rd $BR critical$BR number:" ],
["\$$x =\$$","","".$cn1->ans_rule(2)."","","".$cn2->ans_rule(2)."", "", "".$cn3->ans_rule(2)."","" ], ["\$$f(x)\$$","".$f1->menu."","","".$f2->menu.""," ", "".$f3->menu."", " ","".$f4->menu."" ], ["\$$f^\\prime (x)\$$","".$d1->menu."","","".$d2->menu."","", "".$d3->menu."", "","".$d4->menu.""], ["\$$f^{\\prime \\prime} (x)\$$","".$dd1->menu."","","".$dd2->menu."","", "".$dd3->menu."", "","".dd4->menu."" ], ], caption => "Complete the Sign Analysis in the Table Below: ", midrules=>1, align => "|p{0.25in}|p{0.5in}|p{0.5in}|p{0.5in}|p{0.5in}|p{0.5in}|p{0.5in}|p{0.5in}|p{0.5in}|p{0.5in}|p{0.5in}|p{0.5in}|" ); @]*** END_PGML #Adapted weighted answers values: ## Asymptotes and derivatives ## WEIGHTED_ANS( (fp1)->cmp, 10 );
WEIGHTED_ANS( ($fp2)->cmp, 15 ); ## HW 1.10C Sign Analysis Table: ## ###Column Header: Critical number ID WEIGHTED_ANS( ($cpop1)->cmp, 3 );
WEIGHTED_ANS( ($cpop2)->cmp, 3 ); WEIGHTED_ANS( ($cpop3)->cmp, 3 );

###Row 1:

WEIGHTED_ANS( ($cn1)->cmp, 8 ); WEIGHTED_ANS( ($cn2)->cmp, 8 );
WEIGHTED_ANS( ($cn3)->cmp, 8 ); ###Row 2: WEIGHTED_ANS( ($f1)->cmp, 1 );
WEIGHTED_ANS( ($f2)->cmp, 1 ); WEIGHTED_ANS( ($f3)->cmp, 1 );
WEIGHTED_ANS( ($f4)->cmp, 1 ); ###Row 3: WEIGHTED_ANS( ($d1)->cmp, 1 );
WEIGHTED_ANS( ($d2)->cmp, 1 ); WEIGHTED_ANS( ($d3)->cmp, 1 );
WEIGHTED_ANS( ($d4)->cmp, 1 ); ###Row 4: WEIGHTED_ANS( ($dd1)->cmp, 1 );
WEIGHTED_ANS( ($dd2)->cmp, 1 ); WEIGHTED_ANS( ($dd3)->cmp, 1 );
WEIGHTED_ANS( ($dd4)->cmp, 1 ); ########################################## BEGIN_PGML_SOLUTION a = [$a]
b = [$b] c = [$c]

END_PGML_SOLUTION

ENDDOCUMENT();

### Re: Negative variables when squared stay negative?

by tim Payer -
I think I understand my problem to my Question about negative values inside a square root.

The key point is that when a variable is declared with a "Compute" command, it converts the value to a math object for which a negative value is attached but separate from the variable that it makes negative? That is the negative value will not be squared along with the variable itself unless parentheses are used to hold the unseen negative.

Thus:

$b = Real(-8);$bs = sqrt($b**2); ## results in sqrt(64) = 8 While:$c = Compute("-8");
$cs = sqrt($c**2); ## results in sqrt(-64) an undefined value.

Tim

### Re: Negative variables when squared stay negative?

by Davide Cervone -
This is not correct. Both of your examples should result in the value 8. Real(-8) and Compute("-8") are effectively the same thing, and don't affect how the value is used in later computations.

I suspect your problem is not in a direct computation, like those you give above, but rather in calling Compute("...") on a string, like

$c = Compute("sqrt($b**2)");

when $b is a perl real, not a MathObject Real. The reason for this is that when you do "sqrt($b**2)", the $b not not a variable in a math expression, it is a perl variable whose value is inserted into the string before Compute() is called to evaluation the string as an expression. So if $b is the (perl real) value -8, for example, then "sqrt($b**2)" becomes "sqrt(-8**2)" and since exponentiation has higher precedence than negation, Compute() correctly interprets this as sqrt(-64) and complains about it. On the other hand, when you do "sqrt(($b)**2)", then after the variable substitution, this becomes "sqrt((-8)**2)", which produces the sqrt(64) that you expected.

If $b where a MathObject Real, however, then when it gets inserted into a string, it automatically includes the parentheses, so it will work as expected in both cases above. But you have to use a MathObject, not a perl real, for that to occur. You do in the examples in your second post, but the original code in your PG problem above are perl reals, so would not work properly. I discussed this in Workshop 2 briefly, but it is good to go over it again. In reply to Davide Cervone ### Re: Negative variables when squared stay negative? by tim Payer - Thank you Davide! Yes, if I take away the quotes on my Compute("$b**2"); command the the calculation is correct. I had to get it wrong before I could see why for myself.

Thanks for giving a detailed explanation.

Sincerely, Tim