|
29 | 29 | "df = data.frame(x = seq(-9, 8))\n", |
30 | 30 | "\n", |
31 | 31 | "# Add a y column by applying the quadratic equation to x\n", |
32 | | - "df$y = 2*df$x**2 + 2 *df$x - 4\n", |
| 32 | + "df$y = 2*df$x^2 + 2 *df$x - 4\n", |
33 | 33 | "\n", |
34 | 34 | "## Plot the parabola\n", |
35 | 35 | "library(ggplot2)\n", |
|
63 | 63 | "df = data.frame(x = seq(-8,11))\n", |
64 | 64 | "\n", |
65 | 65 | "# Add a y column by applying the quadratic equation to x\n", |
66 | | - "df$y = -2*df$x**2 + 6*df$x + 7\n", |
| 66 | + "df$y = -2*df$x^2 + 6*df$x + 7\n", |
67 | 67 | "\n", |
68 | 68 | "## Plot the parabola\n", |
69 | 69 | "library(ggplot2)\n", |
|
107 | 107 | " vx = (-1*b)/(2*a)\n", |
108 | 108 | " \n", |
109 | 109 | " # get the y value when x is at the line of symmetry\n", |
110 | | - " vy = a*vx**2 + b*vx + c\n", |
| 110 | + " vy = a*vx^2 + b*vx + c\n", |
111 | 111 | "\n", |
112 | 112 | " # Create a dataframe with an x column containing values from x-10 to x+10\n", |
113 | 113 | " minx = as.integer(vx - 10)\n", |
114 | 114 | " maxx = as.integer(vx + 10)\n", |
115 | 115 | " df = data.frame(x = seq(minx, maxx))\n", |
116 | 116 | " \n", |
117 | 117 | " # Add a y column by applying the quadratic equation to x\n", |
118 | | - " df$y = a*df$x**2 + b*df$x + c\n", |
| 118 | + " df$y = a*df$x^2 + b*df$x + c\n", |
119 | 119 | "\n", |
120 | 120 | " # get min and max y values\n", |
121 | 121 | " miny = min(df$y)\n", |
|
143 | 143 | "metadata": {}, |
144 | 144 | "source": [ |
145 | 145 | "## Parabola Intercepts\n", |
| 146 | + "\n", |
146 | 147 | "Recall that linear equations create lines that intersect the **x** and **y** axis of a graph, and we call the points where these intersections occur *intercepts*. Now look at the graphs of the parabolas we've worked with so far. Note that these parabolas both have a y-intercept; a point where the line intersects the y axis of the graph (in other words, when x is 0). However, note that the parabolas have *two* x-intercepts; in other words there are two points at which the line crosses the x axis (and y is 0). Additionally, imagine a downward opening parabola with its vertex at -1, -1. This is perfectly possible, and the line would never have an x value greater than -1, so it would have *no* x-intercepts.\n", |
147 | 148 | "\n", |
148 | 149 | "Regardless of whether the parabola crosses the x axis or not, other than the vertex, for every ***y*** point in the parabola, there are *two* ***x*** points; one on the right (or positive) side of the axis of symmetry, and one of the left (or negative) side. The implications of this are what make quadratic equations so interesting. When we solve the equation for ***x***, there are *two* correct answers.\n", |
|
191 | 192 | " vx = (-1*b)/(2*a)\n", |
192 | 193 | " \n", |
193 | 194 | " # get the y value when x is at the line of symmetry\n", |
194 | | - " vy = a*vx**2 + b*vx + c\n", |
| 195 | + " vy = a*vx^2 + b*vx + c\n", |
195 | 196 | "\n", |
196 | 197 | " # Create a dataframe with an x column containing values from x-10 to x+10\n", |
197 | 198 | " minx = as.integer(vx - 10)\n", |
198 | 199 | " maxx = as.integer(vx + 10)\n", |
199 | 200 | " df = data.frame(x = seq(minx, maxx))\n", |
200 | 201 | " \n", |
201 | 202 | " # Add a y column by applying the quadratic equation to x\n", |
202 | | - " df$y = a*df$x**2 + b*df$x + c\n", |
| 203 | + " df$y = a*df$x^2 + b*df$x + c\n", |
203 | 204 | "\n", |
204 | 205 | " # get min and max y values\n", |
205 | 206 | " miny = min(df$y)\n", |
|
278 | 279 | "df = data.frame(x = seq(x1-10, x2+10))\n", |
279 | 280 | "\n", |
280 | 281 | "# Add a y column by applying the quadratic equation to x\n", |
281 | | - "df$y = 3*df$x**2 - 12\n", |
| 282 | + "df$y = 3*df$x^2 - 12\n", |
282 | 283 | "\n", |
283 | 284 | "# Get x at the line of symmetry (halfway between x1 and x2)\n", |
284 | 285 | "vx = (x1 + x2) / 2\n", |
285 | 286 | "\n", |
286 | 287 | "# Get y when x is at the line of symmetry\n", |
287 | | - "vy = 3*vx**2 - 12\n", |
| 288 | + "vy = 3*vx^2 - 12\n", |
288 | 289 | "\n", |
289 | 290 | "# get min and max y values\n", |
290 | 291 | "miny = min(df$y)\n", |
|
372 | 373 | "df = data.frame(x = seq(x1-10, x2+10))\n", |
373 | 374 | "\n", |
374 | 375 | "# Add a y column by applying the quadratic equation to x\n", |
375 | | - "df$y = ((df$x + 3)**2) - 16\n", |
| 376 | + "df$y = ((df$x + 3)^2) - 16\n", |
376 | 377 | "\n", |
377 | 378 | "# Get x at the line of symmetry (halfway between x1 and x2)\n", |
378 | 379 | "vx = (x1 + x2) / 2\n", |
379 | 380 | "\n", |
380 | 381 | "# Get y when x is at the line of symmetry\n", |
381 | | - "vy = ((vx + 3)**2) - 16\n", |
| 382 | + "vy = ((vx + 3)^2) - 16\n", |
382 | 383 | "\n", |
383 | 384 | "# get min and max y values\n", |
384 | 385 | "miny = min(df$y)\n", |
|
441 | 442 | "source": [ |
442 | 443 | "x = sample.int(100, 1)\n", |
443 | 444 | "\n", |
444 | | - "2*x**2 - 16*x + 2 == 2*(x - 4)**2 - 30" |
| 445 | + "2*x^2 - 16*x + 2 == 2*(x - 4)^2 - 30" |
445 | 446 | ] |
446 | 447 | }, |
447 | 448 | { |
|
482 | 483 | " df = data.frame(x = seq(h-10, h+10))\n", |
483 | 484 | " \n", |
484 | 485 | " # Add a y column by applying the quadratic equation to x\n", |
485 | | - " df$y = (a*(df$x - h)**2) + k\n", |
| 486 | + " df$y = (a*(df$x - h)^2) + k\n", |
486 | 487 | "\n", |
487 | 488 | " # get min and max y values\n", |
488 | 489 | " miny = min(df$y)\n", |
489 | 490 | " maxy = max(df$y)\n", |
490 | 491 | " \n", |
491 | 492 | " # calculate y when x is 0 (h+-h)\n", |
492 | | - " y = a*(0 - h)**2 + k\n", |
| 493 | + " y = a*(0 - h)^2 + k\n", |
493 | 494 | " \n", |
494 | 495 | " ## data frame for line of symmetry\n", |
495 | 496 | " symmetry = data.frame(sx = c(h,h), sy = c(miny,maxy))\n", |
|
627 | 628 | " print(paste('vy =', toString(a), '(', toString(vx), '^2) + ', \n", |
628 | 629 | " toString(b), '(', toString(vx), ') + ', toString(c)))\n", |
629 | 630 | "\n", |
630 | | - " avx2 = a*vx**2\n", |
| 631 | + " avx2 = a*vx^2\n", |
631 | 632 | " bvx = b*vx\n", |
632 | 633 | " print(paste('vy =', toString(avx2), ' + ', toString(bvx), ' + ', toString(c)))\n", |
633 | 634 | "\n", |
|
642 | 643 | " print('CALCULATING -x AND +x FOR y=0')\n", |
643 | 644 | " print('x = -b +- sqrt(b^2 - 4ac) / 2a')\n", |
644 | 645 | " \n", |
645 | | - " b2 = b**2\n", |
| 646 | + " b2 = b^2\n", |
646 | 647 | " ac4 = 4*a*c\n", |
647 | 648 | " print(paste('x = ', toString(nb), '+-sqrt(', toString(b2), \n", |
648 | 649 | " ' - ', toString(ac4), ')/', toString(a2)))\n", |
|
664 | 665 | " df = data.frame(x = seq(round(vx)-10, round(vx)+10))\n", |
665 | 666 | " \n", |
666 | 667 | " # Add a y column by applying the quadratic equation to x\n", |
667 | | - " df$y = a*df$x**2 + b*df$x + c\n", |
| 668 | + " df$y = a*df$x^2 + b*df$x + c\n", |
668 | 669 | "\n", |
669 | 670 | " # get min and max y values\n", |
670 | 671 | " miny = min(df$y)\n", |
|
0 commit comments