(*********************************************************************** Mathematica-Compatible Notebook This notebook can be used on any computer system with Mathematica 4.0, MathReader 4.0, or any compatible application. 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[ 14586, 476]*) (*NotebookOutlinePosition[ 15575, 512]*) (* CellTagsIndexPosition[ 15469, 505]*) (*WindowFrame->Normal*) Notebook[{ Cell[CellGroupData[{ Cell[TextData[{ "The PlainForm.m package\n", StyleBox["By Ted Ersek\n ersektr@navair.navy.mil", FontSize->12] }], "Subtitle"], Cell[CellGroupData[{ Cell["The trouble with formatting output for email", "Section"], Cell["\<\ Suppose you want to paste the output below in an email message.\ \>", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(\@\(2.0\ x\)\/\(1 + x\^2\) + \[Integral]\@3.0\ \(x\^x\) \ \[DifferentialD]x\)], "Input"], Cell[BoxData[ \(\(1.4142135623730951`\ \@x\)\/\(1 + x\^2\) + 1.7320508075688772`\ \(\[Integral]\(x\^x\) \[DifferentialD]x\)\)], \ "Output"] }, Open ]], Cell[TextData[{ "If you simply copy and paste the cell in your email you probably get the \ following.\n ", Cell[BoxData[ \(\(\(\\\)\(\(! \\(\\(1.4142135623730951` \\\\@x\\) \\/ \\(1 + x \\^ 2\\) + 1.7320508075688772` \\\\ \((\\[Integral]\\(x \\^ x\\)\ \\[DifferentialD]x\)\\)\)\(\\)\)\)\)\)], "Text", CellAutoOverwrite->False, ShowSpecialCharacters->False], "\n\nThe mess above is most difficult to read. Instead you could use \ InputForm in which case the expression above would be written as follows.\n \ (1.4142135623730951*Sqrt[x])/(1 + x^2) + 1.7320508075688772*Integrate[x^x, x]\ \n\nThe expression above much more readable, but we see that the InputForm of \ real numbers often includes sixteen digits. Hence the InputForm of an \ expression with lots of real numbers can also be difficult to read. What we \ really need is a form that looks like InputForm with real numbers rounded to \ six decimal places. In that case the expression above would be formatted as \ follows.\n (1.41421*Sqrt[x])/(1 + x^2) + 1.73205*Integrate[x^x, x]\n \n\ You might also want to copy a whole series of In / Out cells to an email \ message. In that case you might make InputForm the default format for \ output, but then the next two cells return very long output you probably \ don't want to see. This another disadvantage of InputForm. One can obviously \ avoid the lengthy output by ending the expressions with a semi-colon, but \ sometimes you might forget." }], "Text", ShowAutoStyles->False], Cell[BoxData[ \(Plot[Sin[1/x], {x, 0.05, \[Pi]}]\)], "Input"], Cell[BoxData[{ \(\(Clear[x, y];\)\), "\[IndentingNewLine]", \(NDSolve[{x\ \(y''\)[x] \[Equal] Sin[x], y[1] \[Equal] 0, \(y'\)[1] \[Equal] 1}, y[x], {x, 1, 4}]\)}], "Input"] }, Open ]], Cell[CellGroupData[{ Cell["PlainForm solves the problem", "Section"], Cell[TextData[{ "The (PlainForm.m) package defines functions that format ", StyleBox["Mathematica", FontSlant->"Italic"], " output in a way that's easy for people to read in email. Before \ evaluating the examples below you should put the (PlainForm.m) package in one \ of the directories returned by evaluating $Path in the next cell. I normally \ put packages in the ", Cell[BoxData[ \(TraditionalForm\`\(\(\\\)\(AddOns\)\)\\ExtraPackages\)]], " folder." }], "Text"], Cell[BoxData[ \($Path\)], "Input"], Cell["\<\ Once (PlainForm.m) is stored in an appropriate folder it can be loaded by \ evaluating the next cell.\ \>", "Text"], Cell[BoxData[ \(<< PlainForm.m\)], "Input"], Cell["\<\ The (PlainForm.m) package includes definitions of PlainForm and FewerDigits \ and their usage messages are shown below.\ \>", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(\(?FewerDigits\)\)], "Input"], Cell[BoxData[ \("FewerDigits[x] returns x rounded to six decimal places when x is real. \ If the real or imaginary part of a complex number z is approximate then \ FewerDigits[z] rounds those parts to six decimal places. In all other cases \ FewerDigits[expr] returns expr with no change. FewerDigits[x,n] rounds x to n \ decimal places."\)], "Print"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(\(?PlainForm\)\)], "Input"], Cell[BoxData[ \("PlainForm[expr] normally returns the InputForm of expr with real \ numbers rounded to six decimal places. When expr includes complex numbers \ with approximate real or imaginary parts they are rounded to six decimal \ places. A second argument can be used in PlainForm to specify the number of \ decimal places approximate numbers should be rounded to. PlainForm has no \ effect on expressions that include any type of graphics, Sound, \ InterpolationFunction, CompiledFunction, SeriesData or in the case of \ PlainForm[FullForm[expr]]."\)], "Print"] }, Open ]], Cell[CellGroupData[{ Cell["PlainForm Examples", "Subsection"], Cell["\<\ In the cell below the example from above gives an output formatted in a way \ that's easy for people to read in email.\ \>", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(\@\(2.0\ x\)\/\(1 + x\^2\) + \[Integral]\@3.0\ \(x\^x\) \ \[DifferentialD]x\ \ // PlainForm\)], "Input"], Cell["(1.41421*Sqrt[x])/(1 + x^2) + 1.73205*Integrate[x^x, x]", "Output"] }, Open ]], Cell["\<\ In the next two cells the same example has the output formatted using only \ the first eight and first four digits of real numbers.\ \>", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(PlainForm[\@\(2.0\ x\)\/\(1 + x\^2\) + \[Integral]\@3.0\ \(x\^x\) \ \[DifferentialD]x\ \ , 8]\)], "Input"], Cell["(1.4142136*Sqrt[x])/(1 + x^2) + 1.7320508*Integrate[x^x, x]", "Output"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(PlainForm[\@\(2.0\ x\)\/\(1 + x\^2\) + \[Integral]\@3.0\ \(x\^x\) \ \[DifferentialD]x\ \ , 4]\)], "Input"], Cell["(1.414*Sqrt[x])/(1 + x^2) + 1.732*Integrate[x^x, x]", "Output"] }, Open ]], Cell[TextData[{ "In the next example we see PlainForm does the right thing with:\n - \ Scientific notation\n - Real numbers with fewer than six digits\n - \ Complex numbers with approximate imaginary parts\nIn this example we see that \ PlainForm will display ", StyleBox["Mathematica", FontSlant->"Italic"], " characters such as \[Theta]. You will notice the named characters are \ converted to their long name when they are copied into a plain text editor. " }], "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(PlainForm[ Exp[600.0] + 0.25 \[Theta] + \(\@\(-3.0\)\) \[Theta]\^2 + Exp[2.0\ I] \[Theta]\^3 + \@2\/\(\[Pi] + \[Theta]\^2\)]\)], "Input"], Cell["\<\ 3.77302*^260 + 0.25*\[Theta] + 1.73205*I*\[Theta]^2 - (0.416147 - \ 0.909297*I)*\[Theta]^3 + Sqrt[2]/(Pi + \[Theta]^2)\ \>", "Output"] }, Open ]], Cell["\<\ Evaluate the next cell and all your output is formatted using PlainForm.\ \>", "Text"], Cell[BoxData[ \(\($PrePrint = PlainForm;\)\)], "Input"], Cell[CellGroupData[{ Cell[BoxData[ \(tst = \@2.0\ x\^2\/\(x\^2 + 1\)\)], "Input"], Cell["(1.41421*x^2)/(1 + x^2)", "Output"] }, Open ]], Cell["\<\ After evaluating ($PrePrint=PlainForm) the output above is formatted in \ PlainForm. You can edit the output above and the extra digits will not be \ added to the approximate numbers. PlainForm only effected the expression \ sent to the display not the expression assigned to (tst). In the next cell \ we see (tst) is stored with more than six digits for approximate numbers.\ \>", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(FullForm[tst]\)], "Input"], Cell[BoxData[ TagBox[ StyleBox[\(Times[1.4142135623730951`, Power[x, 2], Power[Plus[1, Power[x, 2]], \(-1\)]]\), ShowSpecialCharacters->False, ShowStringCharacters->True, NumberMarks->True], FullForm]], "Output"] }, Open ]], Cell["\<\ After evaluating ($PrePrint=PlainForm) all output not wrapped in FullForm is \ formatted using PlainForm, but PlainForm doesn't affect output that include \ graphics (of any kind), Sound, InterpolatingFunction, or CompiledFunction. As \ a result the five examples below give the StandardForm output.\ \>", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(Plot[Sin[1/x], {x, 0.05, \[Pi]}, DisplayFunction \[Rule] Identity]\)], "Input"], Cell[BoxData[ TagBox[\(\[SkeletonIndicator] Graphics \[SkeletonIndicator]\), False, Editable->False]], "Output"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(Play[Sin[x], {x, 0, 2 \[Pi]}, DisplayFunction \[Rule] Identity]\)], "Input"], Cell[BoxData[ TagBox[\(\[SkeletonIndicator] Sound \[SkeletonIndicator]\), False, Editable->False]], "Output"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[{\(Clear[y, x];\), "\[IndentingNewLine]", RowBox[{"NDSolve", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{ RowBox[{ SuperscriptBox["y", "\[Prime]", MultilineFunction->None], "[", "x", "]"}], "==", \(y[x]\)}], ",", \(y[1] == 2\)}], "}"}], ",", "y", ",", \({x, 0, 3}\)}], "]"}]}], "Input", CellTags->"NDSolve"], Cell[BoxData[ RowBox[{"{", RowBox[{"{", RowBox[{"y", "\[Rule]", TagBox[\(InterpolatingFunction[{{0.`, 3.`}}, "<>"]\), False, Editable->False]}], "}"}], "}"}]], "Output"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(Magnitude = Compile[{{vector, _Real, 1}}, \@\(\(Plus @@ \(vector\^2\)\)\(\ \)\)]\)], "Input"], Cell[BoxData[ TagBox[\(CompiledFunction[{vector}, \@Plus @@ \(vector\^2\), "-CompiledCode-"]\), False, Editable->False]], "Output"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ \(Series[Sin[x], {x, 0, 5}]\)], "Input"], Cell[BoxData[ InterpretationBox[ RowBox[{"x", "-", \(x\^3\/6\), "+", \(x\^5\/120\), "+", InterpretationBox[\(O[x]\^6\), SeriesData[ x, 0, {}, 1, 6, 1]]}], SeriesData[ x, 0, {1, 0, Rational[ -1, 6], 0, Rational[ 1, 120]}, 1, 6, 1]]], "Output"] }, Open ]], Cell["\<\ I would like to have PlainForm format the output of Series in a way that is \ easy to read in a text editor, but I couldn't find a way to make that happen.\ \ \>", "Text"], Cell[" ", "Text", Editable->False, CellMargins->{{0, 0}, {-10, -4}}, CellBracketOptions->{"Thickness"->2, "Color"->RGBColor[0.850004, 0, 0]}, CellElementSpacings->{"CellMinHeight"->1}, PageBreakBelow->True, GeneratedCell->True, Magnification->0.5, CellTags->"PageBreakCell"] }, Closed]], Cell[CellGroupData[{ Cell[" FewerDigits Examples", "Subsection"], Cell["\<\ FewerDigits is the function PlainForm uses to format approximate numbers, and \ it may have other uses. Before demonstrating FewerDigits we clear the value \ of ($PrePrint) in the next cell.\ \>", "Text"], Cell[BoxData[ \($PrePrint =. \)], "Input"], Cell["\<\ In the next example we see FewerDigits does more than format a result for \ output. FewerDigits returns an expression that is rounded to six digits when \ it can.\ \>", "Text"], Cell[CellGroupData[{ Cell[BoxData[{ \(\(Clear[t];\)\), "\[IndentingNewLine]", \(\(t = FewerDigits[\[Pi]/2.0];\)\), "\[IndentingNewLine]", \(FullForm[t]\)}], "Input"], Cell[BoxData[ TagBox[ StyleBox["1.5708`", ShowSpecialCharacters->False, ShowStringCharacters->True, NumberMarks->True], FullForm]], "Output"] }, Open ]], Cell[BoxData[ \(<< PlainForm.m\)], "Input"], Cell["\<\ In the next cell FewerDigits rounds real numbers and complex numbers with \ approximate imaginary parts to six decimal places. However, any expression \ that isn't an inexact number is returned with no change.\ \>", "Text"], Cell[CellGroupData[{ Cell[BoxData[{ \(\(Clear[x];\)\), "\[IndentingNewLine]", \(FewerDigits /@ {x\/\(1 + x\^2\), 2/3, 2.2, \[Pi]/2.0, Exp[1.2\ I], Exp[100.0]}\)}], "Input"], Cell[BoxData[ \({x\/\(1 + x\^2\), 2\/3, 2.2`, 1.5708`, \(\(0.362358`\)\(\[InvisibleSpace]\)\) + 0.932039`\ \[ImaginaryI], 2.68812`*^43}\)], "Output"] }, Open ]], Cell["\<\ In the next line FewerDigits rounds numbers to three decimal places.\ \>", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(\(FewerDigits[#, 3] &\)\ \ /@ {x\/\(1 + x\^2\), 2/3, 2.2, \[Pi]/2.0, Exp[1.2\ I], Exp[100.0]}\)], "Input"], Cell[BoxData[ \({x\/\(1 + x\^2\), 2\/3, 2.2`, 1.57`, \(\(0.362`\)\(\[InvisibleSpace]\)\) + 0.932`\ \[ImaginaryI], 2.69`*^43}\)], "Output"] }, Open ]], Cell["\<\ In the next line FewerDigits rounds numbers to nine decimal places. Recall \ StandardForm would only display the first six digits, so we use InputForm to \ ensure nine digits are displayed.\ \>", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(InputForm[\(FewerDigits[#, 9] &\)\ \ /@ {x\/\(1 + x\^2\), 2.2, 2/3, \[Pi]/2.0, Exp[1.2\ I], Exp[100.0]}]\)], "Input"], Cell["\<\ {x/(1 + x^2), 2.2, 2/3, 1.57079633, 0.362357754 + 0.932039086*I, \ 2.68811714*^43}\ \>", "Output"] }, Open ]] }, Closed]] }, Open ]] }, Open ]] }, FrontEndVersion->"4.0 for Microsoft Windows", ScreenRectangle->{{0, 800}, {0, 527}}, WindowSize->{792, 398}, WindowMargins->{{0, Automatic}, {0, Automatic}}, PrintingCopies->1, PrintingPageRange->{Automatic, Automatic} ] (*********************************************************************** 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->{ "NDSolve"->{ Cell[10152, 313, 433, 11, 50, "Input", CellTags->"NDSolve"]}, "PageBreakCell"->{ Cell[11733, 370, 292, 9, 1, "Text", PageBreakBelow->True, CellTags->"PageBreakCell"]} } *) (*CellTagsIndex CellTagsIndex->{ {"NDSolve", 15248, 494}, {"PageBreakCell", 15341, 497} } *) (*NotebookFileOutline Notebook[{ Cell[CellGroupData[{ Cell[1739, 51, 138, 4, 98, "Subtitle"], Cell[CellGroupData[{ Cell[1902, 59, 63, 0, 53, "Section"], Cell[1968, 61, 87, 2, 33, "Text"], Cell[CellGroupData[{ Cell[2080, 67, 108, 2, 48, "Input"], Cell[2191, 71, 150, 3, 47, "Output"] }, Open ]], Cell[2356, 77, 1601, 27, 280, "Text"], Cell[3960, 106, 65, 1, 30, "Input"], Cell[4028, 109, 190, 3, 50, "Input"] }, Open ]], Cell[CellGroupData[{ Cell[4255, 117, 47, 0, 53, "Section"], Cell[4305, 119, 491, 11, 71, "Text"], Cell[4799, 132, 38, 1, 30, "Input"], Cell[4840, 135, 125, 3, 33, "Text"], Cell[4968, 140, 47, 1, 30, "Input"], Cell[5018, 143, 143, 3, 33, "Text"], Cell[CellGroupData[{ Cell[5186, 150, 49, 1, 30, "Input"], Cell[5238, 153, 355, 5, 82, "Print"] }, Open ]], Cell[CellGroupData[{ Cell[5630, 163, 47, 1, 30, "Input"], Cell[5680, 166, 571, 8, 120, "Print"] }, Open ]], Cell[CellGroupData[{ Cell[6288, 179, 40, 0, 47, "Subsection"], Cell[6331, 181, 142, 3, 33, "Text"], Cell[CellGroupData[{ Cell[6498, 188, 125, 2, 48, "Input"], Cell[6626, 192, 73, 0, 29, "Output"] }, Open ]], Cell[6714, 195, 155, 3, 33, "Text"], Cell[CellGroupData[{ Cell[6894, 202, 126, 2, 48, "Input"], Cell[7023, 206, 77, 0, 29, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[7137, 211, 126, 2, 48, "Input"], Cell[7266, 215, 69, 0, 29, "Output"] }, Open ]], Cell[7350, 218, 488, 9, 128, "Text"], Cell[CellGroupData[{ Cell[7863, 231, 173, 3, 48, "Input"], Cell[8039, 236, 144, 3, 29, "Output"] }, Open ]], Cell[8198, 242, 96, 2, 33, "Text"], Cell[8297, 246, 59, 1, 30, "Input"], Cell[CellGroupData[{ Cell[8381, 251, 64, 1, 45, "Input"], Cell[8448, 254, 41, 0, 29, "Output"] }, Open ]], Cell[8504, 257, 401, 6, 71, "Text"], Cell[CellGroupData[{ Cell[8930, 267, 46, 1, 30, "Input"], Cell[8979, 270, 263, 7, 29, "Output"] }, Open ]], Cell[9257, 280, 323, 5, 71, "Text"], Cell[CellGroupData[{ Cell[9605, 289, 106, 2, 30, "Input"], Cell[9714, 293, 130, 3, 29, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[9881, 301, 104, 2, 30, "Input"], Cell[9988, 305, 127, 3, 29, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[10152, 313, 433, 11, 50, "Input", CellTags->"NDSolve"], Cell[10588, 326, 224, 6, 29, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[10849, 337, 133, 3, 34, "Input"], Cell[10985, 342, 156, 4, 38, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[11178, 351, 58, 1, 30, "Input"], Cell[11239, 354, 295, 7, 45, "Output"] }, Open ]], Cell[11549, 364, 181, 4, 33, "Text"], Cell[11733, 370, 292, 9, 1, "Text", PageBreakBelow->True, CellTags->"PageBreakCell"] }, Closed]], Cell[CellGroupData[{ Cell[12062, 384, 43, 0, 31, "Subsection"], Cell[12108, 386, 214, 4, 52, "Text"], Cell[12325, 392, 46, 1, 30, "Input"], Cell[12374, 395, 187, 4, 52, "Text"], Cell[CellGroupData[{ Cell[12586, 403, 158, 3, 70, "Input"], Cell[12747, 408, 181, 6, 29, "Output"] }, Open ]], Cell[12943, 417, 47, 1, 30, "Input"], Cell[12993, 420, 234, 4, 52, "Text"], Cell[CellGroupData[{ Cell[13252, 428, 169, 3, 61, "Input"], Cell[13424, 433, 169, 3, 42, "Output"] }, Open ]], Cell[13608, 439, 92, 2, 33, "Text"], Cell[CellGroupData[{ Cell[13725, 445, 136, 2, 40, "Input"], Cell[13864, 449, 156, 3, 42, "Output"] }, Open ]], Cell[14035, 455, 214, 4, 52, "Text"], Cell[CellGroupData[{ Cell[14274, 463, 149, 2, 40, "Input"], Cell[14426, 467, 108, 3, 29, "Output"] }, Open ]] }, Closed]] }, Open ]] }, Open ]] } ] *) (*********************************************************************** End of Mathematica Notebook file. ***********************************************************************)