(************** 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[ 13000, 424]*) (*NotebookOutlinePosition[ 13860, 455]*) (* CellTagsIndexPosition[ 13816, 451]*) (*WindowFrame->Normal*) Notebook[{ Cell[CellGroupData[{Cell["\<\ Example 15 Importing and Manipulating Multi-Dimensional Data Files as Lists\ \>", "Title", ImageRegion->{{0, 1}, {0, 1}}], Cell[TextData[{ "Copyright ", StyleBox["\[Copyright]", FontSlant->"Plain"], " 1993 by Bill Titus, Carleton College, \nDepartment of Physics and \ Astronomy, Northfield, MN 55057-4025\nSeptember 6, 1993" }], "Subsubtitle", ImageRegion->{{0, 1}, {0, 1}}], Cell[CellGroupData[{Cell["Topics and Skills", "Section", ImageRegion->{{0, 1}, {0, 1}}], Cell[TextData[{ "1. Using ", StyleBox["!!", FontFamily->"Courier"], " to read a file without storing it.\n2. List functions: ", StyleBox["Partition[]", FontFamily->"Courier"], ", ", StyleBox["Transpose[]", FontFamily->"Courier"], ", and ", StyleBox["Length[]", FontFamily->"Courier"], "\n3. Extended argument for ", StyleBox["ReadList[]", FontFamily->"Courier"], ".\n4. ", StyleBox["Round[]", FontFamily->"Courier"], " to convert a real to an integer.\n5. ", StyleBox["ScatterPlot3D[]", FontFamily->"Courier"], " in the package ", StyleBox["Graphics`Graphics3D`", FontFamily->"Courier"], "." }], "Special1", ImageRegion->{{0, 1}, {0, 1}}]}, Open]], Cell[CellGroupData[{Cell["Problem", "Section", ImageRegion->{{0, 1}, {0, 1}}], Cell["\<\ a. Use a text editor or a word processor to create an ASCII data file \ containing the following set of nine (t, v, x) points. \ \>", "Special1", ImageRegion->{{0, 1}, {0, 1}}], Cell[TextData[{ StyleBox["\t", FontFamily->"Chicago"], StyleBox["0.0 1.0 0.0\n\t0.8 0.7 0.7\n\t1.6 0.0 1.0\n\t2.4 \ -0.7 0.7\n\t3.1 -1.0 0.0\n\t3.9 -0.7 -0.7\n\t4.7 0.0 -1.0\n\t5.5 \ 0.7 -0.7\n\t6.3 1.0 0.0", FontFamily->"Courier"], StyleBox["", FontFamily->"Chicago"] }], "Text", ImageRegion->{{0, 1}, {0, 1}}], Cell["\<\ b. Read this data file into MMA and store it as a list of three dimensional \ points.\ \>", "Special1", ImageRegion->{{0, 1}, {0, 1}}], Cell[TextData[{ "c. Produce a list of just the ", StyleBox["{t, x}", FontFamily->"Courier"], " values and plot the points on a two dimenisonal graph." }], "Special1", ImageRegion->{{0, 1}, {0, 1}}], Cell[TextData[{ "d. Produce a list of just the ", StyleBox["{t, v}", FontFamily->"Courier"], " values and plot the points on a two dimensional graph. Have your plot \ show both the points and the lines connecting the points." }], "Special1", ImageRegion->{{0, 1}, {0, 1}}]}, Open]], Cell[CellGroupData[{Cell["Solution - Part a", "Section", ImageRegion->{{0, 1}, {0, 1}}], Cell[TextData[{ "Step 1 - Use a text editor or word processor to create an ASCII text file \ containing the desired three dimensional data. Arrange the data, using tabs \ and/or spaces, into three columns and nine rows. Save the data to the file \ ", StyleBox["data2.dat", FontFamily->"Helvetica"], "." }], "Subsection", ImageRegion->{{0, 1}, {0, 1}}], Cell[TextData[{ "Step 2 - Verify that your data file can be read by MMA by using the ", StyleBox["!!", FontFamily->"Courier"], " operator followed by the full path name of your file. Do not enclose \ the file name in double quotes. " }], "Subsection", ImageRegion->{{0, 1}, {0, 1}}], Cell[CellGroupData[{Cell["Comment 2", "Subsection", ImageRegion->{{0, 1}, {0, 1}}], Cell[TextData[{ "1. The columns will line-up in MMA only if you use the same number of \ tabs in each row to separate the column items. But then the columns may not \ line up in the document as read by your text editor or word processor. \n2. \ The ", StyleBox["!!file", FontFamily->"Courier"], " command only shows the data in the file. It doesn't store the results \ in MMA; in particular, you can't assign a name to the output associated with \ this command. Try it and see what happens." }], "Special1", ImageRegion->{{0, 1}, {0, 1}}]}, Open]]}, Open]], Cell[CellGroupData[{Cell["Solution - Part b", "Section", ImageRegion->{{0, 1}, {0, 1}}], Cell[TextData[{ "Step 1 - Use ", StyleBox["ReadList[]", FontFamily->"Courier"], " to load ", StyleBox["data2.dat", FontFamily->"Helvetica"], " into MMA as a set of reals. However, only use one read type in ", StyleBox["ReadList[]", FontFamily->"Courier"], "'s argument. Name the list ", StyleBox["dataVer1", FontFamily->"Courier"], ". What do you notice about the form of the final list produced by MMA?" }], "Subsection", ImageRegion->{{0, 1}, {0, 1}}], Cell[CellGroupData[{Cell["Comment 1", "Subsection", ImageRegion->{{0, 1}, {0, 1}}], Cell[TextData[{ "1. The list isn't partitioned into 3D points.\n2. MMA doesn't \ distinguish when reading in numbers between spaces, tabs, and new lines. \n3. \ If the data had been stored with different separators, like commas, it would \ have been necessary to use the Word type in ", StyleBox["ReadList[]", FontFamily->"Courier"], "'s argument and then the function ", StyleBox["ToExpression[]", FontFamily->"Courier"], " to convert the data into reals." }], "Special1", ImageRegion->{{0, 1}, {0, 1}}]}, Open]], Cell[TextData[{ "Step 2 - One way to produce the desired list of 3D points is to partition \ the list ", StyleBox["dataVer1", FontFamily->"Courier"], ". Locate the MMA command that will do this and create the desired list, \ naming it ", StyleBox["dataVer2", FontFamily->"Courier"], "." }], "Subsection", ImageRegion->{{0, 1}, {0, 1}}], Cell[TextData[{ "Step 3 - Another way to accomplish the task in Step 2 is to produce the \ desired list when you first read in the file. The second argument in ", StyleBox["ReadList[]", FontFamily->"Courier"], " can be an expression or function of one or more of the basic \"types\", \ for example, ", StyleBox["{Real, Real, Real}", FontFamily->"Courier"], ". Use this technique to obtain the desired list ", StyleBox["dataVer2", FontFamily->"Courier"], "." }], "Subsection", ImageRegion->{{0, 1}, {0, 1}}], Cell[CellGroupData[{Cell["Comment 3", "Subsection", ImageRegion->{{0, 1}, {0, 1}}], Cell["\<\ 1. Which of the two methods described above do you like best? Why?\ \>", "Special1", ImageRegion->{{0, 1}, {0, 1}}]}, Open]]}, Open]], Cell[CellGroupData[{Cell["Solution - Part c", "Section", ImageRegion->{{0, 1}, {0, 1}}], Cell[CellGroupData[{Cell[TextData[{ "Step 1 - You'll now create a list consisting of the points ", StyleBox["{t, x}", FontFamily->"Courier"], ". To do so, you'll use the MMA function ", StyleBox["Transpose[]", FontFamily->"Courier"], ". Find out about this function and then active the cell below and look \ closely at the code and the output." }], "Subsection", ImageRegion->{{0, 1}, {0, 1}}], Cell["\<\ Clear[tempList] tempList = Transpose[dataVer2] tempList[[1]] tempList[[3]] Transpose[{tempList[[1]], tempList[[3]]}]\ \>", "Input", ImageRegion->{{0, 1}, {0, 1}}]}, Open]], Cell[TextData[{ "Step 2 - Create the list ", StyleBox["dataTX", FontFamily->"Courier"], " consisting of the points ", StyleBox["{t, x}", FontFamily->"Courier"], " and plot the results on a 2D graph." }], "Subsection", ImageRegion->{{0, 1}, {0, 1}}], Cell[CellGroupData[{Cell["Comment 2", "Subsection", ImageRegion->{{0, 1}, {0, 1}}], Cell["\<\ 1. Large lists take up lots of memory and should be cleared once you're \ finished using them. Under certain circumstances, MMA may crash if too much \ memory has been used up during a MMA session.\ \>", "Special1", ImageRegion->{{0, 1}, {0, 1}}]}, Open]]}, Open]], Cell[CellGroupData[{Cell["Solution - Part d", "Section", ImageRegion->{{0, 1}, {0, 1}}], Cell[TextData[{ "Step 1 - Create the list ", StyleBox["dataTV", FontFamily->"Courier"], " consisting of the points ", StyleBox["{t, v}", FontFamily->"Courier"], " and plot the results on a 2D graph. Have your plot show both the points \ and lines connecting the points. (Hint: produce two plots and then \ superimpose them using ", StyleBox["Show[]", FontFamily->"Courier"], ".)" }], "Subsection", ImageRegion->{{0, 1}, {0, 1}}], Cell[CellGroupData[{Cell["Comment 1", "Subsection", ImageRegion->{{0, 1}, {0, 1}}], Cell[TextData[{ "1. Did you use the option ", StyleBox["DisplayFunction", FontFamily->"Courier"], " to suppress the two separate plots before combining them with ", StyleBox["Show[]", FontFamily->"Courier"], "? If not, do so." }], "Special1", ImageRegion->{{0, 1}, {0, 1}}]}, Open]]}, Open]], Cell[CellGroupData[{Cell["Solution - Part e", "Section", ImageRegion->{{0, 1}, {0, 1}}], Cell[TextData[{ "Step 1 - The three dimensional phase plot can be created in two ways. The \ most direct way is to use the function ", StyleBox["ScatterPlot3D[]", FontFamily->"Courier"], " found in the package ", StyleBox["Graphics`Graphics3D`", FontFamily->"Courier"], ". Load this package, find out about the function ", StyleBox["ScatterPlot3D[]", FontFamily->"Courier"], " and apply it to the list", StyleBox[" dataVer2", FontFamily->"Courier"], "." }], "Subsection", ImageRegion->{{0, 1}, {0, 1}}], Cell[CellGroupData[{Cell[TextData[{ "Step 2 - The code in the following cell uses ", StyleBox["ParametricPlot3D[]", FontFamily->"Courier"], " to create the desired 3D phase plot. It also uses the commands ", StyleBox["Length[]", FontFamily->"Courier"], " and ", StyleBox["Round[]", FontFamily->"Courier"], ". Find out about the new commands, look over the code, and then activate \ the cell." }], "Subsection", ImageRegion->{{0, 1}, {0, 1}}], Cell["\<\ Clear[tempList] tempList = Transpose[dataVer2]; ParametricPlot3D[ {tempList[[1, Round[s]]], tempList[[2, Round[s]]], tempList[[3, Round[s]]]}, {s, 1, Length[dataVer2]}, DefaultColor -> RGBColor[0, 0, 1], AxesLabel -> {\"t\", \"x\", \"v\"}, PlotLabel -> \"Three Dimensional Phase Plot\", FaceGrids -> All];\ \>", "Input", ImageRegion->{{0, 1}, {0, 1}}]}, Open]], Cell[CellGroupData[{Cell["Comment 2", "Subsection", ImageRegion->{{0, 1}, {0, 1}}], Cell[TextData[{ "1. This technique using ", StyleBox["ParametricPlot[]", FontFamily->"Courier"], " doesn't allow individual points to be plotted. How might you do this?\n\ 2. The parameter ", StyleBox["s", FontFamily->"Courier"], " must be real in order for the command to work. But ", StyleBox["s ", FontFamily->"Courier"], " also needs to be an integer for indexing the list; thus the use of ", StyleBox["Round[s]", FontFamily->"Courier"], " in indexing ", StyleBox["tempList", FontFamily->"Courier"], "." }], "Special1", ImageRegion->{{0, 1}, {0, 1}}]}, Open]]}, Open]], Cell[CellGroupData[{Cell["Save Your Notebook", "Section", ImageRegion->{{0, 1}, {0, 1}}], Cell[TextData[{ "Remove any output cells from this notebook and then use ", StyleBox["Save As", FontFamily->"Helvetica"], " to store your notebook under the name ", StyleBox["myEx15", FontFamily->"Helvetica"], "." }], "Special1", ImageRegion->{{0, 1}, {0, 1}}]}, Open]]}, Open]] }, FrontEndVersion->"4.1 for Microsoft Windows", ScreenRectangle->{{0, 1024}, {0, 695}}, WindowToolbars->{}, CellGrouping->Manual, WindowSize->{499, 599}, WindowMargins->{{55, Automatic}, {23, Automatic}}, PrivateNotebookOptions->{"ColorPalette"->{RGBColor, -1}}, ShowCellLabel->True, ShowCellTags->False, RenderingOptions->{"ObjectDithering"->True, "RasterDithering"->False} ] (******************************************************************* 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, 134, 5, 70, "Title"], Cell[1864, 59, 265, 7, 70, "Subsubtitle"], Cell[CellGroupData[{ Cell[2152, 68, 69, 1, 70, "Section"], Cell[2224, 71, 721, 27, 70, "Special1"] }, Open ]], Cell[CellGroupData[{ Cell[2977, 100, 59, 1, 70, "Section"], Cell[3039, 103, 203, 4, 70, "Special1"], Cell[3245, 109, 361, 10, 70, "Text"], Cell[3609, 121, 147, 4, 70, "Special1"], Cell[3759, 127, 212, 6, 70, "Special1"], Cell[3974, 135, 288, 7, 70, "Special1"] }, Open ]], Cell[CellGroupData[{ Cell[4294, 144, 69, 1, 70, "Section"], Cell[4366, 147, 366, 9, 70, "Subsection"], Cell[4735, 158, 297, 7, 70, "Subsection"], Cell[CellGroupData[{ Cell[5055, 167, 64, 1, 70, "Subsection"], Cell[5122, 170, 557, 11, 70, "Special1"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[5720, 183, 69, 1, 70, "Section"], Cell[5792, 186, 501, 15, 70, "Subsection"], Cell[CellGroupData[{ Cell[6316, 203, 64, 1, 70, "Subsection"], Cell[6383, 206, 530, 12, 70, "Special1"] }, Open ]], Cell[6925, 220, 359, 11, 70, "Subsection"], Cell[7287, 233, 539, 14, 70, "Subsection"], Cell[CellGroupData[{ Cell[7849, 249, 64, 1, 70, "Subsection"], Cell[7916, 252, 129, 3, 70, "Special1"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[8086, 257, 69, 1, 70, "Section"], Cell[CellGroupData[{ Cell[8178, 260, 397, 10, 70, "Subsection"], Cell[8578, 272, 174, 7, 70, "Input"] }, Open ]], Cell[8764, 281, 272, 9, 70, "Subsection"], Cell[CellGroupData[{ Cell[9059, 292, 64, 1, 70, "Subsection"], Cell[9126, 295, 260, 5, 70, "Special1"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[9427, 302, 69, 1, 70, "Section"], Cell[9499, 305, 463, 14, 70, "Subsection"], Cell[CellGroupData[{ Cell[9985, 321, 64, 1, 70, "Subsection"], Cell[10052, 324, 298, 9, 70, "Special1"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[10391, 335, 69, 1, 70, "Section"], Cell[10463, 338, 545, 16, 70, "Subsection"], Cell[CellGroupData[{ Cell[11031, 356, 456, 13, 70, "Subsection"], Cell[11490, 371, 382, 14, 70, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[11904, 387, 64, 1, 70, "Subsection"], Cell[11971, 390, 610, 19, 70, "Special1"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[12622, 411, 70, 1, 70, "Section"], Cell[12695, 414, 284, 9, 70, "Special1"] }, Open ]] }, Open ]] } ] *) (******************************************************************* End of Mathematica Notebook file. *******************************************************************)