# Khan/khan-exercises

Fetching contributors…
Cannot retrieve contributors at this time
315 lines (299 sloc) 16.4 KB
 Graphing linear inequalities
reduce( randRangeNonZero( -5, 5 ), randRange( 1, 5 ) ) randRangeNonZero( max( -10, -10 - SLOPE_FRAC[0] ), min( 10, 10 - SLOPE_FRAC[0] ) ) SLOPE_FRAC[0] / SLOPE_FRAC[1] fractionVariable(SLOPE_FRAC[0], SLOPE_FRAC[1], "x") randRangeNonZero( -3, 3 ) SLOPE_FRAC[0] * -MULT SLOPE_FRAC[1] * MULT SLOPE_FRAC[1] * YINT * MULT randFromArray([true, false]) randFromArray(["<", ">", "≤", "≥"]) B < 0 ? { "<": ">", ">": "<", "≤": "≥", "≥": "≤" }[COMP] : COMP COMP === "<" || COMP === "≤" COMP === "≥" || COMP === "≤"

Graph the following inequality:

expr([ "+", [ "*", A, "x" ], [ "*", B, "y" ] ]) STD_FORM_COMP C

y COMP PRETTY_SLOPE + YINT

graphInit({ range: 11, scale: 20, axisArrows: "<->", tickStep: 1, labelStep: 1, gridOpacity: 0.05, axisOpacity: 0.2, tickOpacity: 0.4, labelOpacity: 0.5 }); label( [ 0, -11 ], "y", "below" ); label( [ 11, 0 ], "x", "right" ); addMouseLayer(); graph.pointA = addMovablePoint({ coord: [ -5, 5 ], snapX: 0.5, snapY: 0.5, normalStyle: { stroke: KhanUtil.BLUE, fill: KhanUtil.BLUE } }); graph.pointB = addMovablePoint({ coord: [ 5, 5 ], snapX: 0.5, snapY: 0.5, normalStyle: { stroke: KhanUtil.BLUE, fill: KhanUtil.BLUE } }); graph.line1 = bogusShape; graph.shading = bogusShape; graph.update = function() { graph.line1.remove(); graph.shading.remove(); if ( abs( graph.pointB.coord[0] - graph.pointA.coord[0] ) > 0.001 ) { var slope = ( graph.pointB.coord[1] - graph.pointA.coord[1] ) / ( graph.pointB.coord[0] - graph.pointA.coord[0] ); var yint = slope * ( 0 - graph.pointA.coord[0] ) + graph.pointA.coord[1]; var shadeEdge = ( ( graph.pointA.coord[0] < graph.pointB.coord[0] ) ? graph.shadetop : !graph.shadetop ) ? 11 : -11; style({ stroke: BLUE, strokeWidth: 2, strokeDasharray: graph.dasharray }, function() { graph.line1 = line( [ -11, -11 * slope + yint ], [ 11, 11 * slope + yint ] ).toBack(); }); style({ fill: BLUE, stroke: null, opacity: KhanUtil.FILL_OPACITY }, function() { graph.shading = path([ [ 11, shadeEdge ], [ 11, 11 * slope + yint ], [ -11, -11 * slope + yint ], [ -11, shadeEdge ] ]); }); } else { // vertical line var x = graph.pointA.coord[0]; var shadeEdge = ( ( graph.pointB.coord[1] < graph.pointA.coord[1] ) ? graph.shadetop : !graph.shadetop ) ? 11 : -11; style({ stroke: BLUE, strokeWidth: 2, strokeDasharray: graph.dasharray }, function() { graph.line1 = line( [ x, -11 ], [ x, 11 ] ).toBack(); }); style({ fill: BLUE, stroke: null, opacity: KhanUtil.FILL_OPACITY }, function() { graph.shading = path([ [ x, -11 ], [ x, 11 ], [ shadeEdge, 11 ], [ shadeEdge, -11 ] ]); }); } graph.pointA.toFront(); graph.pointB.toFront(); }; graph.showCorrect = function() { graph.pointA.setCoord([0, YINT]); graph.pointB.setCoord([SLOPE_FRAC[1], YINT + SLOPE_FRAC[0]]); graph.shadetop = graph.pointA.coord[0] > graph.pointB.coord[0] ? LESS_THAN : !LESS_THAN; if (INCLUSIVE) { graph.dasharray = ''; $('input[name=dashradio][value=solid]').attr('checked', true); } else { graph.dasharray = '- ';$('input[name=dashradio][value=dashed]').attr('checked', true); } graph.update(); }; // A and B can't be in the same place graph.pointA.onMove = function( x, y ) { if ( x != graph.pointB.coord[0] || y != graph.pointB.coord[1] ) { graph.pointA.setCoord([ x, y ]); graph.update(); return true; } else { return false; } } graph.pointB.onMove = function( x, y ) { if ( x != graph.pointA.coord[0] || y != graph.pointA.coord[1] ) { graph.pointB.setCoord([ x, y, ]); graph.update(); return true; } else { return false; } } graph.dasharray = ""; graph.shadetop = true; graph.update(); graph.pointA.toFront(); graph.pointB.toFront();
Drag the two points to move the line into the correct position.
[ graph.pointA.coord, graph.pointB.coord, graph.pointA.coord[0] > graph.pointB.coord[0] ? graph.shadetop : !graph.shadetop, graph.dasharray === "- " ? false : true ]
var slope = ( guess[1][1] - guess[0][1] ) / ( guess[1][0] - guess[0][0] ); var yint = slope * ( 0 - guess[0][0] ) + guess[0][1]; return abs( SLOPE - slope ) < 0.001 && abs( YINT - yint ) < 0.001 && guess[2] === LESS_THAN && guess[3] === INCLUSIVE;
graph.pointA.setCoord( guess[0] ); graph.pointB.setCoord( guess[1] ); graph.shadetop = graph.pointA.coord[0] > graph.pointB.coord[0] ? guess[2] : !guess[2]; if ( guess[3] ) { graph.dasharray = ""; $( "input[name=dashradio][value=solid]" ).attr( "checked", true ); } else { graph.dasharray = "- ";$( "input[name=dashradio][value=dashed]" ).attr( "checked", true ); } graph.update();

Convert expr([ "+", [ "*", A, "x" ], [ "*", B, "y" ] ]) STD_FORM_COMP C to slope-intercept form by solving for y.

Add abs( A )x to both sides:

Subtract abs( A )x from both sides:

\qquad expr( [ "*", B, "y" ] ) STD_FORM_COMP expr([ "+", [ "*", -A, "x" ], C ])

Divide both sides by B. Since you're multiplying or dividing by a negative number, don't forget to flip the inequality sign:

\qquad y COMP expr([ "+", "\\dfrac{" + expr([ "*", -A, "x" ]) + "}{" + B + "}", "\\dfrac{" + C + "}{" + B + "}" ])

\qquad y COMP \purple{PRETTY_SLOPE} \green{+ YINT}

The y-intercept is YINT and the slope is decimalFraction( SLOPE, true, true ). Since the y-intercept is YINT, the line must pass through the point (0, YINT).

style({ stroke: GREEN, fill: GREEN }, function() { graph.yint = circle( [ 0, YINT ], 0.2 ).toBack(); });

The slope is decimalFraction( SLOPE, true, true ). Remember that the slope tells you rise over run. For every step we take we must move abs( SLOPE_FRAC[0] ) positions down (because it's negative)up. For every step we take we must move abs( SLOPE_FRAC[0] ) position down (because it's negative)up. For every step we take we must also move SLOPE_FRAC[1] positions to the right. For every step we take we must also move SLOPE_FRAC[1] position to the right. So the line must also pass through (SLOPE_FRAC[1], YINT + SLOPE_FRAC[0]).

style({ stroke: "purple", strokeWidth: 2, arrows: "->" }, function() { path([ [ 0, YINT ], [ 0, YINT + SLOPE_FRAC[0] ] ]).toBack(); path([ [ 0, YINT + SLOPE_FRAC[0] ], [ SLOPE_FRAC[1], YINT + SLOPE_FRAC[0] ] ]).toBack(); }); label( [ 0, YINT + SLOPE_FRAC[0] / 2 ], abs( SLOPE_FRAC[0] ) + " \\text{ " + ( SLOPE_FRAC[0] < 0 ? "down" : "up" ) + "} \\quad", "left", { color: "purple" } ); label( [ 0, YINT + SLOPE_FRAC[0] ], SLOPE_FRAC[1] + " \\text{ " + i18n._("right") + "}", ( SLOPE_FRAC[0] < 0 ? "below right" : "above right" ), { color: "purple" } ); graph.yint.toBack();

Since our inequality has a less-than or equal to sign, that means that any point below the line is a solution to the inequality, so the area below the line should be shaded.

Since our inequality has a greater-than or equal to sign, that means that any point above the line is a solution to the inequality, so the area above the line should be shaded.

Note that since the sign is less-than or equal to, any point on the line is also a solution, so the line should be solid. Note that since the sign is greater-than or equal to, any point on the line is also a solution, so the line should be solid.

Note that since the sign is less-than (and not equal to), any point on the line is not part of the solution, so the line should be dashed to indicate this. Note that since the sign is greater-than (and not equal to), any point on the line is not part of the solution, so the line should be dashed to indicate this.