How to resolve the algorithm Matrix multiplication step by step in the Fortran programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Matrix multiplication step by step in the Fortran programming language

Table of Contents

Problem Statement

Multiply two matrices together. They can be of any dimensions, so long as the number of columns of the first matrix is equal to the number of rows of the second matrix.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Matrix multiplication step by step in the Fortran programming language

Source code in the fortran programming language

real, dimension(n,m) :: a = reshape( [ (i, i=1, n*m) ], [ n, m ] )
real, dimension(m,k) :: b = reshape( [ (i, i=1, m*k) ], [ m, k ] )
real, dimension(size(a,1), size(b,2)) :: c    ! C is an array whose first dimension (row) size
                                              ! is the same as A's first dimension size, and
                                              ! whose second dimension (column) size is the same
                                              ! as B's second dimension size.

c = matmul( a, b )

print *, 'A'
do i = 1, n
    print *, a(i,:)
end do

print *,
print *, 'B'
do i = 1, m
    print *, b(i,:)
end do

print *,
print *, 'C = AB'
do i = 1, n
    print *, c(i,:)
end do


        program mm
          real   , allocatable :: a(:,:),b(:,:)
          integer              :: l=5,m=6,n=4
          a = reshape([1:l*m],[l,m])
          b = reshape([1:m*n],[m,n])
          print'(<n>f15.7)',transpose(matmul(a,b))
        end program


  

You may also check:How to resolve the algorithm Calkin-Wilf sequence step by step in the FreeBASIC programming language
You may also check:How to resolve the algorithm Horner's rule for polynomial evaluation step by step in the Wren programming language
You may also check:How to resolve the algorithm Priority queue step by step in the zkl programming language
You may also check:How to resolve the algorithm Zsigmondy numbers step by step in the Sidef programming language
You may also check:How to resolve the algorithm Forward difference step by step in the Racket programming language