Write a programme to find multiplication
of matrices of order 4*4 and find the total number of comparison, total no. of
assignments, total number of multiplications and total number of addition
operations required in the programme.
sangeedesign:
can u send answer for this question?pls
Answers
Answered by
1
I write the algorithm. Please write the program in the
language of your choice.
Integer M = 4 , N = 4 , P = 4 ;
Integer A [0..M-1, 0.. N-1] , B [0..N-1, 0..P-1], AB[ 0..M-1, 0..P-1] ;
Multiply(INPUT M, N, P, A, B ; OUTPUT AB)
Begin
Integer I, J, K ;
I = 0 ;
While (I < M) do
K = 0 ;
While ( K < P) do
AB[I, K] = 0 ; J = 0 ;
while ( J < N ) do
AB[I, K] = AB[I, K] + A[I, J] * B[J, K] ;
end while
K = K + 1
end while
I = I + 1 ;
end while
end program
============================
M = 4, N = 4 , P = 4
Number of assignments = 1 + M [ 2 + P { 3 + N } ] = 1 + M (2 + 3 P + N P )
= 1 + 2 M + 3 M P + M N P = 1 + 8 + 48 + 64 = 121
Number of comparisons = M * [ P ( N + 1 ) + 1 ] + 1 = M (PN + P + 1) + 1
= M N P + M P + M + 1 = 4³ + 4² + 4 + 1 = 85
Number of additions = M [ 1 + P ( 1 + N ) ] = M + M P + M P N = 4 + 16 + 64 = 84
Number of Multiplications = M [ P ( N ) ] = M N P = 64
Integer M = 4 , N = 4 , P = 4 ;
Integer A [0..M-1, 0.. N-1] , B [0..N-1, 0..P-1], AB[ 0..M-1, 0..P-1] ;
Multiply(INPUT M, N, P, A, B ; OUTPUT AB)
Begin
Integer I, J, K ;
I = 0 ;
While (I < M) do
K = 0 ;
While ( K < P) do
AB[I, K] = 0 ; J = 0 ;
while ( J < N ) do
AB[I, K] = AB[I, K] + A[I, J] * B[J, K] ;
end while
K = K + 1
end while
I = I + 1 ;
end while
end program
============================
M = 4, N = 4 , P = 4
Number of assignments = 1 + M [ 2 + P { 3 + N } ] = 1 + M (2 + 3 P + N P )
= 1 + 2 M + 3 M P + M N P = 1 + 8 + 48 + 64 = 121
Number of comparisons = M * [ P ( N + 1 ) + 1 ] + 1 = M (PN + P + 1) + 1
= M N P + M P + M + 1 = 4³ + 4² + 4 + 1 = 85
Number of additions = M [ 1 + P ( 1 + N ) ] = M + M P + M P N = 4 + 16 + 64 = 84
Number of Multiplications = M [ P ( N ) ] = M N P = 64
Similar questions