19 - 2/25/2000AME 150L1 Solving Systems of Linear Equations.

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

Multidimensional Array
Introduction to arrays
Input and Output READ WRITE OPEN. FORMAT statement Format statements allow you to control how data are read or written. Some simple examples: Int=2; real=
CHAPTER 5 INPUT/OUT FORMAT. Introduction READ (*,*) x WRITE (*,*) x This is free format: the first * is for I/O device number (* = input is keyboard *
Dale Roberts Basic I/O – printf() CSCI 230 Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Department of.
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
More Review, with Some New Chapter 3. Review C++ simple data types – Integral and float – Arithmetic operators Expressions and expression evaluation –
1 Basic I/O Input and Output. 2 The READ Statement Basic Version l Performs a list-directed read from the file (or device) indicated by the unit number.
Chapter 5 Basic I/O Concepts Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering İstanbul - Turkey Tel:
11/06/20151 FORTRAN 77 Programming. Lecture 5 : January 2001 Dr. Andrew Paul Myers.
Reading and Writing Files Keeping Data. Why do we use files? ä For permanently storing data. ä For dealing with information too large to fit in memory.
Input and output. Input streams n there are two ways of handling I/o n list-directed –done using default settings –PRINT*, num –READ*, num n formatted.
27 April, 2000 CS1001 Lecture 25 Files Internal Files.
Chapter 9 Formatted Input/Output Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
CHAPTER 3 INPUT/OUTPUT List-directed (free formatted) input/output As in section 2.6 Formatted input/output General Form: Read format-specifier, input-list.
Chapter 5 Input / Output. 2 Control over input & output  The input and output are basically facilitates a communication between the user and the program.
Chapter 8 Arrays and Strings
CHAPTER 6 FILE PROCESSING. 2 Introduction  The most convenient way to process involving large data sets is to store them into a file for later processing.
21 April, 2000 CS1001 Lecture 27 Final Examination Review.
C Formatted Input/Output /* Using Integer Conversion Specifiers */ #include int main ( ) { printf( "%d\n", 455 ); printf( "%i\n", 455 ); printf( "%d\n",
Arithmetic Operations on Matrices. 1. Definition of Matrix 2. Column, Row and Square Matrix 3. Addition and Subtraction of Matrices 4. Multiplying Row.
The printf Method The printf method is another way to format output. It is based on the printf function of the C language. System.out.printf(,,,..., );
 2007 Pearson Education, Inc. All rights reserved C Formatted Input/Output.
Chapter 2 Systems of Linear Equations and Matrices Section 2.4 Multiplication of Matrices.
Example in Final Fall 2006 PROGRAM EXAM IMPLICIT NONE INTEGER :: A=3, B=8 REAL :: CALC B = CALC(A, B) A = CALC(A, B) WRITE(*,*) A, B END PROGRAM EXAM a)
Generalized I/O. Mystery of stars I/O statements took the form read *, x, y,z print *, a,b,c Such I/O is said to be List-directed or in free format user.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
Fortran: Specification Statements Session Six ICoCSIS.
Introduction to FORTRAN
 2000 Prentice Hall, Inc. All rights reserved. Chapter 9 - Formatted Input/Output Outline 9.1Introduction 9.2Streams 9.3Formatting Output with printf.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Streams Streams –Sequences of characters organized.
1 Week 12 Arrays, vectors, matrices and cubes. Introduction to Scientific & Engineering Computing 2 Array subscript expressions n Each subscript in an.
Chapter 9 Formatted Input/Output. Objectives In this chapter, you will learn: –To understand input and output streams. –To be able to use all print formatting.
Fortran 1- Basics Chapters 1-2 in your Fortran book.
 2004 Prentice Hall, Inc. All rights reserved. 1 Chapter 11 - JavaScript: Arrays Outline 11.1 Introduction 11.2 Arrays 11.3 Declaring and Allocating Arrays.
Multi-Dimensional Arrays
Arrays 1 Multiple values per variable. Why arrays? Can you collect one value from the user? How about two? Twenty? Two hundred? How about… I need to collect.
You gotta be cool. Stream Stream Output Stream Input Unformatted I/O with read, gcount and write Stream Manipulators Stream Format States Stream Error.
Chapter 8 Arrays and Strings
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Arrays.
Equation Jeopardy Add Mixed Multiply/ Divide Fractions Q $100 Q $200 Q $300 Q $400 Q $500 Q $100 Q $200 Q $300 Q $400 Q $500 Final Jeopardy Subtract.
Chapter 3: Formatted Input/Output Copyright © 2008 W. W. Norton & Company. All rights reserved. 1 Chapter 3 Formatted Input/Output.
Solving a System of Equations in Two Variables By Elimination Chapter 8.3.
Data TypestMyn1 Data Types The type of a variable is not set by the programmer; rather, it is decided at runtime by PHP depending on the context in which.
INPUT / OUTPUT STATEMENTS
ENG College of Engineering Engineering Education Innovation Center 1 Array Accessing and Strings in MATLAB Topics Covered: 1.Array addressing. 2.
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.
COMP 116: Introduction to Scientific Programming Lecture 29: File I/O.
21 April, 2000 CS1001 Lecture 22 Formatted Input and Output.
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
INTRODUCTION TO MATLAB DAVID COOPER SUMMER Course Layout SundayMondayTuesdayWednesdayThursdayFridaySaturday 67 Intro 89 Scripts 1011 Work
Gator Engineering Copyright © 2008 W. W. Norton & Company. All rights reserved. 1 Chapter 3 Formatted Input/Output.
Lecture 7: Menus and getting input. switch Multiple-selection Statement switch Useful when a variable or expression is tested for all the values it can.
Chapter 3: Formatted Input/Output 1 Chapter 3 Formatted Input/Output.
CSCE Do Loops Simplest form DO j = 1,100 PRINT *,j END DO Variable j runs from 1 to 100 counting by ones.
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
Do-more Technical Training
Formatted Input and Output
ECE 3301 General Electrical Engineering
Other Kinds of Arrays Chapter 11
Input and Output Lecture 4.
Lecture 13 Input/Output Files.
Midterm Review Programming in Fortran
Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions
Solving Equations involving Decimal Coefficients
Matlab Basics.
DATA TYPES AND OPERATIONS
Week 10 FILE PROCESSING.
OUTPUT DESIGN PRINT K, expression list K FORMAT (specification list)
Presentation transcript:

19 - 2/25/2000AME 150L1 Solving Systems of Linear Equations

19 - 2/25/2000AME 150L2 Set of Linear Equations Require N linear equations in N unknowns General Form: x i is an unknown vector with N elements a ij is a known, square array with N 2 elements b i is a known vector with N elements a ij and b i are both constant

19 - 2/25/2000AME 150L3 Use of  for Summation

19 - 2/25/2000AME 150L4 SUBROUTINE Mat_Vect_Mult(a,x,b,N) IMPLICIT NONE ! Evaluates b(i) = Sum(j=1,N)a(i,j)*x(j) for i=1,3 INTEGER, INTENT(IN):: N !Order of the system REAL, INTENT(IN) :: a(N,N) !square coefficient matrix REAL, INTENT(IN) :: x(N) !Vector REAL, INTENT(OUT):: b(N) !Output Vector !Local Variables INTEGER :: i,j DO i=1,N b(i)=0. !Initialize to 0. DO j=1,N b(i) = b(i) + a(i,j)*x(j) !The actual summation END DO ! RETURN is optional if at end of Subroutine END SUBROUTINE Mat_Vect_Mult Matrix-Vector Multiply

19 - 2/25/2000AME 150L5 Discussion of Mat_Vec_Mult Storage Model –Assumes that N, the order of the Matrix and the dimension information are the same –If the storage is different (i.e., for a program to work with different sized arrays), need an additional input

19 - 2/25/2000AME 150L6 Storage Specification N = Ndim SUBROUTINE & &Mat_Vect_Mult(a,x,b,N) IMPLICIT NONE INTEGER, INTENT(IN) :: N REAL, INTENT(IN) :: a(N,*) REAL, INTENT(IN) :: x(*) REAL, INTENT(OUT):: b(*) Dimension Information of * allows use of index, but no checking N  Ndim SUBROUTINE & &Mat_Vect_Mult(a,x,b,N,Ndim) IMPLICIT NONE INTEGER, INTENT(IN) :: N, Ndim REAL, INTENT(IN) :: a(Ndim,*) REAL, INTENT(IN) :: x(*) REAL, INTENT(OUT):: b(*)

19 - 2/25/2000AME 150L7 Calling Program PROGRAM Test_Mult IMPLICIT NONE REAL :: a(3,3),b(3),x(3) INTEGER :: i,j OPEN(1,FILE="Input.data") !Open Input File DO i=1,3 READ(1,*) (a(i,j),j=1,3),x(i) WRITE(*,*)(a(i,j),j=1,3),x(i) END DO CALL Mat_Vect_Mult(a,x,b,3) WRITE(*,*)"b=",(b(i),i=1,3) END PROGRAM Test_Mult

19 - 2/25/2000AME 150L8 File I/O Open File –Create new file (for output) –Open existing file (for input) OPEN statement uses keywords First argument is an integer constant (unit) Then a list of keywords B: Chapter 4, D: Chapter 8

19 - 2/25/2000AME 150L9 Open Keywords FILE= 'file name expression' STATUS= 'status expression' NEW - create new file (write) REPLACE - replace existing file (write) SCRATCH - delete when closed (write) OLD - use existing (read) UNKNOWN - do what makes sense (default)

19 - 2/25/2000AME 150L10 Open Keywords (2) ACTION= 'read'|'write'|'readwrite' READ - Input only WRITE - Output only READWRITE - Either (default) POSITION = 'asis'|append'|'rewind' REWIND - always start start at beginning APPEND - add to end ASIS - unchanged (default)

19 - 2/25/2000AME 150L11 Open Keywords (3) IOSTAT= integer set by routine >0 - Some error occurred <0 - End of File (End of data) 0 - Successful completion ERROR = statement label

19 - 2/25/2000AME 150L12 Open Keywords (end) ACCESS='sequential'|'direct' FORM='formatted'|'unformatted' RECL= integer record length BLANK='null'|'zero' DELIM= 'none'|'apostrophe'|'quote' PAD='yes'|'no' (pad with blanks)

19 - 2/25/2000AME 150L13 General Input/Output Start (and end) of file access –OPEN … CLOSE Normal usage –READ … WRITE Control –BACKSPACE … REWIND … END FILE Information about file (or record) –INQUIRE … FORMAT

19 - 2/25/2000AME 150L14 READ or WRITE READ|WRITE (unit, fmt, keywords) iolist unit - integer as in OPEN statement fmt - label of FORMAT or 'string' rec = integer record number (direct access) iostat = integer (see OPEN) err = label (go when error) end = label (go when end of file)

19 - 2/25/2000AME 150L15 IO List List can contain any of Variables x, y, J, c(1), d(1,N) Constants "text", 7 Entire array vector, c Implied DO (c(i),i=1,n) ((d(i,j),j=1,3),I=1,N)

19 - 2/25/2000AME 150L16 FORMAT Use of * easiest (chose best method) Sometimes not neat –zero data sometimes 0.E+0 –hard to line up decimal points (columns) –fractions have too many digits Format specification must match an item in IOlist

19 - 2/25/2000AME 150L17 FORMAT Specifications INTEGER - Iw, Ow, Zw I -decimal, O -octal, Z -hexadecimal REAL - Fw.d, Ew.d, Gw.d (w  d+7) F fixed decimal, E always E format G is a mix [ E is ±0.ddddE±12 ] CHARACTER - A w - width of field (in spaces) d - number of decimal digits

19 - 2/25/2000AME 150L18 More FORMAT Specifications Blank spaces X (or nX ) Tab to column n Tn True Scientific ESw.d (w  d+7) [ ES is ±D.ddddE±DD ] Logical Lw produces only T or F Next record / Characters: 'text',"text",or 4 H text

19 - 2/25/2000AME 150L19 FORMAT Examples Currency - '$',F10.2 $ Repeat Specifications 10F10.2, or 15('$',F10.2) Neat format: c(1)=1.5, c(2)=-3.8, c(3)=12.0 WRITE(*,'(3("c(",I1,")=",F4.1))')(i,C(i),i=1,3)