Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Interacting with Files and Generating Code in Maple for Symbolic Computation - Prof. Jan V, Study notes of Computer Science

The capabilities of maple in handling low-level data input and output, as well as generating code. Topics include importing and exporting data using readdata and writedata, manipulating files with maple's low-level i/o functions, and generating c or fortran code for functions. The document also includes assignments for practicing these concepts.

Typology: Study notes

Pre 2010

Uploaded on 07/29/2009

koofers-user-idv
koofers-user-idv 🇺🇸

10 documents

1 / 2

Toggle sidebar

Related documents


Partial preview of the text

Download Interacting with Files and Generating Code in Maple for Symbolic Computation - Prof. Jan V and more Study notes Computer Science in PDF only on Docsity! MCS 320 Introduction to Symbolic Computation Spring 2003 9. Import/export of data; Low-Level I/O; Code generation In this lecture we go deeper into the capabilities of Maple to interact at a low level to retrieve or save data. We end this part with a demonstration how Maple can generate code. 9.1 Import/export of data Raw numerical data in the form of matrices of floating-point numbers can be brought in and out of Maple with the commands readdata and writedata. Let us first create a matrix: [> indfun := (i,j) -> 1/(i+j-1); # index function [> data := matrix(3,5,indfun); # 3-by-5 Hilbert matrix [> Digits := 20: # write a 20 digit approximation to file [> writedata(terminal,data,float); # first write to terminal as test [> writedata("C:\\MCS320\\mydata",data,float); [> data := ’data’; # release variable to check retrieval Matrices in readdata are considered to be organized columnwise. Besides the file, we give in the number of columns we wish to read : [> data := readdata("C:\\MCS320\\mydata",5); 9.2 Low-Level I/O We can manipulate files very much like if we were programming in C. A sample session is below: [> ourfile := "C:\\MCS320\\testfile": [> fopen(ourfile,WRITE,TEXT); [> n := writeline(ourfile,‘this is some text‘); [> fclose(ourfile); [> fopen(ourfile,READ,TEXT); [> readline(ourfile); [> fclose(ourfile); [> fopen(ourfile,APPEND,TEXT); [> fprintf(ourfile,"number of characters on previous line :%d\n",n); [> fclose(ourfile); 9.3 Code Generation If we wish to export functions, for example to evaluate polynomials or other mathematical expressions, we can generate C or Fortran code. [> with(codegen); [> p := x^4 + 3*x + 2; [> fortran(p,’optimized’,precision=double,mode=double); [> C(p); Jan Verschelde, February 3, 2003 UIC, Dept of Math, Stat & CS Lecture 9, page 1
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved