Computers in Engineering - 308-208 Lecture 10
Computers in Engineering - 308-208

Lesson 10 - Learning Goals

10.2 How to define and use a matrix in FORTRAN

MATRICES

Two dimensional arrays or matrices of data occur naturally in many areas of engineering, science and business. Any kind of tabular data, such as results of an experiment or the performance of a company or stock can be considered a matrix.

General form :

NAME_OF_MATRIX(ROWS,COLUMNS)

Examples :

```INTEGER :: DAYS(12,31)
REAL :: YSALES(12,2)
CHARACTER (LEN=3) :: SEASON(4,3)
```

* Arrays are stored by columns.

```PROGRAM MATRICES
IMPLICIT NONE
CHARACTER(LEN=3) :: MONTHS(3,4)
33 FORMAT (12(' ',A3))
PRINT 33,MONTHS
L1: DO I=1,3
L2: DO J=1,4
PRINT 40,I,J,MONTHS(I,J)
40         FORMAT (' ROW ',I1,' COLUMN ',I1,' IS ',A3)
END DO L2
END DO L1
STOP
END PROGRAM MATRICES
```
/DATA
```JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC
```
/ENDRUN
OUTPUT :
```JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC
ROW 1 COLUMN 1 IS JAN
ROW 1 COLUMN 2 IS APR
ROW 1 COLUMN 3 IS JUL
ROW 1 COLUMN 4 IS OCT
ROW 2 COLUMN 1 IS FEB
:
```

SEE EXAMPLES :

P71.F90 MATRIX INPUT/OUTPUT

P72.F90 MATRIX SUMMARY

P73.F90 MATRIX MULTIPLICATION PROGRAM

On to the next lecture