# Khan/khan-exercises

Fetching contributors…
Cannot retrieve contributors at this time
116 lines (106 sloc) 5.94 KB
 Multiplying polynomials
randVar() [ BLUE, ORANGE, GREEN ] 4 tabulate( function() { return randRangeUniqueNonZero( 0, MAX_DEGREE, randRange(1, 3) ).sort().reverse(); }, 2 ) tabulate( function(n) { var coefs = []; for ( var i = 0; i <= MAX_DEGREE; i++ ) { var value = 0; for ( var j = 0; j < 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 ) function() { var likeTerms = []; var counter = 0; var areLikeTerms = false; for ( var i = POL_1.minDegree; i <= POL_1.maxDegree; i++ ) { if ( POL_1.coefs[ i ] === 0 ) { continue; } for ( var j = POL_2.minDegree; j <= 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; }() POL_1.multiply( POL_2 ) tabulate( function(n) { var counter = 0; var coefs = []; for ( var i = 0; i < 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 )

Simplify the expression.

(POL)

SOLUTION

• SOLUTION.multiply( -1 )
• FAKE_SOLUTION_1
• FAKE_SOLUTION_2

First use the distributive property.

( POL_1.coefs[ index1 ] < 0 ) ? "-" : ( n1 === 0 && n2 === 0 ) ? "" : "+"abs( POL_1.coefs[ index1 ] ) === 1 ? "" : abs( POL_1.coefs[ index1 ] )X^index1(( POL_2.coefs[ index2 ] === 1 ) ? "" : ( POL_2.coefs[ index2 ] === -1 ) ? "-" : POL_2.coefs[ index2 ]X^index2)

Simplify.

( POL_1.coefs[ index1 ] * POL_2.coefs[ index2 ] < 0 ) ? "-" : ( n1 === 0 && n2 === 0 ) ? "" : "+"abs( POL_1.coefs[ index1 ] * POL_2.coefs[ index2 ] )X^{index1 + index2}
SOLUTION

You're done!

Identify like terms.

\color{LIKE_TERMS[ index1 + index2 ]}{( POL_1.coefs[ index1 ] * POL_2.coefs[ index2 ] < 0 ) ? "-" : ( n1 === 0 && n2 === 0 ) ? "" : "+"abs( POL_1.coefs[ index1 ] * POL_2.coefs[ index2 ] )X^{index1 + index2}}