Question

In: Computer Science

Write a Fortran program that reads in two NxN matrices A & B, and prints their...

Write a Fortran program that reads in two NxN matrices A & B, and prints their element-wise sum (A+B), element-wise difference (A-B), element-wise division (A/B), element-wise product (A*B), and their matrix product (matmul(A,B)), on the standard output.

Solutions

Expert Solution

Addition
program sum                                          !a: name of program
        !an example of program  structure                    !b: a  comment   
        real :: answer,x,y                                   !c: declarations
        print  *, 'Enter two numbers'                        !d: output
        read  *, x                                           !e: input
        read  *, y                                           !e: input
        answer=x+y                                           !f: arithmetic
        print  *, 'The total is ', answer                    !g: output
        end  program sum                                     !h: end of program
program matMulProduct

   integer, dimension(3,3) :: a, b, c
   integer :: i, j
    
   do i = 1, 3
      do j = 1, 3
         a(i, j) = i+j
      end do
   end do
   
   print *, 'Matrix Multiplication: A Matrix'
   
   do i = 1, 3
      do j = 1, 3
         print*, a(i, j)
      end do
   end do
   
   do i = 1, 3
      do j = 1, 3
         b(i, j) = i*j
      end do
   end do
   
   Print*, 'Matrix Multiplication: B Matrix'
   
   do i = 1, 3
      do j = 1, 3
         print*, b(i, j)
      end do
   end do
   
   c = matmul(a, b)
   Print*, 'Matrix Multiplication: Result Matrix'
   
   do i = 1, 3
      do j = 1, 3
         print*, c(i, j)
      end do
   end do
   
end program matMulProduct
Matrix Multiplication: A Matrix
2
3
4
3
4
5
4
5
6
 Matrix Multiplication: B Matrix
1
2
3
2
4
6
3
6
9
Matrix Multiplication: Result Matrix
20
40
60
26
52
78
32
64
96

Related Solutions

Write a program that reads two square Matrices of size 2 *2 and calculate and print...
Write a program that reads two square Matrices of size 2 *2 and calculate and print the sum of them. Also, the signed value of the matrices are input by the user Note: 1) Use CamelCase for variables names 2) Write Comments such as your name, the class, description of the program, and description of your logic. 4) Use sematic names for your variables 5) Your program should be C program not C++.
Write a program that reads and prints a joke and its punch line from two different...
Write a program that reads and prints a joke and its punch line from two different files. The first file contains a joke, but not its punch line. The second file has the punch line as its last line, preceded by “garbage.” The main function of your program should open the two files then call two functions, passing each one the file it needs. The first function should read and display each line in the file it is passed (the...
Write a Python program that reads in an amount in cents and prints the dollar amount...
Write a Python program that reads in an amount in cents and prints the dollar amount in that and the remaining value in cents. For example, if the amount reads in is 360 (cents), the program would print 3 dollars and 60 cents. if the amount read in is 75 (cents), the program would print 0 dollars and 75 cents.
in.java Write a program that reads an integer from the user and prints a rectangle of...
in.java Write a program that reads an integer from the user and prints a rectangle of starts of width 5 3 and height N. Sample run 1: Enter N: 5 *** *** *** *** *** Bye Sample run 2: Enter N: 8 *** *** *** *** *** *** *** *** Bye Sample run 3: Enter N: 2 *** *** Bye Sample run 4: Enter N: -2 Bye
C program, please Write a program that reads a sequence of 10 integer inputs and prints...
C program, please Write a program that reads a sequence of 10 integer inputs and prints the smallest and largest of the inputs and the number of even and odd inputs. for a beginner please, you could use a while loop,if-else,
*Java program* Use while loop 1.) Write a program that reads an integer, and then prints...
*Java program* Use while loop 1.) Write a program that reads an integer, and then prints the sum of the even and odd integers. 2.) Write program to calculate the sum of the following series where in is input by user. (1/1 + 1/2 + 1/3 +..... 1/n)
Write a C++ program to determine the sum of two 1-D matrices: A = [a b...
Write a C++ program to determine the sum of two 1-D matrices: A = [a b c d] B = [e f g h] The user will provide the values of a to h.
Write a C++ program to multiply two matrices a and b and print the result. Use...
Write a C++ program to multiply two matrices a and b and print the result. Use two-dimensional arrays to represent the matrices.
Write a pyhton program that reads a stream of bits, e.g. 11001, and calculates and prints...
Write a pyhton program that reads a stream of bits, e.g. 11001, and calculates and prints the decimal value of the binary number represented by the entered bits, i.e. 25 in this case.
Write a c program that reads a .img file by rows and columns and prints out...
Write a c program that reads a .img file by rows and columns and prints out the arrays. The .img file contains h(the height) and w(the width) of the text size. An example .img file would be: 2 4 DFJSK HJ5JF HFDY5
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT