home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / fortran / 4407 < prev    next >
Encoding:
Internet Message Format  |  1992-11-22  |  4.0 KB

  1. 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
  2. From: 01jmbrown@leo.bsuvc.bsu.edu
  3. Newsgroups: comp.lang.fortran
  4. Subject: Multiplies matrices, so I'm told....
  5. Message-ID: <1992Nov22.120521.12216@bsu-ucs>
  6. Date: 22 Nov 92 17:05:21 GMT
  7. Organization: Ball State University, Muncie, In - Univ. Computing Svc's
  8. Lines: 98
  9.  
  10.  
  11. Well, I don't know if this is exactly what you want or not, but it
  12. multiplies two matrices together, so I'm told.  I'm taking an intro
  13. FORTRAN class now, but I will confess my math background is lacking,
  14. so I'm not even sure how to go about checking it by hand. Basically,
  15. our instructor gives us some basic formulas and we run from there.
  16. The dimensions of the matrices are quite limited by this program; some
  17. of the more educated programmers out there could probably rip this to
  18. shreads and/or offer better ways to do this... FYI, I'm using (again,
  19. what I'm told is) FORTRAN 77 on a VAX/VMS system...
  20.  
  21. But I figure this might help give you a starting place to jump from
  22. if nothing else.
  23.  
  24. One of the weird things in this program that comes from the "Heck, if
  25. it works, use it" department is how I get the screen to clear. It wouldn't
  26. take
  27.  
  28.       WRITE(6,*) CHAR(27),'[2J',CHAR(27),'[0;0H'
  29.  
  30. so instead I did:
  31.  
  32.  9900 FORMAT(1X,A1,'[2J',A1,'[0;0H')
  33.         .
  34.         .
  35.         .
  36.       WRITE(6,9900) CHAR(27),CHAR(27)
  37.  
  38. like I say, it's probably not the most-educated way to do it, but it
  39. works...
  40.  
  41. cut the program as indicated below. I'm new to newsgroups, too, so I don't
  42. have one of those little .sig things down below quite yet, so everything after
  43. the '***TRIM PROGRAM HERE***' should compile....
  44.  
  45. Jeff Brown / 01JMBROWN@VIRGO.BSUVC.BSU.EDU
  46. working on a BA in Telecommunications (news option) at Ball State University,
  47. Muncie, Indiana. (So what the heck am I doing taking a FORTRAN class?
  48. I plead guilty but insane...)
  49.  
  50.  
  51. ****** TRIM PROGRAM HERE ********************************************
  52.  
  53. *********************************************************************
  54. ****** Inputs two matrices and then prints out a matrix that's ******
  55. ****** the product of the former two matrices.                 ******
  56. ******                                                         ******
  57. ****** NOTE THAT THE SIZE OF THE MATRICES ARE DEFINED IN THE   ******
  58. ****** STATEMENT:                                              ******
  59. ******        Integer Mx1(5,4), Mx2(4,3), Mx3(5,3)             ******
  60. ******                                                         ******
  61. ****** Description of variables used:                          ******
  62. ******     Mx1, Mx2, Mx3  ::  Matrix 1, 2, and 3               ******
  63. ******     Ix1, Ix2, Ix3  ::  Index 1, 2, and 3                ******
  64. ******     Px             ::  Variable storing products        ******
  65. ******                                                         ******
  66. ****** Format code 9900 is used to clear the screen            ******
  67. *********************************************************************
  68.  
  69. ******DECLARATION SECTION
  70.       INTEGER Mx1(5,4), Mx2(4,3), Mx3(5,3)
  71.       INTEGER Ix1, Ix2, Ix3, Px
  72.  8001 FORMAT(1X,4I3)
  73.  8002 FORMAT(1X,3I3)
  74.  8003 FORMAT(1X,3I6)
  75.  9900 FORMAT(1X,A1,'[2J',A1,'[0;0H')
  76.  
  77. ******INPUT SECTION
  78.       WRITE(6,9900) CHAR(27),CHAR(27)
  79.       WRITE(6,*) 'Enter the numbers of the first matrix'
  80.       READ(5,*)((Mx1(Ix1,Ix2),Ix2=1,4),Ix1=1,5)
  81.       WRITE(6,*) 'Enter the numbers of the second matrix'
  82.       READ(5,*)((Mx2(Ix1,Ix2),Ix2=1,3),Ix1=1,4)
  83.  
  84. ******PROCESSING SECTION
  85.       DO 1001 Ix1 = 1,5
  86.         DO 1002 Ix2 = 1,3
  87.           Px = 0
  88.           DO 1003 Ix3 = 1,4
  89.             Px = Px + Mx1(Ix1,Ix3) * Mx2(Ix3,Ix2)
  90.  1003     CONTINUE
  91.           Mx3(Ix1,Ix2) = Px
  92.  1002   CONTINUE
  93.  1001 CONTINUE
  94.  
  95. ******OUTPUT SECTION
  96.       WRITE(6,9900) CHAR(27),CHAR(27)
  97.       WRITE(6,*) 'First Matrix:'
  98.       WRITE(6,8001) ((Mx1(Ix1,Ix2),Ix2=1,4),Ix1=1,5)
  99.       WRITE(6,*)
  100.       WRITE(6,*) 'Second Matrix:'
  101.       WRITE(6,8002) ((Mx2(Ix1,Ix2),Ix2=1,3),Ix1=1,4)
  102.       WRITE(6,*)
  103.       WRITE(6,*) 'Third Matrix:'
  104.       WRITE(6,8003) ((Mx3(Ix1,Ix2),Ix2=1,3),Ix1=1,5)
  105.  
  106.       STOP
  107.       END
  108.