Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "19 - 2/25/2000AME 150L1 Solving Systems of Linear Equations."— Presentation transcript:

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

2 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

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

4 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

5 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

6 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(*)

7 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

8 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

9 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)

10 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)

11 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

12 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)

13 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

14 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)

15 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)

16 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

17 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

18 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 19 - 2/25/2000AME 150L19 FORMAT Examples Currency - '$',F10.2 $ 1234.00 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)


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

Similar presentations


Ads by Google