# Khan/khan-exercises

Switch branches/tags
Nothing to show
Fetching contributors…
Cannot retrieve contributors at this time
342 lines (317 sloc) 15.1 KB
 Graphing parabolas in all forms
randRangeNonZero(-5, 5) randRangeNonZero(-5, 5) randRangeNonZero(-5, 5) A === 1 ? "" : A === -1 ? "-" : A H + 1 A * (X1 - H) * (X1 - H) + K H - 1 A * (X2 - H) * (X2 - H) + K

Graph the following equation:

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", "above" ); 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.pointC = addMovablePoint({ coord: [ 0, 5 ], snapX: 0.5, snapY: 0.5, normalStyle: { stroke: KhanUtil.BLUE, fill: KhanUtil.BLUE } }); // returns true if the three points don't form a parabola (that opens vertically) graph.invalid = function( p1, p2, p3 ) { return ( ( p1[ 0 ] - p2[ 0 ] ) * ( p1[ 0 ] - p3[ 0 ] ) * ( p2[ 0 ] - p3[ 0 ] ) === 0 ); }; // Fits a parabola to 3 points graph.fitParabola = function( p1, p2, p3 ) { var denom = (p1[0] - p2[0]) * (p1[0] - p3[0]) * (p2[0] - p3[0]); if ( denom !== 0 ) { var A = (p3[0] * (p2[1] - p1[1]) + p2[0] * (p1[1] - p3[1]) + p1[0] * (p3[1] - p2[1])) / denom; var B = ((p3[0] * p3[0]) * (p1[1] - p2[1]) + (p2[0] * p2[0]) * (p3[1] - p1[1]) + (p1[0] * p1[0]) * (p2[1] - p3[1])) / denom; var C = (p2[0] * p3[0] * (p2[0] - p3[0]) * p1[1] + p3[0] * p1[0] * (p3[0] - p1[0]) * p2[1] + p1[0] * p2[0] * (p1[0] - p2[0]) * p3[1]) / denom; return [ A, B, C ]; } else { return [ 0, 0, 0 ]; } }; // A and B can't be in the same place graph.pointA.onMove = function( x, y ) { if ( graph.invalid( [ x, y ], graph.pointB.coord, graph.pointC.coord ) ) { return false; } graph.pointA.coord = [ x, y ]; graph.drawParabola(); }; graph.pointB.onMove = function( x, y ) { if ( graph.invalid( graph.pointA.coord, [ x, y ], graph.pointC.coord ) ) { return false; } graph.pointB.coord = [ x, y ]; graph.drawParabola(); }; graph.pointC.onMove = function( x, y ) { if ( graph.invalid( graph.pointA.coord, graph.pointB.coord, [ x, y ] ) ) { return false; } graph.pointC.coord = [ x, y ]; graph.drawParabola(); }; graph.parabola = bogusShape; graph.drawParabola = function() { graph.parabola.remove(); var coeffs = graph.fitParabola( graph.pointA.coord, graph.pointB.coord, graph.pointC.coord ); style({ stroke: KhanUtil.BLUE }, function() { // Plot the parabola var a = coeffs[0], b = coeffs[1], c = coeffs[2]; graph.parabola = parabola(a, b, c); graph.parabola.toBack(); }); }; graph.drawParabola(); graph.showSolution = function() { $( "html, body" ).animate({ scrollTop:$( ".question" ).offset().top }, { duration: 500, easing: "swing", complete: function() { var coords = { x1: graph.pointA.coord[0], y1: graph.pointA.coord[1], x2: graph.pointB.coord[0], y2: graph.pointB.coord[1], x3: graph.pointC.coord[0], y3: graph.pointC.coord[1] }; \$( coords ).delay( 100 ).animate({ x1: X1, y1: Y1, x2: X2, y2: Y2, x3: H, y3: K }, { duration: 500, easing: "linear", step: function( now, fx ) { coords[ fx.prop ] = now; graph.pointA.setCoord([ coords.x1, coords.y1 ]); graph.pointB.setCoord([ coords.x2, coords.y2 ]); graph.pointC.setCoord([ coords.x3, coords.y3 ]); graph.drawParabola(); } }); } }); };
Drag the three points to graph the equation.
[graph.pointA.coord, graph.pointB.coord, graph.pointC.coord]
var coeffs = graph.fitParabola(graph.pointA.coord, graph.pointB.coord, graph.pointC.coord); if (coeffs[0] === 0 && coeffs[1] === 0 && coeffs[2] === 5) { return ""; } return abs(A - coeffs[0]) < 0.001 && abs((-2 * A * H) - coeffs[1]) < 0.001 && abs((A * H * H + K) - coeffs[2]) < 0.001;
graph.pointA.setCoord(guess[0]); graph.pointB.setCoord(guess[1]); graph.pointC.setCoord(guess[2]); graph.drawParabola();

\qquad y = A_DISP(x - H)^2 + K

y = A_DISPx^2 + -2 * A * Hx + A * H * H + K

We could try plugging in some different x-values, but instead of guessing it might be easier to convert the equation to vertex form.

Convert the equation to vertex form by completing the square. [Show me how]

First, move the constant term to the left side of the equation:

\qquad \begin{eqnarray} y &=& Ax^2 + -2 * A * Hx + A * H * H + K \\ \\ y + -A * H * H - K &=& Ax^2 + -2 * A * Hx \end{eqnarray}

Next, we can factor out a A from the right side:

\qquad y + -A * H * H - K = A_DISP(x^2 + -2 * Hx)

We can complete the square by taking half of the coefficient of our x term, squaring it, and adding it to both sides of the equation. The coefficient of our x term is -2 * H, so half of it would be -H, and squaring that gives us H * H. Because we're adding the H * H inside the parentheses on the right where it's being multiplied by A, we need to add A * H * H to the left side to make sure we're adding the same thing to both sides.

\qquad \begin{eqnarray} y + -A * H * H - K &=& A_DISP(x^2 + -2 * Hx) \\ \\ y + -A * H * H - K + \blue{A * H * H} &=& A_DISP(x^2 + -2 * Hx + \blue{H * H}) \\ \\ y - K &=& A_DISP(x^2 + -2 * Hx + H * H) \end{eqnarray}

Now we can rewrite the expression in parentheses as a squared term:

\qquad y - K = A_DISP(x - H)^2

Move the constant term to the right side of the equation. Now the equation is in vertex form:

\qquad y = A_DISP(x - H)^2 + K

\qquad y = A_DISP(x - H)^2 + K

When the equation is written in vertex form like this, the vertex is the point (h, k):

\qquad y = a(x - \green{h})^2 + \green{k}

\qquad y = A_DISP(x - \green{H})^2 + \green{K}

Examining our equation, we can see the vertex of the parabola is at (H, K).

style({ stroke: GREEN, strokeWidth: 3 }, function() { line( [ H - 0.3, K - 0.3 ], [ H + 0.3, K + 0.3 ] ).toBack(); line( [ H - 0.3, K + 0.3 ], [ H + 0.3, K - 0.3 ] ).toBack(); });

To find another point on the parabola, we can try plugging an x value into the equation.

Since the vertex is at x = H, let's try one unit to the right and evaluate the equation at x = X1.

\qquad \begin{eqnarray} A_DISP(\pink{x} - H)^2 + K &=& y \\ \\ A_DISP(\pink{X1} - H)^2 + K &=& \pink{Y1} \end{eqnarray}

Another point on the parabola is (X1, Y1)

style({ stroke: PINK, strokeWidth: 3 }, function() { line( [ X1 - 0.3, Y1 - 0.3 ], [ X1 + 0.3, Y1 + 0.3 ] ).toBack(); line( [ X1 - 0.3, Y1 + 0.3 ], [ X1 + 0.3, Y1 - 0.3 ] ).toBack(); });

A parabola has an axis of symmetry that passes through its vertex.

style({ stroke: GREEN, strokeDasharray: "-" }, function() { line( [ H, -11 ], [ H, 11 ] ).toBack(); });

Because the parabola is symmetric, we can reflect the point (X1, Y1) across the axis of symmetry to get another point, (X2, Y2), that must also be on the parabola.

style({ stroke: ORANGE, strokeWidth: 3 }, function() { line( [ X2 - 0.3, Y2 - 0.3 ], [ X2 + 0.3, Y2 + 0.3 ] ).toBack(); line( [ X2 - 0.3, Y2 + 0.3 ], [ X2 + 0.3, Y2 - 0.3 ] ).toBack(); });

There is only one graph of a parabola that passes through all three points we found.