(************** Content-type: application/mathematica ************** Mathematica-Compatible Notebook This notebook can be used with any Mathematica-compatible application, such as Mathematica, MathReader or Publicon. The data for the notebook starts with the line containing stars above. To get the notebook into a Mathematica-compatible application, do one of the following: * Save the data starting with the line of stars above into a file with a name ending in .nb, then open the file inside the application; * Copy the data starting with the line of stars above to the clipboard, then use the Paste menu command inside the application. Data for notebooks contains only printable 7-bit ASCII and can be sent directly in email or through ftp in text mode. Newlines can be CR, LF or CRLF (Unix, Macintosh or MS-DOS style). NOTE: If you modify the data for this notebook not in a Mathematica- compatible application, you must delete the line below containing the word CacheID, otherwise Mathematica-compatible applications may try to use invalid cache data. For more information on notebooks and Mathematica-compatible applications, contact Wolfram Research: web: http://www.wolfram.com email: info@wolfram.com phone: +1-217-398-0700 (U.S.) Notebook reader applications are available free of charge from Wolfram Research. *******************************************************************) (*CacheID: 232*) (*NotebookFileLineBreakTest NotebookFileLineBreakTest*) (*NotebookOptionsPosition[ 27331, 781]*) (*NotebookOutlinePosition[ 28072, 806]*) (* CellTagsIndexPosition[ 28028, 802]*) (*WindowFrame->Normal*) Notebook[{ Cell[CellGroupData[{ Cell["Using Vectors to Represent Lines and Find Distances", "Title"], Cell[TextData[StyleBox["Chapter 9, Sections 1 & 2", FontFamily->"Arial", FontSize->16, FontWeight->"Bold"]], "Text"], Cell[CellGroupData[{ Cell["Introduction", "Section"], Cell["\<\ OBJECTIVE: Visualize and interpret the use of vectors to represent lines in \ the plane.\ \>", "Text"], Cell["\<\ Do you remember how you first learned about the equations of lines in a \ plane? In this module, you will gain insight into why it is to your advantage \ to interpret lines in the plane using vectors.\ \>", "Text"], Cell[CellGroupData[{ Cell["Technology Guidelines", "Subsection", CellDingbat->"\[LightBulb]"], Cell[TextData[{ StyleBox["NOTE: If you have just finished a module, restart ", CellFrame->True, Background->None], StyleBox["Mathematica", CellFrame->True, FontSlant->"Italic", Background->None], StyleBox[ " before executing a new module.\nTO OPEN CELLS, put your cursor on the \ right cell bracket and double click.", CellFrame->True, Background->None], "\nTO STOP AN EXECUTION\n\tSelect the ", StyleBox["Kernel", FontSlant->"Italic"], " pull-down menu and click on ", StyleBox["Abort Evaluation.\n", FontSlant->"Italic"], "ORDER OF EXECUTION\n\tExecute cells in the order given. Do not skip any \ Input cells within a given notebook.\nSAVING NOTEBOOKS\n\tYou can save \ anytime to any directory you choose, and it is wise to save often.\n\t\ However, before you do your final save, delete all your output by selecting \ the \n\t ", StyleBox["Delete All Output", FontSlant->"Italic"], " selection under the ", StyleBox["Kernel", FontSlant->"Italic"], " pull-down menu.\nEXPERIENCING MAJOR PROBLEMS\n\tSave if appropriate, and \ then shut down ", StyleBox["Mathematica", FontSlant->"Italic"], " and start it up again." }], "Text"] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell["Part I: Interpreting Lines Using Their Vector Definition", "Section"], Cell[TextData[{ "You can construct straight lines in two dimensions using the vector \ definition. Given two points on the line, you will first determine the \ direction of the line and then write any other point on the line as the \ position vector to that point plus a multiple (", StyleBox["t", FontSlant->"Italic"], ") of the vector in the direction of the line. We plot points along the \ line corresponding to different values of the parameter ", StyleBox["t", FontSlant->"Italic"], ". Our example uses points ", Cell[BoxData[ \(TraditionalForm\`\((1, 5)\)\)]], " and", Cell[BoxData[ \(TraditionalForm\`\(\ \((4, 2)\)\)\)]], " and we plot points for values of ", StyleBox["t", FontSlant->"Italic"], " from ", Cell[BoxData[ \(TraditionalForm\`\(-10\)\)]], " to ", Cell[BoxData[ \(TraditionalForm\`10\)]], "." }], "Text"], Cell[BoxData[{ \(Off[General::spell]\), \(Off[General::spell1]\), \(Clear[x, y, t]\), \(origin = {0, 0}; \np1 = {1, 5}; \np2 = {4, 2}; \n Print["\", dir = p1 - p2]\), \(Print["\<{x,y} = \>", eq = \((p1 - origin)\) + t\ dir]\), \(\(ParametricPlot[Evaluate[eq], {t, \(-10\), 10}, AxesLabel -> {x, y}]; \)\)}], "Input"] }, Closed]], Cell[CellGroupData[{ Cell["You Try It - Part I", "Section"], Cell[TextData[{ "Write and plot the line connecting the points ", Cell[BoxData[ \(TraditionalForm\`\((\(-23\), \ \(-5\))\)\)]], " and ", Cell[BoxData[ \(TraditionalForm\`\((10, \ 12)\)\)]], " in parametric form.\nYou need to identify and enter the new points for ", StyleBox["p1", FontSlant->"Italic"], " and ", StyleBox["p2", FontSlant->"Italic"], " on the line and re-execute the input cell. Simply replace the numbers in \ red." }], "Text"], Cell[BoxData[{ RowBox[{\(origin = {0, 0}\), ";", "\n", RowBox[{"p1", "=", RowBox[{"{", RowBox[{ StyleBox["1", FontColor->RGBColor[1, 0, 0]], StyleBox[",", FontColor->RGBColor[1, 0, 0]], StyleBox["1", FontColor->RGBColor[1, 0, 0]]}], "}"}]}], ";", "\n", RowBox[{"p2", "=", RowBox[{"{", RowBox[{ StyleBox["2", FontColor->RGBColor[1, 0, 0]], StyleBox[",", FontColor->RGBColor[1, 0, 0]], StyleBox["2", FontColor->RGBColor[1, 0, 0]]}], "}"}]}], ";", "\n", \(Print["\", dir = p1 - p2]\)}], \(Print["\<{x,y} = \>", eq = \((p1 - origin)\) + t\ dir]\), \(plot1 = ParametricPlot[Evaluate[eq], {t, \(-10\), 10}, AxesLabel -> {x, y}]; \)}], "Input"], Cell[TextData[{ " For the preceding function, match the parametric plot with the standard \ Cartesian form and plot. You need to solve for ", StyleBox["y", FontSlant->"Italic"], " as a function of ", StyleBox["x", FontSlant->"Italic"], " and put that into the expression for ", Cell[BoxData[ \(TraditionalForm\`f[x_]\)]], ". Replace the expression in red with the appropriate expression." }], "Text"], Cell[BoxData[{ RowBox[{\(f[x_]\), ":=", " ", StyleBox["x", FontColor->RGBColor[1, 0, 0]]}], \(pf = Plot[f[x], {x, \(-300\), 300}, PlotStyle -> RGBColor[1, 0, 0], AxesLabel -> {"\", "\"}]; \nShow[plot1, pf]; \)}], "Input"] }, Closed]], Cell[CellGroupData[{ Cell["Part II: Different Parametric Forms for the Same Line", "Section"], Cell[TextData[{ "Write the equation of the line ", Cell[BoxData[ \(TraditionalForm\`y\ = \ 3 x\ - \ 5\)]], " in parametric form. \nYou may be accustomed to seeing equations of lines \ in the standard slope intercept form. That form is a unique representation. \ In contrast, the parametric form can appear in different forms; however, the \ set of points represented is the same." }], "Text"], Cell[TextData[{ "If we take the direction vector from the slope to be ", Cell[BoxData[ \(TraditionalForm\`\((1, 3)\)\)]], " and use the ", StyleBox["y", FontSlant->"Italic"], "-intercept ", Cell[BoxData[ \(TraditionalForm\`\((0, 5)\)\)]], " as our given point on the line, we get the following." }], "Text"], Cell[BoxData[{ \(Clear[x, f]\), \(origin = {0, 0}; \ndir = {1, 3}; \np1 = {0, \(-5\)}; \n Print["\<{x,y} = \>", eq = \((p1 - origin)\) + t\ dir]\), \(\(plot1 = ParametricPlot[Evaluate[eq], {t, \(-3\), 5}, AxesLabel -> {x, y}, PlotStyle -> RGBColor[0, 1, 0]]; \)\)}], "Input"], Cell[TextData[{ "Had we used a different point on the line, for example,", Cell[BoxData[ \(TraditionalForm\`\(\ \((2, 1)\)\)\)]], ", and written the slope as ", Cell[BoxData[ \(TraditionalForm\`\(\((2, \ 6)\), \)\)]], " the equation would look a bit different, although it would produce the \ same line." }], "Text"], Cell[BoxData[{ \(Clear[x, f]\), \(dir = {2, 6}; \np2 = {2, 1}; \n Print["\<{x,y} = \>", eq = \((p2 - origin)\) + t\ dir]\), \(\(plot2 = ParametricPlot[Evaluate[eq], {t, \(-1\), 3}, AxesLabel -> {x, y}, PlotStyle -> RGBColor[0, 0, 1]]; \)\)}], "Input"], Cell["We can look at these graphs together.", "Text"], Cell[BoxData[ \(\(Show[plot1, plot2]; \)\)], "Input"], Cell[TextData[{ "Note that the parameter ", StyleBox["t", FontSlant->"Italic"], " is not the same in the two equations. However, all the points lie on the \ same line, even though we are plotting only segments of that line.\n\n For \ the preceding function, match the parametric plot with the standard Cartesian \ form and plot." }], "Text"], Cell[BoxData[{ \(f[x_] := 3 x - 5\), \(pf = Plot[f[x], {x, \(-1\), 5}, PlotStyle -> RGBColor[1, 0, 0], AxesLabel -> {"\", "\"}]; \nShow[plot1, plot2, pf]; \)}], "Input"], Cell["Do they match?", "Text"] }, Closed]], Cell[CellGroupData[{ Cell["You Try It - Part II", "Section"], Cell[TextData[{ "Write the line ", Cell[BoxData[ \(TraditionalForm\`4 x\ + \ 5 y\ = \ 12\)]], " in parametric form. \nYou need to identify a point on the line and a \ vector in the direction of the line. Substitute these for ", StyleBox["dir", FontWeight->"Bold"], " and ", StyleBox["p1", FontWeight->"Bold"], " (items in red), and re-execute the input cell. " }], "Text"], Cell[BoxData[{ RowBox[{ RowBox[{"dir", "=", RowBox[{"{", StyleBox[\(1, 2\), FontColor->RGBColor[1, 0, 0]], "}"}]}], ";", "\n", RowBox[{"p1", "=", RowBox[{"{", StyleBox[\(1, 1\), FontColor->RGBColor[1, 0, 0]], "}"}]}], ";", "\n", \(Print["\<{x,y} = \>", eq = \((p1 - origin)\) + t\ dir]\)}], \(plot1 = ParametricPlot[Evaluate[eq], {t, \(-3\), 5}, AxesLabel -> {x, y}, PlotStyle -> RGBColor[0, 1, 0]]; \)}], "Input"], Cell[TextData[{ "For the preceding function, match the parametric plot with the standard \ Cartesian form and plot. \nYou need to solve for ", StyleBox["y", FontSlant->"Italic"], " as a function of x and put that into the expression for ", Cell[BoxData[ \(TraditionalForm\`f[x_]\)]], ". Replace the red with the appropriate expression." }], "Text"], Cell[BoxData[{ RowBox[{\(f[x_]\), ":=", StyleBox[\(2 x - 1\), FontColor->RGBColor[1, 0, 0]]}], \(pf = Plot[f[x], {x, \(-1\), 5}, PlotStyle -> RGBColor[1, 0, 0], AxesLabel -> {"\", "\"}]; \nShow[plot1, pf]; \)}], "Input"] }, Closed]], Cell[CellGroupData[{ Cell["Part III: Finding the Distance from a Point to a Line", "Section"], Cell[TextData[{ "Suppose you are driving on a long, straight road on a flat planar region \ of desert land. You have a grid-map of the region and have been told that \ there is a radiation site in the at the point ", Cell[BoxData[ \(TraditionalForm\`\((230, \ \(-500\))\)\)]], ". You started at the point ", Cell[BoxData[ \(TraditionalForm\`\((\(-400\), \ 350)\)\)]], " and are traveling in a path that is always in the direction of the vector \ ", Cell[BoxData[ \(TraditionalForm\`\((1, \ \(-2\))\)\)]], ". You are worried about how close to the radiation site you will pass.\n\n\ Let's begin by visualizing the problem." }], "Text"], Cell[BoxData[{ \(origin = {0, 0}; \nsite = {230, \(-500\)}; \nstart = {\(-400\), 350}; \n dir = {1, \ \(-2\)}; \n Print["\<{x,y} = \>", eq = \((start - origin)\) + t\ dir]\), \(pp = ParametricPlot[Evaluate[eq], {t, 0, 700}, AxesLabel -> {x, y}, DisplayFunction -> Identity]; \n rad = ListPlot[{site}, PlotStyle -> PointSize[ .02], DisplayFunction -> Identity]; \n Show[pp, rad, DisplayFunction -> $DisplayFunction]; \)}], "Input"], Cell["\<\ Consider the vector from the starting point to the radiation site.\ \>", "Text"], Cell[BoxData[ \(vector = site - start; \n vp = ListPlot[{start, site}, PlotJoined -> True, DisplayFunction -> Identity]; \n Show[pp, rad, vp, DisplayFunction -> $DisplayFunction]; \)], "Input"], Cell[TextData[{ "Now, use the dot product to find the projection of this vector onto a \ direction perpendicular to the line. That will represent the shortest \ distance between the radiation site and the road.\n\nFinding the \ perpendicular to a vector in two-space is very easy. Think of how \ perpendicular lines have slopes that are negative reciprocals of each other. \ You will find the perpendicular to the line by simply reversing the ", StyleBox["x", FontSlant->"Italic"], " and ", StyleBox["y", FontSlant->"Italic"], " components of the direction vector and negating one of them." }], "Text"], Cell[BoxData[ \(perpdir = {\(-dir[\([2]\)]\), dir[\([1]\)]}\)], "Input"], Cell["\<\ Then to find the projection of the vector connecting the starting point with \ the radiation site onto this perpendicular direction, use the dot product of \ those two vectors and divide by the magnitude of the perpendicular vector.\ \>", "Text"], Cell[BoxData[ \(distance = Abs[vector . perpdir]/\@\(perpdir . perpdir\) // N\)], "Input"] }, Closed]], Cell[CellGroupData[{ Cell["You Try It: Part III", "Section"], Cell[TextData[{ "Find the shortest distance from the line ", Cell[BoxData[ \(TraditionalForm\`4 x\ + \ 5 y\ = \ 12\)]], " to the point ", Cell[BoxData[ \(TraditionalForm\`\((\(-2\), 3)\)\)]], ".\nIn the following set of commands, put in the new site, select a point \ on the line, and identify the direction of the line. To do this, just replace \ the red with the appropriate expressions." }], "Text"], Cell[BoxData[{ RowBox[{\(origin = {0, 0}\), ";", "\n", RowBox[{"site", "=", RowBox[{"{", StyleBox[\(1, 1\), FontColor->RGBColor[1, 0, 0]], "}"}]}], ";", "\n", RowBox[{"start", "=", RowBox[{"{", StyleBox[\(2, 2\), FontColor->RGBColor[1, 0, 0]], "}"}]}], ";", "\n", RowBox[{"dir", "=", RowBox[{"{", StyleBox[\(\(-3\), 3\), FontColor->RGBColor[1, 0, 0]], "}"}]}], ";", "\n", \(Print["\<{x,y} = \>", eq = \((start - origin)\) + t\ dir]\)}], \(pp = ParametricPlot[Evaluate[eq], {t, \(-10\), 10}, AxesLabel -> {x, y}, DisplayFunction -> Identity]; \n rad = ListPlot[{site}, PlotStyle -> PointSize[ .02], DisplayFunction -> Identity]; \n Show[pp, rad, DisplayFunction -> $DisplayFunction]; \n vector = site - start; \nperpdir = {\(-dir[\([2]\)]\), dir[\([1]\)]}; \n distance = Abs[vector . perpdir]/\@\(perpdir . perpdir\) // N; \n Print["\", distance]\)}], "Input"] }, Closed]], Cell[CellGroupData[{ Cell["Part IV: Apply the Dot Product to Find a Line of Best Fit", "Section"], Cell[CellGroupData[{ Cell["\<\ Looking for Cause and Effect:Temperature as a Function of Latitude\ \>", "Subsection"], Cell["\<\ Following is data showing 56 cities in the U. S. together with their average \ January temperatures (in degrees Fahrenheit) over a thirty-year period and \ their latitudes.\ \>", "Text"], Cell[BoxData[{ \(Off[General::spell]\ \), "\n", \(Off[General::spell1]\ \), "\n", \(Off[Set::write]\), "\n", \(\(\(city = {MobileAL, MontgomeryAL, PhoenixAZ, LittleRockAR, Los\ AngelesCA, San\ FranciscoCA, DenverCO, NewHavenCT, WilmingtonDE, WashingtonDC, JacksonvilleFL, KeyWestFL, MiamiFL, AtlantaGA, BoiseID, ChicagoIL, IndianapolisIN, DesMoinesIA, WichitaKS, LouisvilleKY, NewOrleansLA, PortlandME, BaltimoreMD, BostonMA, DetroitMI, MinneapolisMN, St . LouisMO, HelenaMT, OmahaNE, ConcordNH, AtlanticCityNJ, AlbuquerqueNM, AlbanyNY, NewYorkNY, CharlotteNC, RaleighNC, BismarckND, CincinnatiOH, ClevelandOH, OklahomaCityOK, PortlandOR, HarrisburgPA, PhiladelphiaPA, CharlestonSC, NashvilleTN, AmarilloTX, GalvestonTX, HoustonTX, SaltLakeCityUT, BurlingtonVT, NorfolkVA, SeattleWA, SpokaneWA, MadisonWI, MilwaukeeWI, CheyenneWY};\)\(\n\) \)\), "\n", \(\(\(januarytemp = {44, 38, 35, 31, 47, 42, 15, 22, 26, 30, 45, 65, 58, 37, 22, 19, 21, 11, 22, 27, 45, 12, 25, 23, 21, 2, 24, 8, 13, 11, 27, 24, 14, 27, 34, 31, 0, 26, 21, 28, 33, 24, 24, 38, 31, 24, 49, 44, 18, 7, 32, 33, 19, 9, 13, 14};\)\(\n\) \)\), "\n", \(\(\(latitude = {31.2, 32.9, 33.6, 35.4, 34.3, 38.4, 40.7, 41.7, 40.5, 39.7, 31, 25, 26.3, 33.9, 43.7, 42.3, 39.8, 41.8, 38.1, 39, 30.8, 44.2, 39.7, 42.7, 43.1, 45.9, 39.3, 47.1, 41.9, 43.5, 39.8, 35.1, 42.6, 40.8, 35.9, 36.4, 47.1, 39.2, 42.3, 35.9, 45.6, 40.9, 40.9, 33.3, 36.7, 35.6, 29.4, 30.1, 41.1, 45, 37, 48.1, 48.1, 43.4, 43.3, 41.2};\)\(\n\) \)\), "\[IndentingNewLine]", \(Clear[citydata]\), "\n", \(\(citydata = Table[{city[\([i]\)], januarytemp[\([i]\)], latitude[\([i]\)]}, {i, 1, Length[city]}];\)\), "\[IndentingNewLine]", \(\(PrependTo[ citydata, {City, January\ Temperature, Latitude}];\)\), "\[IndentingNewLine]", \(citydata // TableForm\)}], "Input"], Cell["\<\ First do a scatterplot to see if there is a relationship between the January \ temperatures and latitude.\ \>", "Text"], Cell[BoxData[ \(\(scatter = ListPlot[ Table[{latitude[\([i]\)], januarytemp[\([i]\)]}, {i, 1, Length[latitude]}], AxesLabel -> {"\", January\ Temperature}, PlotStyle -> PointSize[ .015]];\)\)], "Input"], Cell["\<\ Since the scatterplot appears to have somewhat of a linear pattern, with the \ average January temperature dropping as the latitude increases, we will \ investigate this relationship further. We will use Mathematica's built-in Fit \ function to get results. Note that you choose a linear fit by specifying the \ {x,1}. We can write the line of best fit as follows.\ \>", "Text"], Cell[BoxData[ \(yfit = Fit[Table[{latitude[\([i]\)], januarytemp[\([i]\)]}, {i, 1, Length[latitude]}], {x, 1}, x]\)], "Input"], Cell["Now we can plot this line with our scatterplot.", "Text"], Cell[BoxData[{ \(\(linearfit = Plot[yfit, {x, 20, 50}, DisplayFunction \[Rule] Identity];\)\), "\n", \(\(Show[scatter, linearfit, DisplayFunction \[Rule] $DisplayFunction];\)\)}], "Input"], Cell[TextData[StyleBox[" Can you identify cities that deviate from the \ pattern? Might you speculate on the reason for the deviation? Name one \ important factor that might explain at least a part of this deviation.", FontColor->RGBColor[1, 0, 0]]], "Text"] }, Closed]], Cell[CellGroupData[{ Cell["Dot Product Approach", "Subsection"], Cell["\<\ If the data sets for the latitude and the januarytemp are scaled around their \ means, the dot product can be used to determine how closely aligned the two \ sets of data are. The following commands will effectively accomplish the \ necessary scaling and define the dot product of two vectors and the magnitude \ of a vector in terms of a dot product. Note that the dot product is arrived \ at with the use of a \"period\" between two vectors, rather than the times \ sign.\ \>", "Text"], Cell[BoxData[{ \(mean[x_] := Sum[x[\([i]\)], {i, 1, Length[x]}]/Length[x]\), "\n", \(scaled[x_] := Table[x[\([i]\)] - mean[x], {i, 1, Length[x]}]\), "\n", \(dot[x_, y_] := scaled[x] . scaled[y]\), "\n", \(magnitude[x_] := Sqrt[dot[x, x]]\)}], "Input"], Cell["\<\ Recall that the cosine of the angle between two vectors can be found by \ taking the dot product and then dividing by the magnitude of each vector. \ When the cosine is fairly near +1 or -1, the vectors are closely aligned. In \ statistics, we call the cosine of this angle the correlation coefficient (r), \ and its square measures the percent of change in the dependent variable (y) \ that can be attributed to that variables linear relationship with the \ independent variable (x). Furthermore, the slope of the line that best describes the linear \ relationship between x and y is this cosine value times the ratio of the \ magnitude of y over the magnitude of x.\ \>", "Text"], Cell[BoxData[{ \(slope[x_, y_] := dot[x, y]/dot[x, x]\), "\n", \(correlation[x_, y_] := dot[x, y]/\((magnitude[x] magnitude[y])\)\)}], "Input"], Cell["\<\ Now, thinking of latitude as the independent variable (x) and januarytemp as \ the dependent variable (y), we will find the slope and correlation \ coefficient.\ \>", "Text"], Cell[BoxData[{ \(Print[\n\t"\", slope[latitude, januarytemp]]\), "\n", \(Print["\", r = correlation[latitude, januarytemp]]\), "\n", \(Print[\*"\"\<\!\(r\^2\) = \>\"", correlation[latitude, januarytemp]\^2]\)}], "Input"], Cell["\<\ Using this slope and rescaling the two variables, we can write the line of \ best fit as follows.\ \>", "Text"], Cell[BoxData[{ \(Clear[x]\), "\n", \(y = mean[januarytemp] + slope[latitude, januarytemp] \((x - mean[latitude])\) // Simplify\)}], "Input"], Cell["\<\ How do your two results compare to the fit function found above? \ \>", "Text"] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell["You Try It: Part IV", "Section"], Cell[TextData[{ StyleBox["Age and EEG", FontSize->14, FontSlant->"Italic"], "\nThe electroencephalogram (EEG) is a device used to measure brain waves. \ Neurologists have found that the peak EEG frequency in children increases \ with age. The data below represents the results of a study done on children \ age 2 through 16 and the EEG readings (in hertz) represent the average peak \ EEG frequencies for each age group. It would be reasonable to think of age as \ the independent variable and eeg as the dependent variable." }], "Text"], Cell[BoxData[{ \(\(age = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};\)\), "\n", \(\(eeg = {5.33, 5.75, 5.80, 5.60, 6.00, 5.78, 5.90, 6.23, 7.28, 7.06, 7.60, 7.45, 8.23, 8.50, 9.38};\)\), "\n", \(\(eegdata = Table[{age[\([i]\)], eeg[\([i]\)]}, {i, 1, Length[age]}];\)\), "\n", \(eegdata // TableForm\), "\n", \(\(scatter = ListPlot[eegdata];\)\)}], "Input"], Cell["\<\ Using the above names for the independent and dependent data sets, replace \ the terms in red with the appropriate names and execute the commands.\ \>", "Text"], Cell[BoxData[{ RowBox[{"Print", "[", "\n", "\t", RowBox[{"\"\\"", ",", RowBox[{"slope", "[", StyleBox[\(latitude, januarytemp\), FontColor->RGBColor[1, 0, 0]], "]"}]}], "]"}], "\n", RowBox[{"Print", "[", RowBox[{"\"\\"", ",", RowBox[{"correlation", "[", StyleBox[\(latitude, januarytemp\), FontColor->RGBColor[1, 0, 0]], "]"}]}], "]"}], "\n", RowBox[{"Print", "[", RowBox[{"\"\<\!\(r\^2\) = \>\"", ",", SuperscriptBox[ RowBox[{"correlation", "[", StyleBox[\(latitude, januarytemp\), FontColor->RGBColor[1, 0, 0]], "]"}], "2"]}], "]"}]}], "Input"], Cell["\<\ Using this slope and rescaling the two variables, EXPLAIN WHY we can write \ the line of best fit as follows.\ \>", "Text"], Cell[BoxData[{\(Clear[x]\), "\n", RowBox[{"y", "=", RowBox[{ RowBox[{ RowBox[{"mean", "[", StyleBox["januarytemp", FontColor->RGBColor[1, 0, 0]], "]"}], "+", RowBox[{ RowBox[{"slope", "[", StyleBox[\(latitude, januarytemp\), FontColor->RGBColor[1, 0, 0]], "]"}], RowBox[{"(", RowBox[{"x", "-", RowBox[{"mean", "[", StyleBox["latitude", FontColor->RGBColor[1, 0, 0]], "]"}]}], ")"}]}]}], "//", "Simplify"}]}]}], "Input"], Cell["Now we can plot this line with our scatterplot.", "Text"], Cell[BoxData[{ RowBox[{ RowBox[{"linearfit", "=", RowBox[{"Plot", "[", RowBox[{"y", ",", RowBox[{"{", RowBox[{"x", ",", RowBox[{"Min", "[", StyleBox["latitude", FontColor->RGBColor[1, 0, 0]], "]"}], ",", RowBox[{"Max", "[", StyleBox["latitude", FontColor->RGBColor[1, 0, 0]], "]"}]}], "}"}], ",", StyleBox[\(DisplayFunction -> Identity\), "MR"]}], " ", "]"}]}], ";"}], "\n", \(Show[scatter, linearfit];\)}], "Input"], Cell["\<\ Next, we will compare Mathematica's built-in Fit function to our own results. \ Note that we choose a linear fit by specifying the {x,1}.\ \>", "Text"], Cell[BoxData[ RowBox[{"yfit", "=", RowBox[{"Fit", "[", RowBox[{ RowBox[{"Table", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{ StyleBox["latitude", FontColor->RGBColor[1, 0, 0]], "[", \([i]\), "]"}], ",", RowBox[{ StyleBox["januarytemp", FontColor->RGBColor[1, 0, 0]], "[", \([i]\), "]"}]}], "}"}], ",", RowBox[{"{", RowBox[{"i", ",", "1", ",", RowBox[{"Length", "[", StyleBox["latitude", FontColor->RGBColor[1, 0, 0]], "]"}]}], "}"}]}], "]"}], ",", \({x, 1}\), ",", "x"}], "]"}]}]], "Input"], Cell[TextData[{ "To test to see if our dot product results agree with the Fit function \ results, we can ask ", StyleBox["Mathematica", FontSlant->"Italic"], " that question with the double equal sign." }], "Text"], Cell[BoxData[ \(y == yfit\)], "Input"], Cell["\<\ Check to see how good the fit is by interpreting the cosine of the angle \ between the vectors for age and eeg.\ \>", "Text"], Cell[BoxData[{ \(Print["\", corr = correlation[age, eeg]]\), "\[IndentingNewLine]", \(Print["\", ArcCos[corr]*180/\[Pi], "\< degrees\>"]\)}], "Input"] }, Closed]] }, Open ]] }, FrontEndVersion->"4.1 for Microsoft Windows", ScreenRectangle->{{0, 1024}, {0, 695}}, WindowSize->{712, 517}, WindowMargins->{{61, Automatic}, {Automatic, 78}}, PrintingCopies->1, PrintingPageRange->{Automatic, Automatic}, StyleDefinitions -> "Default.nb" ] (******************************************************************* Cached data follows. If you edit this Notebook file directly, not using Mathematica, you must remove the line containing CacheID at the top of the file. The cache data will then be recreated when you save this file from within Mathematica. *******************************************************************) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[CellGroupData[{ Cell[1727, 52, 68, 0, 170, "Title"], Cell[1798, 54, 122, 3, 37, "Text"], Cell[CellGroupData[{ Cell[1945, 61, 31, 0, 59, "Section"], Cell[1979, 63, 113, 3, 33, "Text"], Cell[2095, 68, 224, 4, 52, "Text"], Cell[CellGroupData[{ Cell[2344, 76, 74, 1, 47, "Subsection"], Cell[2421, 79, 1209, 34, 242, "Text"] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell[3679, 119, 76, 0, 39, "Section"], Cell[3758, 121, 892, 27, 90, "Text"], Cell[4653, 150, 386, 8, 190, "Input"] }, Closed]], Cell[CellGroupData[{ Cell[5076, 163, 38, 0, 39, "Section"], Cell[5117, 165, 481, 15, 52, "Text"], Cell[5601, 182, 912, 24, 130, "Input"], Cell[6516, 208, 428, 12, 52, "Text"], Cell[6947, 222, 260, 5, 70, "Input"] }, Closed]], Cell[CellGroupData[{ Cell[7244, 232, 73, 0, 39, "Section"], Cell[7320, 234, 407, 8, 71, "Text"], Cell[7730, 244, 337, 11, 33, "Text"], Cell[8070, 257, 309, 6, 150, "Input"], Cell[8382, 265, 338, 9, 52, "Text"], Cell[8723, 276, 285, 6, 130, "Input"], Cell[9011, 284, 53, 0, 33, "Text"], Cell[9067, 286, 57, 1, 30, "Input"], Cell[9127, 289, 351, 8, 90, "Text"], Cell[9481, 299, 206, 5, 70, "Input"], Cell[9690, 306, 30, 0, 33, "Text"] }, Closed]], Cell[CellGroupData[{ Cell[9757, 311, 39, 0, 39, "Section"], Cell[9799, 313, 404, 12, 71, "Text"], Cell[10206, 327, 521, 13, 110, "Input"], Cell[10730, 342, 368, 9, 52, "Text"], Cell[11101, 353, 259, 5, 70, "Input"] }, Closed]], Cell[CellGroupData[{ Cell[11397, 363, 73, 0, 39, "Section"], Cell[11473, 365, 666, 15, 109, "Text"], Cell[12142, 382, 480, 9, 190, "Input"], Cell[12625, 393, 90, 2, 33, "Text"], Cell[12718, 397, 214, 4, 70, "Input"], Cell[12935, 403, 620, 13, 128, "Text"], Cell[13558, 418, 76, 1, 30, "Input"], Cell[13637, 421, 256, 4, 52, "Text"], Cell[13896, 427, 97, 2, 35, "Input"] }, Closed]], Cell[CellGroupData[{ Cell[14030, 434, 40, 0, 39, "Section"], Cell[14073, 436, 428, 10, 71, "Text"], Cell[14504, 448, 1090, 23, 276, "Input"] }, Closed]], Cell[CellGroupData[{ Cell[15631, 476, 77, 0, 39, "Section"], Cell[CellGroupData[{ Cell[15733, 480, 96, 2, 47, "Subsection"], Cell[15832, 484, 196, 4, 52, "Text"], Cell[16031, 490, 2094, 36, 570, "Input"], Cell[18128, 528, 129, 3, 33, "Text"], Cell[18260, 533, 273, 6, 50, "Input"], Cell[18536, 541, 388, 6, 71, "Text"], Cell[18927, 549, 150, 3, 30, "Input"], Cell[19080, 554, 63, 0, 33, "Text"], Cell[19146, 556, 226, 5, 50, "Input"], Cell[19375, 563, 260, 3, 52, "Text"] }, Closed]], Cell[CellGroupData[{ Cell[19672, 571, 42, 0, 31, "Subsection"], Cell[19717, 573, 497, 8, 90, "Text"], Cell[20217, 583, 270, 4, 90, "Input"], Cell[20490, 589, 691, 11, 128, "Text"], Cell[21184, 602, 159, 3, 50, "Input"], Cell[21346, 607, 185, 4, 52, "Text"], Cell[21534, 613, 259, 4, 91, "Input"], Cell[21796, 619, 121, 3, 33, "Text"], Cell[21920, 624, 176, 5, 50, "Input"], Cell[22099, 631, 89, 2, 33, "Text"] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell[22237, 639, 39, 0, 39, "Section"], Cell[22279, 641, 549, 10, 110, "Text"], Cell[22831, 653, 421, 8, 130, "Input"], Cell[23255, 663, 170, 3, 52, "Text"], Cell[23428, 668, 709, 16, 91, "Input"], Cell[24140, 686, 133, 3, 33, "Text"], Cell[24276, 691, 623, 16, 50, "Input"], Cell[24902, 709, 63, 0, 33, "Text"], Cell[24968, 711, 620, 15, 50, "Input"], Cell[25591, 728, 161, 3, 33, "Text"], Cell[25755, 733, 827, 21, 30, "Input"], Cell[26585, 756, 224, 6, 52, "Text"], Cell[26812, 764, 42, 1, 30, "Input"], Cell[26857, 767, 135, 3, 33, "Text"], Cell[26995, 772, 308, 5, 70, "Input"] }, Closed]] }, Open ]] } ] *) (******************************************************************* End of Mathematica Notebook file. *******************************************************************)