Skip to content
This repository has been archived by the owner on May 11, 2021. It is now read-only.

Commit

Permalink
Merge branch 'master' into simple-maps
Browse files Browse the repository at this point in the history
  • Loading branch information
nsfmc committed Nov 9, 2011
2 parents 7b9c1e6 + 62a0559 commit e85ae50
Show file tree
Hide file tree
Showing 37 changed files with 1,927 additions and 413 deletions.
1 change: 1 addition & 0 deletions css/khan-exercise.css
Expand Up @@ -50,6 +50,7 @@ body.debug .graphie { outline: 1px dashed red; }

#tester-info.info-box { background: #f2e4bf; }
#tester-info .box { border: 1px solid black; padding: 2px 4px; margin-left: 5px; }
#tester-info .group-box { border: 1px solid #aaa; padding: 6px 4px 6px 0px; margin-left: 2px; }

.summary { display: none; }
#browserwarning { background: white; margin: 0 1px; padding: 18px; font-size: 120%; text-align: center; }
Expand Down
113 changes: 93 additions & 20 deletions exercises/adding_and_subtracting_polynomials.html
Expand Up @@ -4,45 +4,118 @@
<meta charset="UTF-8" />
<title>Adding and subtracting polynomials</title>
<script src="../khan-exercise.js"></script>
<script type="text/javascript">
function getFakeAnswers( solution ) {
var answers = [];
for ( var i = 0; i < solution.getNumberOfTerms(); i++ ) {
var coefs = [];

for ( var j = 0; j < solution.getNumberOfTerms(); j++ ) {
var term = solution.getCoefAndDegreeForTerm( j );

if ( i === j ) {
coefs[ term.degree ] = KhanUtil.randRangeNonZero( -7, 7 );
} else {
coefs[ term.degree ] = term.coef;
}
}

for ( var j = 0; j < coefs.length; j++ ) {
if ( coefs[ j ] === undefined ) {
coefs[ j ] = 0;
}
}

answers.push( new KhanUtil.Polynomial(0, solution.maxDegree, coefs, solution.variable) );
}

return answers;
}
</script>
</head>
<body>
<div class="exercise">
<div class="vars">
<var id="X">randFromArray([ "x", "k", "y", "a", "n", "r", "p", "u", "v" ])</var>
<var id="X">randVar()</var>
<var id="COLORS">[ BLUE, ORANGE, GREEN ]</var>
<var id="MAX_DEGREE">7</var>
<var id="NON_ZERO_INDICES">function() {
var numberNonZeroCoefficients = randRange( 2, 3 );

return randRangeUniqueNonZero( 0, MAX_DEGREE, numberNonZeroCoefficients );
}()</var>
<var id="POL_1, POL_2">listFn( function() {
<var id="NON_ZERO_INDICES">randRangeUniqueNonZero( 0, MAX_DEGREE, randRange(2, 3) ).sort().reverse()</var>
<var id="POL_1, POL_2" data-ensure="POL_1.add( POL_2 ).getNumberOfTerms() >= 1 && POL_1.subtract( POL_2 ).getNumberOfTerms() >= 1">tabulate( function() {
var coefs = [];
for ( var i = 0; i <= MAX_DEGREE; i++ ) {
coefs[ i ] = 0;
}

for ( var i = 0; i < NON_ZERO_INDICES.length; i++ ) {
coefs[ NON_ZERO_INDICES[ i ] ] = randRangeNonZero( -7, 7 )
var value = 0;
for ( var j = 0; j < NON_ZERO_INDICES.length; j++ ) {
if ( i === NON_ZERO_INDICES[ j ] ) {
value = randRangeNonZero( -7, 7 );
break;
}
}
coefs[ i ] = value;
}

return new Polynomial( 0, MAX_DEGREE, coefs, X )
return new Polynomial( 0, MAX_DEGREE, coefs, X );
}, 2 )</var>
<var id="SOLUTION"></var>
</div>

<div class="problems">
<div id="add">
<p class="problem">Simplify the expression:</p>
<div class="question">
<code>(<var>POL_1.text()</var>) + (<var>POL_2.text()</var>)</code>
<div class="vars">
<var id="SIGN">"+"</var>
<var id="SOLUTION">POL_1.add( POL_2 )</var>
<var id="FAKE_ANSWERS">getFakeAnswers( SOLUTION )</var>
</div>

<p class="question">Simplify the expression.</p>
<p class="problem"><code>(<var>POL_1</var>) <var>SIGN</var> (<var>POL_2</var>)</code></p>
<p class="solution"><code><var>SOLUTION</var></code></p>
<ul class="choices" data-none="true">
<li><code><var>POL_1.subtract( POL_2 )</var></code></li>
<li data-each="FAKE_ANSWERS as FAKE_ANSWER"><code><var>FAKE_ANSWER</var></code></li>
</ul>
</div>

<div id="subtract" data-type="add">
<div class="vars">
<var id="SIGN">"-"</var>
<var id="SOLUTION">POL_1.subtract( POL_2 )</var>
<var id="FAKE_ANSWERS">getFakeAnswers( SOLUTION )</var>
</div>

<ul class="choices" data-none="true">
<li><code><var>POL_1.add( POL_2 )</var></code></li>
<li data-each="FAKE_ANSWERS as FAKE_ANSWER"><code><var>FAKE_ANSWER</var></code></li>
</ul>

<div class="hints" data-apply="appendContents">
<div id="paren">
<p>Since this is subtraction, when removing the parenthesis we must distribute the minus sign to all terms in the second polynomial.</p>
<var>POL_2 = POL_2.multiply( -1 ), null</var>
<p><code><var>POL_1</var> + <var>POL_2</var></code></p>
</div>
</div>
<div><code><var>POL_1.add(POL_2).text()</var></code></div>
<div class="solution">5</div>
</div>
</div>

<div class="hints">
<p>Hey</p>
<div id="paren">
<p>Since this is addition, we can remove the parenthesis without any extra steps.</p>
<p><code><var>POL_1</var> + <var>POL_2</var></code></p>
</div>
<div>
<p>Identify like terms.</p>
<p><code><span data-each="[ POL_1, POL_2 ] as POL"><span data-each="NON_ZERO_INDICES as n, index" data-unwrap><var>( POL.coefs[ index ] < 0 ) ? "-" : ( n === 0 && POL === POL_1 ) ? "" : "+"</var>\color{<var>COLORS[ n ]</var>}{<var>abs( POL.coefs[ index ] ) === 1 ? "" : abs( POL.coefs[ index ] )</var><var>X</var>^<var>index</var>}</span></span></code></p>

</div>
<div>
<p>Combine like terms.</p>
<p><code><span data-each="NON_ZERO_INDICES as n, index"><span data-if="n !== 0">+</span>\color{<var>COLORS[ n ]</var>}{(<var>POL_1.coefs[ index ]</var> + <var>POL_2.coefs[ index ]</var>)<var>X</var>^<var>index</var>}</span></code></p>
</div>
<div>
<div>
<p>Add the coefficients.</p>
<p><code><var>POL_1.add(POL_2).text()</var></code></p>
<p>You're done!</p>
</div>
</div>
</div>
</body>
Expand Down
22 changes: 11 additions & 11 deletions exercises/compound_inequalities.html
Expand Up @@ -22,46 +22,46 @@
<body>
<div class="exercise">
<div class="vars" data-ensure="abs( SOLUTION[0] - SOLUTION[1] ) <= 5 && FAKE_ANSWER[0] !== SOLUTION[0] && FAKE_ANSWER[1] !== SOLUTION[1]">
<var id="COEF">listFn( function() {
<var id="COEF">tabulate( function() {
return randRange( 2, 9 ) * ( rand( 3 ) > 0 ? 1 : -1 );
} , 2 )</var>
<var id="ONE_OVER_COEF">listFn( function(i) {
<var id="ONE_OVER_COEF">tabulate( function(i) {
return fraction( 1, COEF[i] );
}, 2 )</var>
<var id="SIGN">randFromArray( [ "-", "+" ], 2)</var>
<var id="LEFT_INT">listFn( function() {
<var id="LEFT_INT">tabulate( function() {
return rand( 3 ) > 0 ? randRange( 2, 9 ) : 0;
}, 2 )</var>
<var id="ADD_TO_SIMPLIFY">listFn( function(i) {
<var id="ADD_TO_SIMPLIFY">tabulate( function(i) {
return LEFT_INT[i] * ( SIGN[i] === "+" ? -1 : 1 );
}, 2 )</var>
<var id="COMP">randFromArray( [ "&lt;", "&gt;", "&le;", "&ge;" ], 2 )</var>
<var id="RIGHT_INT">listFn( function(i) {
<var id="RIGHT_INT">tabulate( function(i) {
return randRange( 1, 6 ) * abs( COEF[i] ) + ( SIGN[i] === "+" ? 1 : -1 ) * LEFT_INT[i];
}, 2 )</var>
<var id="VARIABLE_NAME">randFromArray([ "a", "b", "c", "x", "y", "z" ])</var>
<var id="COMP_SOLUTION">listFn( function(i) {
<var id="COMP_SOLUTION">tabulate( function(i) {
return getComp( COEF[i], COMP[i] );
}, 2 )</var>
<var id="SOLUTION_NOT_REDUCED">listFn( function(i) {
<var id="SOLUTION_NOT_REDUCED">tabulate( function(i) {
return fraction( RIGHT_INT[i] + ADD_TO_SIMPLIFY[i], COEF[i] );
}, 2 )</var>
<var id="SOLUTION">listFn( function(i) {
<var id="SOLUTION">tabulate( function(i) {
return ( RIGHT_INT[i] + ADD_TO_SIMPLIFY[i] ) / COEF[i];
}, 2 )</var>
<var id="FIRST">[ "first", "second" ]</var>
<var id="COLOR">[ "#1F78B4", "#B30000" ]</var>
<var id="INCLUSIVE">listFn( function(i) {
<var id="INCLUSIVE">tabulate( function(i) {
return COMP_SOLUTION[i] === "&le;" || COMP_SOLUTION[i] === "&ge;";
}, 2 )</var>
<var id="LESS_THAN">listFn( function(i) {
<var id="LESS_THAN">tabulate( function(i) {
return COMP_SOLUTION[i] === "&le;" || COMP_SOLUTION[i] === "&lt;";
}, 2 )</var>
<var id="ALL_NUMBERS">( LESS_THAN[0] && !LESS_THAN[1] && SOLUTION[0] >= SOLUTION [1] ) || ( !LESS_THAN[0] && LESS_THAN[1] && SOLUTION[0] <= SOLUTION [1] )</var>
<var id="NO_SOLUTION">( LESS_THAN[0] && !LESS_THAN[1] && SOLUTION[1] > SOLUTION[0] ) || ( !LESS_THAN[0] && LESS_THAN[1] && SOLUTION[0] > SOLUTION[1] ) || ( LESS_THAN[0] !== LESS_THAN[1] && SOLUTION[0] === SOLUTION[1] && ( !INCLUSIVE[0] || !INCLUSIVE[1] ) )</var>
<var id="OR">randFromArray([ "or", "and" ])</var>
<var id="IS_OR">OR === "or"</var>
<var id="FAKE_ANSWER">listFn( function() {
<var id="FAKE_ANSWER">tabulate( function() {
return randRange( 2, 9 ) * ( rand( 3 ) > 0 ? 1 : -1 )
}, 2 )</var>
<var id="CONTAINS">(function() {
Expand Down
26 changes: 16 additions & 10 deletions exercises/converting_between_slope_intercept_and_standard_form.html
Expand Up @@ -34,16 +34,16 @@
</div>
<div>
<p>Inspecting the equation in slope intercept form, we see the following.</p>
<p><code>\begin{align*}m &= <var>fractionReduce( -1 * A, B)</var>\\
b &= <var>fractionReduce( C, B )</var>\end{align*}</code></p>
<p><code>\begin{align*}m &amp;= <var>fractionReduce( -1 * A, B)</var>\\
b &amp;= <var>fractionReduce( C, B )</var>\end{align*}</code></p>
</div>
<div>
<p>Behold! The magic of math, that both equations could represent the same line!</p>
<div class="graphie" id="grid">
graphInit({
range: 10,
scale: 20,
axisArrows: "<->",
axisArrows: "&lt;-&gt;",
tickStep: 1,
labelStep: 1
});
Expand All @@ -61,12 +61,13 @@
<div class="vars">
<var id="SLOPE">randRange( -3, 3 )</var>
<var id="Y_INTERCEPT">randRangeNonZero( -3, 3 )</var>
<var id="A">-1 * SLOPE</var>
<var id="B">1</var>
<var id="C">Y_INTERCEPT</var>
<var id="A">SLOPE &lt;= 0 ? -1 * SLOPE : SLOPE</var>
<var id="B">SLOPE &lt;= 0 ? 1 : -1</var>
<var id="C">SLOPE &lt;= 0 ? Y_INTERCEPT: -1 * Y_INTERCEPT</var>
</div>
<p class="question">Convert the following equation from slope intercept form to standard form.</p>
<p>In other words, if the equation is rewritten to look like <code>Ax + By = C</code>, what are the values of <code>A</code>, <code>B</code>, and <code>C</code>?</p>
<p>Assume <code>A</code> is positive.</p>
<p><code>y = <var>expr([ "+", [ "*", SLOPE, "x" ], Y_INTERCEPT ])</var></code></p>
<div class="solution" data-type="multiple">
<p><code>A</code> = <span class="sol"><var>A</var></span></p>
Expand All @@ -80,20 +81,25 @@
</div>
<div data-else>
<p>Since the slope is <code>0</code> and there is no <code>x</code> term, the equation is already in slope intercept form.</p>
<p><code>y = <var>Y_INTERCEPT</var></code></p>
</div>
<div data-if="SLOPE > 0">
<p>Multiply both sides by <code>-1</code> so that <code>A</code> will be positive</p>
<p><code><var>expr([ "*", SLOPE, "x" ])</var> - y = <var>-Y_INTERCEPT</var></code></p>
</div>
<div>
<p>Inspecting the equation in standard form, we see the following.</p>
<p><code>\begin{align*}A &= <var>A</var>\\
B &= <var>B</var>\\
C &= <var>C</var>\end{align*}</code></p>
<p><code>\begin{align*}A &amp;= <var>A</var>\\
B &amp;= <var>B</var>\\
C &amp;= <var>C</var>\end{align*}</code></p>
</div>
<div>
<p>Behold! The magic of math, that both equations could represent the same line!</p>
<div class="graphie" id="grid">
graphInit({
range: 10,
scale: 20,
axisArrows: "<->",
axisArrows: "&lt;-&gt;",
tickStep: 1,
labelStep: 1
});
Expand Down

0 comments on commit e85ae50

Please sign in to comment.