Input Output Garbage In, Garbage Out. Outline Announcements: –Homework III: due Today. by 5, by e-mail Discuss on Friday. –Homework IV: on web, due following.

Slides:



Advertisements
Similar presentations
Where to Go Next. Outline Announcements: –Homework IV due Wed. 10/8 by 5, by Extra week for projects Absolutely no exceptions! Answers will be.
Advertisements

M AT L AB Reading & Writing Files. Low-level file input and output is very similar to that in 'C', but with inherent vectorization. Files are opened with.
Fprintf and other examples. Save command >> !ls >> a = 3; >> save afile a >> !ls afile.mat >> !dir Directory of C:\MATLAB6p5\work\save 11/21/ :30.
1 9/10/07CS150 Introduction to Computer Science 1 Data Types Section 2.7 – 2.12 CS 150 Introduction to Computer Science I.
1 Homework Turn in HW2 at start of next class. Starting Chapter 2 K&R. Read ahead. HW3 is on line. –Due: class 9, but a lot to do! –You may want to get.
EGR 106 – Truss Design Project (cont.) Truss design programs Graphical interface tools in Matlab Saving and loading data Formatted output Project Assignment.
Hash Tables1 Part E Hash Tables  
Hash Tables1 Part E Hash Tables  
Data Representation Kieran Mathieson. Outline Digital constraints Data types Integer Real Character Boolean Memory address.
Computer Graphics (Spring 2008) COMS 4160, Lecture 22: Global Illumination
1 Agenda Variables (Review) Example Input / Output Arithmetic Operations Casting Char as a Number (if time allow)
Matrix Mathematics in MATLAB and Excel
Introduction to Array The fundamental unit of data in any MATLAB program is the array. 1. An array is a collection of data values organized into rows and.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 21P. 1Winter Quarter MATLAB: Structures.
Chapter 10 Review: Matrix Algebra
Matlab tutorial course Lesson 2: Arrays and data types
Engineering Analysis ENG 3420 Fall 2009 Dan C. Marinescu Office: HEC 439 B Office hours: Tu-Th 11:00-12:00.
2/4/2003CSCI 150: Introduction to Computer Science1 Introduction to Computer Science CSCI 150 Section 002 Session 6 Dr. Richard J. Bonneau IONA Technologies.
IT253: Computer Organization
Text Processing. Outline Announcements: –Homework I: due Today. by 5, by Discuss on Friday. –Homework II: on web HW I: question 7 Finish functions.
C programming for Engineers Lcc compiler – a free C compiler available on the web. Some instructions.
C Tokens Identifiers Keywords Constants Operators Special symbols.
Why does it matter how data is stored on a computer? Example: Perform each of the following calculations in your head. a = 4/3 b = a – 1 c = 3*b e = 1.
CS 114 – Class 02 Topics  Computer programs  Using the compiler Assignments  Read pages for Thursday.  We will go to the lab on Thursday.
Bits & Bytes Created by Chris McAbee For AAMU AGB199 Extra Credit Created from information copied and pasted from
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
IT253: Computer Organization Lecture 3: Memory and Bit Operations Tonga Institute of Higher Education.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Tevfik Bultan Lecture 12: Pointers continued, C strings.
Matlab Basics Tutorial. Vectors Let's start off by creating something simple, like a vector. Enter each element of the vector (separated by a space) between.
CMPS 1371 Introduction to Computing for Engineers MATRICES.
1 Ch. 4 Linear Models & Matrix Algebra Matrix algebra can be used: a. To express the system of equations in a compact manner. b. To find out whether solution.
CS 403: Development of Scientific Computing Programs Andrew Pershing 3134 Snee Hall
Matlab Training Session 10: Loading Binary Data Course Website: Training Sessions.htm.
MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright.
CISC105 – General Computer Science Class 9 – 07/03/2006.
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
1 Input / Output Input – reads/gets data for the program Output – the product, after processing Both can be: interactive I/O (while program is running)
ENG College of Engineering Engineering Education Innovation Center 1 Array Accessing and Strings in MATLAB Topics Covered: 1.Array addressing. 2.
Getting Started with MATLAB (part2) 1. Basic Data manipulation 2. Basic Data Understanding 1. The Binary System 2. The ASCII Table 3. Creating Good Variables.
A string is an array of characters Strings have many uses in MATLAB Display text output Specify formatting for plots Input arguments for some functions.
1 File Handling. 2 Storage seen so far All variables stored in memory Problem: the contents of memory are wiped out when the computer is powered off Example:
Outline Announcements: –HW III due Friday! –HW II returned soon Software performance Architecture & performance Measuring performance.
COMP 116: Introduction to Scientific Programming Lecture 29: File I/O.
EGR 115 Introduction to Computing for Engineers Formatted File Input / Output Wednesday 12 Nov 2014 EGR 115 Introduction to Computing for Engineers.
Linear Systems What is the Matrix?. Outline Announcements: –Homework III: due Today. by 5, by –Ideas for Friday? Linear Systems Basics Matlab and.
Programming Fundamentals. Overview of Previous Lecture Phases of C++ Environment Program statement Vs Preprocessor directive Whitespaces Comments.
1 Programming a Computer Lecture Ten. 2 Outline  A quick introduction to the programming language C  Introduction to software packages: Matlab for numerical.
Matlab Data types, input and output. Data types Char: >> a = ‘ Jim ’ Char: >> a = ‘ Jim ’ Numeric: uint8, uint16, uint32, uint64 int8, int16, int32, int64.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Input and Output.
1 Lecture 4 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
1.2 Primitive Data Types and Variables
CMPS 1371 Introduction to Computing for Engineers CHARACTER STRINGS.
What is a program? A sequence of steps
1 CSC103: Introduction to Computer and Programming Lecture No 28.
Extra Recitations Wednesday 19:40-22:30 FENS L055 (tomorrow!) Friday 13:40-16:30 FENS L063 Friday 17: :30 FENS L045 Friday 19:40-22:30 FENS G032.
Using and Programming with MATLAB as an Engineering Tool [ Part III ]
Improving performance Matlab’s a pig. Outline Announcements: –Homework I: Solutions on web –Homework II: on web--due Wed. Homework I Performance Issues.
Input Output Garbage In, Garbage Out. Outline Announcements: –HWII solutions on web soon –Homework III: due Wednesday Advanced ASCII Binary Basics Cell-arrays.
Chapter 1 slides1 What is C? A high-level language that is extremely useful for engineering computations. A computer language that has endured for almost.
Input Output Garbage In, Garbage Out. Outline Announcements: –Homework III: due Wednesday Advanced ASCII Binary Basics Filesystem Fun.
Formatted I/O ä ä Standard Output ä ä printf() family of functions ä ä Standard Input ä ä scanf() family of functions.
How Computers Store Variables
Understand Computer Storage and Data Types
Other Kinds of Arrays Chapter 11
Other Kinds of Arrays Chapter 11
Matlab review Matlab is a numerical analysis system
Beginning C Lecture 11 Lecturer: Dr. Zhao Qinpei
Variables Title slide variables.
Note on Indexing of Array Elements
Signals.
Presentation transcript:

Input Output Garbage In, Garbage Out

Outline Announcements: –Homework III: due Today. by 5, by Discuss on Friday. –Homework IV: on web, due following Friday Linear Systems Example: Advection- Diffusion Advanced ASCII Binary Basics

Key Points on Linear Systems They’re everywhere Easy to solve in Matlab (\) If possible, reuse factors from LU- decomposition Never use inv(A) for anything important Linear algebra (analytical and numerical) are highly recommended

Advection-Diffusion Model concentration of “contaminant” C Similar equations occur in –fluid dynamics –developmental biology –ecology

Numerical Solution We start with an initial distribution of C over the interval [0 1] Divide [0 1] into discrete points separated by dx C(x,t+dt) will depend on C(x), C(x-dx), & C(x+dx) x C(x,t)

Numerical Solution replace partial derivatives with differences: The solution of C(x,t+dt) depends on neighboring points

Numerical Solution Each C x will have a row in matrix A All rows are the same except for first and last –We need to specify what happens at end points –Boundary conditions are a big problem –We’ll use periodic BC’s C(0)=C(1), so first and last rows are:

Sparse Matrices A is sparse –the only non-zero elements are immediately above, below, and on the diagonal –corners for periodic BC’s Matlab has special sparse matrices –much less memory (don’t need space for 0’s) –faster to process –A=sparse(I,J,S) forms A s.t. A(I(j),J(j))=S(j)

AdvDiff1D.m Uses slightly more complicated procedure for advection known as “Lax-Wendroff” Must specify –Initial concentration C0 –parameters (u, k) –size of domain L –length of time T, –dx, dt Returns x, t, and N(x,t)

Advanced ASCII Read tables of ASCII data with load Other functions like textread will read simple files Sometimes, you’ve just got to do it yourself –Complicated files

Opening Files To read a file manually, open with fopen –fid=fopen(‘fname’, ‘rt’); –fid will be <1 if open fails File I/O functions accept fid Close the file when you’re done with fclose(fid)

Reading files A=fscanf(fid,cstring,{N}) –like C’s fscanf, cstring is a C format string: ‘%d\t%f’--integer (%d),tab(\t),double (%f) –fscanf is “vectorized” and Matlab will keep trying to match cstring. Limit with N lin=fgetl(fid) –Reads a single line from the file as text (char array) –Process lin with str2num, findstr, sscanf Test for end of file with feof(fid);

Writing Files Save matrices using save fname varname - ascii Doing it yourself: –fid=fopen(‘fname’,’wt’) –fprintf(fid,cstring, variables) –Example: A=[(1:10)’, sin(2*pi*0.1*(1:10)’)];%[integers, doubles] fid=fopen(‘example.txt’,’wt’); fprintf(fid,’%d %f\n’,A’); fclose(fid);

Binary Basics All computer files are “binary”, that is composed of 0’s and1’s When the computer reads ASCII files, it takes chunks of 8 bits (1 byte) and looks up the character To save pi to 16 digits takes 18 bytes in ASCII If you save the 1’s and 0’s that correspond to the double precision value of pi, that takes only 8 bytes

You can’t just look at them You must know exactly how they were created –integers vs. floating point –single precision vs. double precision –signed vs. unsigned Problem with Binary Files

fid=fopen(fname,’r’); A=fread(fid,N,precision) –N=number of data points –precision is how the file was created “uint64” is an unsiqned integer saved in 64 bits “double” is a double Reading Binary files

Free advice (you get what you pay for) The only reasons to use binary files are –someone gives you one –you enjoy frustration and pain –you’re too poor (or cheap) to buy a new hard drive