1· (5 0 points) Write a VBA code to perform matrix multiplication operation: whe
ID: 3593774 • Letter: 1
Question
1· (5 0 points) Write a VBA code to perform matrix multiplication operation: where A and B are given matrices in spreadsheet. Then use your code to calculate matrix multiplication: 1 -2 3 4 4 -3 2 1 -1 2 3 12 2 -1 2 1 1 1 -2 1 2 -2 3-4 113×413 2 1-2 2J4x5 Specific requirements: 1) Select and read matrices [A] and [B] from spreadsheet; 2) Check if the number of columns in matrix [A] matches with the number of rows in matrix [B]; if not match, please prompt a matrix IC] to spreadsheet; 4) you are not allowed to use "Application. WorkSheetFunction.MMult" in your code. Hint: you can use “UBound(A,2)" to find the number of columns in matrix [A]. sage "The size of input matrices doesn't match!" and stop the calculation; 3) Return result rule then annlv your code to solve belowExplanation / Answer
Function Multiply(ParamArray IPM() As Variant) As Variant
Dim i As Long, j As Long, k As Long, L As Long, temp As Double
Dim M As Variant, Matrix As Variant, hold As Variant
'***********************************************
'* Function multiplies n matrices. *
'* Matrices must be conformable: *
'* Matrix M(i) is mxn and matrix M(i+1) is nxm *
'***********************************************
'Cycle through the parameter array multiplying each matrix
M = IPM(0)
For L = LBound(IPM) To UBound(IPM) - 1
'Check that matrices are comformable
If UBound(M, 2) <> UBound(IPM(L + 1), 1) Then Exit Function
'Redimension the product matrix
ReDim Matrix(1 To UBound(M, 1), 1 To UBound(IPM(L + 1), 2))
'Multiplication routine
For i = 1 To UBound(M, 1)
For j = 1 To UBound(IPM(L + 1), 2)
For k = 1 To UBound(IPM(L + 1), 1)
temp = temp + M(i, k) * IPM(L + 1)(k, j)
Next k
Matrix(i, j) = temp
temp = 0
Next j
Next i
M = Matrix
Next L
M_Mult = Matrix
End Function
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.