This preview shows page 1. Sign up to view the full content.
Unformatted text preview: a Taylor approximation; and manipulate and solve ordinary and partial diﬀerential equations, numerically as well as symbolically. 8 Input and Output Maple provides convenient ways to import and export raw numerical data and graphics. It presents individual algebraic and numeric results in formats suitable for use in FORTRAN, C, or the mathematical typesetting A system L TEX. You can export the entire worksheet as a ﬁle in any of the A following formats: HTML or HTML with MathML, L TEX, Maple Input, Maple Text, Maplet application, Plain Text, or Rich Text Format. You can cut and paste results, and export either single expressions or entire worksheets. This chapter discusses the most common aspects of exporting and importing information to and from ﬁles. It introduces how Maple interacts with the ﬁle system on your computer, and how Maple can begin interacting with other software. In This Chapter
• Reading Files • Writing Data to a File • Exporting Worksheets • Printing Graphics 8.1 Reading Files The two most common cases for reading ﬁles are to obtain data and to retrieve Maple commands stored in a text ﬁle. • The ﬁrst case is often concerned with data generated from an experiment. You can store numbers separated by whitespace and line breaks in a text ﬁle, then read them into Maple for study. You can 277 278 • Chapter 8: Input and Output accomplish these operations by using the Maple ExportMatrix and ImportMatrix commands. • The second case concerns reading commands from a text ﬁle. Perhaps you have received a worksheet in text format, or you have written a Maple procedure by using a text editor and have stored it in a text ﬁle. You can cut and paste commands into Maple or you can use the read command. The following section discusses the second case. Reading Columns of Numbers from a File
If you generate data outside Maple, you must read it into Maple before you can manipulate it. Often such external data is in the form of columns of numbers in a text ﬁle. The ﬁle data.txt below is an example. 0 1 2 3 4 5 6 10 .5403023059 .8414709848 -.4161468365 .9092974268 -.9899924966 .1411200081 -.6536436209 -.7568024953 .2836621855 -.9589242747 .9601702867 -.2794154982 The ImportMatrix command reads columns of numbers. Use ImportMatrix as follows. ImportMatrix( "filename ", delimiter=string ) • ﬁlename is the name of the ﬁle to read • string is the character that separates the entries in the ﬁle. The default value of string is a tab, represented by using "\t". In data.txt, the entries are separated by spaces, so the value of string is " "
> L := ImportMatrix( "data.txt", delimiter="\t" ); 0 1 2 L := 3 4 5 6 1 0.5403023059 −0.4161468365 −0.9899924966 −0.6536436209 0.2836621855 0.9601702867 0 0.8414709848 0.9092974268 0.1411200081 −0.7568024953 −0.9589242747 −0.2794154982 8.1 Reading Files • 279 For example, you can plot the third column against the ﬁrst. Use the convert c...
View Full Document