Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

116 lines (106 sloc) 6.082 kB
<!DOCTYPE html>
<html data-require="math math-format polynomials functional">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Multiplying polynomials</title>
<script src="../khan-exercise.js"></script>
</head>
<body>
<div class="exercise">
<div class="vars">
<var id="X">randVar()</var>
<var id="COLORS">[ BLUE, ORANGE, GREEN ]</var>
<var id="MAX_DEGREE">4</var>
<var id="NON_ZERO_INDICES" data-ensure="( NON_ZERO_INDICES[ 0 ].length !== 3 || NON_ZERO_INDICES[ 1 ].length !== 3 ) && ( NON_ZERO_INDICES[ 0 ].length !== 1 || NON_ZERO_INDICES[ 1 ].length !== 1 )">tabulate( function() {
return randRangeUniqueNonZero( 0, MAX_DEGREE, randRange(1, 3) ).sort().reverse();
}, 2 )</var>
<var id="POL_1, POL_2">tabulate( function(n) {
var coefs = [];
for ( var i = 0; i &lt;= MAX_DEGREE; i++ ) {
var value = 0;
for ( var j = 0; j &lt; NON_ZERO_INDICES[ n ].length; j++ ) {
if ( i === NON_ZERO_INDICES[ n ][ j ] ) {
value = randRangeNonZero( -7, 7 );
break;
}
}
coefs[ i ] = value;
}
return new Polynomial( 0, MAX_DEGREE, coefs, X );
}, 2 )</var>
<var id="LIKE_TERMS">function() {
var likeTerms = [];
var counter = 0;
var areLikeTerms = false;
for ( var i = POL_1.minDegree; i &lt;= POL_1.maxDegree; i++ ) {
if ( POL_1.coefs[ i ] === 0 ) {
continue;
}
for ( var j = POL_2.minDegree; j &lt;= POL_2.maxDegree; j++ ) {
if ( POL_2.coefs[ j ] === 0 ) {
continue;
}
if ( likeTerms[ i + j ] === undefined ) {
likeTerms[ i + j ] = "";
} else if ( likeTerms[ i + j ] === "" ) {
likeTerms[ i + j ] = COLORS[ counter++ ];
areLikeTerms = true;
}
}
}
return areLikeTerms ? likeTerms : false;
}()</var>
<var id="SOLUTION">POL_1.multiply( POL_2 )</var>
<var id="FAKE_SOLUTION_1, FAKE_SOLUTION_2">tabulate( function(n) {
var counter = 0;
var coefs = [];
for ( var i = 0; i &lt; SOLUTION.coefs.length; i++ )
{
if ( SOLUTION.coefs[ i ] === 0 ) {
continue;
}
coefs[ i ] = SOLUTION.coefs[ i ] * ( n + counter++ % 2 === 0 ? 1 : -1 );
}
return new Polynomial( SOLUTION.minDegree, SOLUTION.maxDegree, coefs, SOLUTION.variable );
}, 2 )</var>
</div>
<div class="problems">
<div id="multiply">
<p class="question">Simplify the expression.</p>
<p class="problem"><code><span data-each="[ POL_1, POL_2 ] as POL" data-unwrap>(<var>POL</var>)</span></code></p>
<p class="solution"><code><var>SOLUTION</var></code></p>
<ul class="choices" data-show="4" data-none="true">
<li><code><var>SOLUTION.multiply( -1 )</var></code></li>
<li><code><var>FAKE_SOLUTION_1</var></code></li>
<li><code><var>FAKE_SOLUTION_2</var></code></li>
</ul>
</div>
</div>
<div class="hints">
<div>
<p>First use the distributive property.</p>
<code><span data-each="NON_ZERO_INDICES[ 0 ] as n1, index1"><span data-each="NON_ZERO_INDICES[ 1 ] as n2, index2"><var>( POL_1.coefs[ index1 ] &lt; 0 ) ? "-" : ( n1 === 0 && n2 === 0 ) ? "" : "+"</var><var>abs( POL_1.coefs[ index1 ] ) === 1 ? "" : abs( POL_1.coefs[ index1 ] )</var><var>X</var>^<var>index1</var>(<var>( POL_2.coefs[ index2 ] === 1 ) ? "" : ( POL_2.coefs[ index2 ] === -1 ) ? "-" : POL_2.coefs[ index2 ]</var><var>X</var>^<var>index2</var>)</span></span></code>
</div>
<div>
<p>Simplify.</p>
<code data-if="LIKE_TERMS"><span data-each="NON_ZERO_INDICES[ 0 ] as n1, index1"><span data-each="NON_ZERO_INDICES[ 1 ] as n2, index2"><var>( POL_1.coefs[ index1 ] * POL_2.coefs[ index2 ] &lt; 0 ) ? "-" : ( n1 === 0 && n2 === 0 ) ? "" : "+"</var><var>abs( POL_1.coefs[ index1 ] * POL_2.coefs[ index2 ] )</var><var>X</var>^{<var>index1 + index2</var>}</span></span></code>
<div data-else>
<code><var>SOLUTION</var></code>
<p>You're done!</p>
</div>
</div>
<div data-if="LIKE_TERMS">
<div>
<p>Identify like terms.</p>
<code><span data-each="NON_ZERO_INDICES[ 0 ] as n1, index1"><span data-each="NON_ZERO_INDICES[ 1 ] as n2, index2">\color{<var>LIKE_TERMS[ index1 + index2 ]</var>}{<var>( POL_1.coefs[ index1 ] * POL_2.coefs[ index2 ] &lt; 0 ) ? "-" : ( n1 === 0 && n2 === 0 ) ? "" : "+"</var><var>abs( POL_1.coefs[ index1 ] * POL_2.coefs[ index2 ] )</var><var>X</var>^{<var>index1 + index2</var>}}</span></span></code>
</div>
<div>
<p>Add the coefficients.</p>
<p><code><span data-each="new Array( SOLUTION.getNumberOfTerms() ) as n, index">\color{<var>LIKE_TERMS[ SOLUTION.getCoefAndDegreeForTerm( n ).degree ]</var>}{<var>( SOLUTION.getCoefAndDegreeForTerm( n ).coef &lt; 0 || n === 0 ) ? "" : "+"</var><var>expr( SOLUTION.expr()[ n + 1 ] )</var>}</span></code></p>
<p>You're done!</p>
</div>
</div>
</div>
</div>
</body>
</html>
Jump to Line
Something went wrong with that request. Please try again.