Results 1 to 2 of 2

Thread: Problem solving multiplication of two matrices with entries decimal

  1. #1

    Question Problem solving multiplication of two matrices with entries decimal



    Register for a FREE account, and/
    or Log in to avoid these ads!

    Problem solving multiplication of two matrices with entries decimal in vba code:
    Code:
    Option Explicit
    
    Public MatrixA(30, 30) As Long
    Public MatrixB(30, 30) As Long
    Public MatrixC(30, 30) As Long
    Public RowA As Integer
    Public ColA As Integer
    Public RowB As Integer
    Public ColB As Integer
    
    Function ProperMaticesSizes() As Boolean
        If ColA <> RowB Then ProperMaticesSizes = False Else ProperMaticesSizes = True
    End Function
    
    Sub ReadMatrixA()
    Dim i As Integer
    Dim j As Integer
    Dim intLastRow As Integer
    Dim intLastCol As Integer
    
    Sheets("Sheet1").Activate
    
    intLastRow = ActiveSheet.UsedRange.Rows.Count
    intLastCol = ActiveSheet.UsedRange.Columns.Count
    
    For i = 1 To intLastRow
        For j = 1 To intLastCol
            MatrixA(i - 1, j - 1) = Cells(i, j)
        Next
    Next
    RowA = intLastRow
    ColA = intLastCol
    
    End Sub
    Sub ReadMatrixB()
    Dim i As Integer
    Dim j As Integer
    Dim intLastRow As Integer
    Dim intLastCol As Integer
    
    Sheets("Sheet2").Activate
    
    intLastRow = ActiveSheet.UsedRange.Rows.Count
    intLastCol = ActiveSheet.UsedRange.Columns.Count
    
    For i = 1 To intLastRow
        For j = 1 To intLastCol
            MatrixB(i - 1, j - 1) = Cells(i, j)
        Next
    Next
    RowB = intLastRow
    ColB = intLastCol
    
    End Sub
    
    Sub MultiplyMatrices()
    
    Call ReadMatrixA
    Call ReadMatrixB
    
    If ProperMaticesSizes = False Then
        MsgBox "Wrong matrices sizes. Re-dimension them"
        Exit Sub
    End If
    
    Sheets("Sheet3").Activate
    
    Dim i As Integer
    Dim j As Integer
    Dim k As Integer
    
    For i = 1 To RowA
        For j = 1 To ColB
            MatrixC(i - 1, j - 1) = 0
            For k = 1 To ColA
                MatrixC(i - 1, j - 1) = MatrixC(i - 1, j - 1) + MatrixA(i - 1, k - 1) * MatrixB(k - 1, j - 1)
            Next
            Cells(i, j) = MatrixC(i - 1, j - 1)
        Next
    Next
    
    End Sub
    Not respond to decimals
    Can someone tell what the problem is:

  2. #2
    Solved

    Public MatrixA(30, 30) As double Public MatrixB(30, 30) As double Public MatrixC(30, 30) As double

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •