home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!know!cass.ma02.bull.com!think.com!ames!sun-barr!cs.utexas.edu!rutgers!news.cs.indiana.edu!bsu-cs!bsu-ucs.uucp!01jmbrown
- From: 01jmbrown@leo.bsuvc.bsu.edu
- Newsgroups: comp.lang.fortran
- Subject: Multiplies matrices, so I'm told....
- Message-ID: <1992Nov22.120521.12216@bsu-ucs>
- Date: 22 Nov 92 17:05:21 GMT
- Organization: Ball State University, Muncie, In - Univ. Computing Svc's
- Lines: 98
-
-
- Well, I don't know if this is exactly what you want or not, but it
- multiplies two matrices together, so I'm told. I'm taking an intro
- FORTRAN class now, but I will confess my math background is lacking,
- so I'm not even sure how to go about checking it by hand. Basically,
- our instructor gives us some basic formulas and we run from there.
- The dimensions of the matrices are quite limited by this program; some
- of the more educated programmers out there could probably rip this to
- shreads and/or offer better ways to do this... FYI, I'm using (again,
- what I'm told is) FORTRAN 77 on a VAX/VMS system...
-
- But I figure this might help give you a starting place to jump from
- if nothing else.
-
- One of the weird things in this program that comes from the "Heck, if
- it works, use it" department is how I get the screen to clear. It wouldn't
- take
-
- WRITE(6,*) CHAR(27),'[2J',CHAR(27),'[0;0H'
-
- so instead I did:
-
- 9900 FORMAT(1X,A1,'[2J',A1,'[0;0H')
- .
- .
- .
- WRITE(6,9900) CHAR(27),CHAR(27)
-
- like I say, it's probably not the most-educated way to do it, but it
- works...
-
- cut the program as indicated below. I'm new to newsgroups, too, so I don't
- have one of those little .sig things down below quite yet, so everything after
- the '***TRIM PROGRAM HERE***' should compile....
-
- Jeff Brown / 01JMBROWN@VIRGO.BSUVC.BSU.EDU
- working on a BA in Telecommunications (news option) at Ball State University,
- Muncie, Indiana. (So what the heck am I doing taking a FORTRAN class?
- I plead guilty but insane...)
-
-
- ****** TRIM PROGRAM HERE ********************************************
-
- *********************************************************************
- ****** Inputs two matrices and then prints out a matrix that's ******
- ****** the product of the former two matrices. ******
- ****** ******
- ****** NOTE THAT THE SIZE OF THE MATRICES ARE DEFINED IN THE ******
- ****** STATEMENT: ******
- ****** Integer Mx1(5,4), Mx2(4,3), Mx3(5,3) ******
- ****** ******
- ****** Description of variables used: ******
- ****** Mx1, Mx2, Mx3 :: Matrix 1, 2, and 3 ******
- ****** Ix1, Ix2, Ix3 :: Index 1, 2, and 3 ******
- ****** Px :: Variable storing products ******
- ****** ******
- ****** Format code 9900 is used to clear the screen ******
- *********************************************************************
-
- ******DECLARATION SECTION
- INTEGER Mx1(5,4), Mx2(4,3), Mx3(5,3)
- INTEGER Ix1, Ix2, Ix3, Px
- 8001 FORMAT(1X,4I3)
- 8002 FORMAT(1X,3I3)
- 8003 FORMAT(1X,3I6)
- 9900 FORMAT(1X,A1,'[2J',A1,'[0;0H')
-
- ******INPUT SECTION
- WRITE(6,9900) CHAR(27),CHAR(27)
- WRITE(6,*) 'Enter the numbers of the first matrix'
- READ(5,*)((Mx1(Ix1,Ix2),Ix2=1,4),Ix1=1,5)
- WRITE(6,*) 'Enter the numbers of the second matrix'
- READ(5,*)((Mx2(Ix1,Ix2),Ix2=1,3),Ix1=1,4)
-
- ******PROCESSING SECTION
- DO 1001 Ix1 = 1,5
- DO 1002 Ix2 = 1,3
- Px = 0
- DO 1003 Ix3 = 1,4
- Px = Px + Mx1(Ix1,Ix3) * Mx2(Ix3,Ix2)
- 1003 CONTINUE
- Mx3(Ix1,Ix2) = Px
- 1002 CONTINUE
- 1001 CONTINUE
-
- ******OUTPUT SECTION
- WRITE(6,9900) CHAR(27),CHAR(27)
- WRITE(6,*) 'First Matrix:'
- WRITE(6,8001) ((Mx1(Ix1,Ix2),Ix2=1,4),Ix1=1,5)
- WRITE(6,*)
- WRITE(6,*) 'Second Matrix:'
- WRITE(6,8002) ((Mx2(Ix1,Ix2),Ix2=1,3),Ix1=1,4)
- WRITE(6,*)
- WRITE(6,*) 'Third Matrix:'
- WRITE(6,8003) ((Mx3(Ix1,Ix2),Ix2=1,3),Ix1=1,5)
-
- STOP
- END
-