Difference between revisions of "ExpandedPolynomial1"

From WeBWorK_wiki
Jump to navigation Jump to search
(Created page with '<h2>Polynomial Multiplication (Expanding)</h2> <p style="background-color:#eeeeee;border:black solid 1px;padding:3px;"> This PG code shows how to require students to expand poly…')
 
(11 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
<h2>Polynomial Multiplication (Expanding)</h2>
 
<h2>Polynomial Multiplication (Expanding)</h2>
   
<p style="background-color:#eeeeee;border:black solid 1px;padding:3px;">
 
  +
[[File:ExpandedPolynomial1.png|300px|thumb|right|Click to enlarge]]
  +
<p style="background-color:#f9f9f9;border:black solid 1px;padding:3px;">
 
This PG code shows how to require students to expand polynomial multiplication.
 
This PG code shows how to require students to expand polynomial multiplication.
<ul>
 
<li>Download file: [[File:ExpandedPolynomial1.txt]] (change the file extension from txt to pg when you save it)</li>
 
<li>File location in NPL: <code>NationalProblemLibrary/FortLewis/Authoring/Templates/Algebra/ExpandedPolynomial1.pg</code></li>
 
</ul>
 
 
</p>
 
</p>
  +
* File location in OPL: [https://github.com/openwebwork/webwork-open-problem-library/blob/master/OpenProblemLibrary/FortLewis/Authoring/Templates/Algebra/ExpandedPolynomial1.pg FortLewis/Authoring/Templates/Algebra/ExpandedPolynomial1.pg]
  +
* PGML location in OPL: [https://github.com/openwebwork/webwork-open-problem-library/blob/master/OpenProblemLibrary/FortLewis/Authoring/Templates/Algebra/ExpandedPolynomial1_PGML.pg FortLewis/Authoring/Templates/Algebra/ExpandedPolynomial1_PGML.pg]
   
  +
<br clear="all" />
 
<p style="text-align:center;">
 
<p style="text-align:center;">
 
[[SubjectAreaTemplates|Templates by Subject Area]]
 
[[SubjectAreaTemplates|Templates by Subject Area]]
Line 41: Line 41:
 
<pre>
 
<pre>
 
DOCUMENT();
 
DOCUMENT();
  +
 
loadMacros(
 
loadMacros(
 
"PGstandard.pl",
 
"PGstandard.pl",
 
"MathObjects.pl",
 
"MathObjects.pl",
 
"contextLimitedPolynomial.pl",
 
"contextLimitedPolynomial.pl",
"contextPolynomialFactors.pl",
 
"contextLimitedPowers.pl",
 
 
);
 
);
   
Line 55: Line 54:
 
<p>
 
<p>
 
<b>Initialization:</b>
 
<b>Initialization:</b>
We need all of these macros.
 
  +
We must load <code>contextLimitedPolynomial.pl</code>
 
</p>
 
</p>
 
</td>
 
</td>
Line 69: Line 68:
 
#
 
#
 
Context("Numeric");
 
Context("Numeric");
$n = list_random(4,6);
 
  +
$h = 3;
$a = random(2,4,1);
+
$k = 5;
$b = ($a+$n);
 
$h = ($b-$a)/2;
 
$k = $h**2+$a*$b;
 
 
$vertexform = Compute("(x-$h)^2-$k");
 
$vertexform = Compute("(x-$h)^2-$k");
   
Line 77: Line 76:
 
#
 
#
 
Context("LimitedPolynomial-Strict");
 
Context("LimitedPolynomial-Strict");
$p[0] = $h**2 - $k;
+
$b = -2 * $h;
$p[1] = 2*$h;
+
$c = $h**2 - $k;
$expandedform = Formula("x^2 - $p[1] x + $p[0]")->reduce;
+
$expandedform = Formula("x^2 + $b x + $c")->reduce();
 
#
 
# Factored form
 
#
 
Context("PolynomialFactors-Strict");
 
Context()->flags->set(singleFactors=>0);
 
LimitedPowers::OnlyIntegers(
 
minPower => 0, maxPower => 1,
 
message => "either 0 or 1",
 
);
 
$factoredform = Compute("(x+$a)(x-$b)");
 
 
</pre>
 
</pre>
 
</td>
 
</td>
Line 85: Line 84:
 
<p>
 
<p>
 
<b>Setup:</b>
 
<b>Setup:</b>
To construct this quadratic, we choose a nice factored form <code>(x+$a)(x-$b)</code> and from it we construct its vertex form (a(x-h)^2+k) and expanded form (ax^2+bx+c).
 
  +
The macro <code>contextLimitedPolynomial.pl</code> provides two contexts:
</p>
+
<pre>
<p>
+
Context("LimitedPolynomial");
For the expanded form we use the <code>LimitedPolynomial-Strict</code> context, construct the coefficients <code>$p[0]</code> and <code>$p[1]</code> as Perl reals, and then construct <code>$expandedform</code> using these pre-computed coefficients. This is because the LimitedPolynomial-Strict context balks at answers that are not already simplified completely.
+
Context("LimitedPolynomial-Strict");
  +
</pre>
  +
The strict version does not allow any mathematical operations within coefficients, so <code>(5+3)x</code> must be simplified to <code>8x</code>.
  +
For more details, see [http://webwork.maa.org/pod/pg/macros/contextLimitedPolynomial.html contextLimitedPolynomial.pl]
 
</p>
 
</p>
 
<p>
 
<p>
For the factored form we need to change to the <code>PolynomialFactors-Strict</code> context and restrict the allowed powers to either 0 or 1 using the <code>LimitedPowers::OnlyIntegers</code> block of code. Note: restricting all exponents to 0 or 1 means that repeated factors will have to be entered in the form <code>k(ax+b)(ax+b)</code> instead of <code>k(ax+b)^2</code>. Also, restricting all exponents to 0 or 1 means that the polynomial must factor as a product of linear factors (no irreducible quadratic factors can appear). Of course, we could allow exponents to be 0, 1, or 2, but then students would be allowed to enter <i>reducible</i> quadratic factors. There are no restrictions on the coefficients, i.e., the quadratic could have any nonzero leading coefficient. We set <code>singleFactors=>0</code> so that repeated, non-simplified factors do not generate errors.
 
  +
We use the <code>LimitedPolynomial-Strict</code> context, construct the coefficients <code>$b</code> and <code>$c</code> as Perl reals, and then construct <code>$expandedform</code> using these pre-computed coefficients. This is because the LimitedPolynomial-Strict context balks at answers that are not already simplified completely. Notice that we called the <code>-&gt;reduce()</code> method on the expanded form of the polynomial, which will ensure that the polynomial will be displayed as <code>x^2 - 6x + 4</code> instead of <code>x^2 + -6x + 4</code>.
 
</p>
 
</p>
 
</td>
 
</td>
Line 104: Line 103:
 
BEGIN_TEXT
 
BEGIN_TEXT
 
The quadratic expression \( $vertexform \)
 
The quadratic expression \( $vertexform \)
is written in vertex form.
+
is written in vertex form. Write the
  +
expression in expanded form
  +
\( ax^2 + bx + c \).
 
$BR
 
$BR
$BR
 
(a) Write the expression in expanded form
 
\( ax^2 + bx + c \).
 
 
$BR
 
$BR
 
\{ ans_rule(30) \}
 
\{ ans_rule(30) \}
$BR
 
$BR
 
(b) Write the expression in factored form
 
\( k(ax+b)(cx+d) \).
 
$BR
 
\{ ans_rule(30)\}
 
 
END_TEXT
 
END_TEXT
 
Context()->normalStrings;
 
Context()->normalStrings;
Line 123: Line 113:
 
<p>
 
<p>
 
<b>Main Text:</b>
 
<b>Main Text:</b>
Everything here is as usual. To help students understand how to format their answers, we give examples <code>ax^2+bx+c</code> and <code>k(ax+b)(cx+d)</code> of what the answers should look like.
+
To help students understand how to format their answers, we give an example <code>ax^2+bx+c</code> of what the answer should look like.
 
</p>
 
</p>
 
</td>
 
</td>
Line 136: Line 126:
   
 
ANS( $expandedform->cmp() );
 
ANS( $expandedform->cmp() );
ANS( $factoredform->cmp() );
 
   
 
</pre>
 
</pre>
Line 142: Line 131:
 
<p>
 
<p>
 
<b>Answer Evaluation:</b>
 
<b>Answer Evaluation:</b>
Everything is as expected.
 
 
</p>
 
</p>
 
</td>
 
</td>
Line 178: Line 166:
   
 
[[Category:Top]]
 
[[Category:Top]]
[[Category:Authors]]
+
[[Category:Sample Problems]]
  +
[[Category:Subject Area Templates]]

Revision as of 17:56, 7 April 2021

Polynomial Multiplication (Expanding)

Click to enlarge

This PG code shows how to require students to expand polynomial multiplication.


Templates by Subject Area

PG problem file Explanation

Problem tagging data

Problem tagging:

DOCUMENT();

loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"contextLimitedPolynomial.pl",
);

TEXT(beginproblem()); 

Initialization: We must load contextLimitedPolynomial.pl

#
#  Vertex form
#
Context("Numeric");
$h = 3;
$k = 5;
$vertexform = Compute("(x-$h)^2-$k");

#
#  Expanded form
#
Context("LimitedPolynomial-Strict");
$b = -2 * $h;
$c = $h**2 - $k;
$expandedform = Formula("x^2 + $b x + $c")->reduce();

Setup: The macro contextLimitedPolynomial.pl provides two contexts:

Context("LimitedPolynomial");
Context("LimitedPolynomial-Strict");

The strict version does not allow any mathematical operations within coefficients, so (5+3)x must be simplified to 8x. For more details, see contextLimitedPolynomial.pl

We use the LimitedPolynomial-Strict context, construct the coefficients $b and $c as Perl reals, and then construct $expandedform using these pre-computed coefficients. This is because the LimitedPolynomial-Strict context balks at answers that are not already simplified completely. Notice that we called the ->reduce() method on the expanded form of the polynomial, which will ensure that the polynomial will be displayed as x^2 - 6x + 4 instead of x^2 + -6x + 4.

Context()->texStrings;
BEGIN_TEXT
The quadratic expression \( $vertexform \)
is written in vertex form.  Write the 
expression in expanded form 
\( ax^2 + bx + c \).
$BR
$BR
\{ ans_rule(30) \}
END_TEXT
Context()->normalStrings;

Main Text: To help students understand how to format their answers, we give an example ax^2+bx+c of what the answer should look like.

$showPartialCorrectAnswers = 1;

ANS( $expandedform->cmp() );

Answer Evaluation:


Context()->texStrings;
BEGIN_SOLUTION
${PAR}SOLUTION:${PAR}
Solution explanation goes here.
END_SOLUTION
Context()->normalStrings;

COMMENT('MathObject version.');

ENDDOCUMENT();

Solution:

Templates by Subject Area