A maple character styles are mapped directly onto l

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ram. Writing Columns of Numerical Data to a File If the result of a Maple calculation is a long list or a large array of numbers, you can convert it to a Matrix and write the numbers to a file in a structured manner. 282 • Chapter 8: Input and Output The ExportMatrix Command The ExportMatrix command writes columns of numerical data to a file, allowing you to import the numbers into another program. You can use the ExportMatrix command with the following syntax. ExportMatrix( "filename ", data ) • filename is the string containing the name of the file to which ExportMatrix writes the data • data is a Matrix Note: A list, vector, list of lists, or table-based matrix can be converted to a Matrix by using the Matrix constructor. For more information, refer to the ?Matrix help page. > L:=LinearAlgebra[RandomMatrix](5); −66 −65 20 55 5 −7 68 66 16 L := 26 −36 −34 13 −41 −62 −90 30 −21 62 −56 −79 −8 −71 −50 28 > ExportMatrix("matrixdata.txt", L): If the data is a Vector or any object that can be converted to type Vector, then ExportVector can be used. Lists and table-based vectors can be converted by using the Vector constructor. For more information, refer to the ?Vector help page. > L := [ 3, 3.1415, -65, 0 ]; L := [3, 3.1415, −65, 0] > V := Vector(L); 3 3.1415 V := −65 0 8.2 Writing Data to a File > ExportVector( "vectordata.txt", V ): • 283 You can extend these routines to write more complicated data, such as complex numbers or symbolic expressions. For more information, refer to the ?ExportMatrix and ?ExportVector help pages. Saving Expressions in the Maple Internal Format If you construct a complicated expression or procedure, you can save it for future use in Maple. If you save the expression or procedure in the Maple internal format, then Maple can retrieve it efficiently. Use the save command to write the expression to a filename ending with the characters “.m”. Use the save command with the following syntax. save nameseq, "filename .m"; • nameseq is a sequence of names; you can save only named objects. The save command saves the objects in filename.m • .m indicates that save writes the file using the Maple internal format Consider the following. > qbinomial := (n,k) -> product(1-q^i, i=n-k+1..n) / > product(1-q^i, i=1..k ); n (1 − q i ) qbinomial := (n, k ) → i=n−k+1 k (1 − q i ) i=1 > expr := qbinomial(10, 4); expr := (1 − q 7 ) (1 − q 8 ) (1 − q 9 ) (1 − q 10 ) (1 − q ) (1 − q 2 ) (1 − q 3 ) (1 − q 4 ) > nexpr := normal( expr ); nexpr := (q 6 + q 5 + q 4 + q 3 + q 2 + q + 1) (q 4 + 1) (q 6 + q 3 + 1) (q 8 + q 6 + q 4 + q 2 + 1) You can save these expressions to the file qbinom.m. 284 • Chapter 8: Input and Output > save qbinomial, expr, nexpr, "qbinom.m"; The restart command clears the three expressions from memory. Thus expr evaluates to its own name. > restart: > expr; expr Use the read command to retrieve the expressions that you saved i...
View Full Document

This note was uploaded on 08/27/2012 for the course MATH 1100 taught by Professor Nil during the Spring '12 term at National University of Singapore.

Ask a homework question - tutors are online