Как умножить массив на другой массив? - PullRequest
0 голосов
/ 10 июля 2019

Код для умножения 2 массивов и создания нового одномерного массива

Публичная функция APortfolioReturns (AReturns () как двойной, веса () как двойной) как двойной () При ошибке GoTo errHandler

    Dim arrData() As Double
    Dim TotRows As Long
    Dim TotCols As Integer
    Dim RowCtr As Long
    Dim Colctr As Integer
    Dim dblSum As Double

    TotRows = UBound(AReturns, 1) - LBound(AReturns, 1) + 1
    TotCols = UBound(Weights) - LBound(Weights) + 1

    ReDim arrData(1 To TotRows)

    For RowCtr = 1 To TotRows

        dblSum = 0

            For Colctr = 1 To TotCols

                dblSum = dblSum + (AReturns(RowCtr, Colctr) * Weights(Colctr))

            Next

        arrData(RowCtr) = dblSum

    Next

    APortfolioReturns = arrData()

    Exit Function

errHandler:
    MsgBox "An error has occurred." & vbCrLf & Err.Description & vbCrLf & CStr(Err.Number)

End Function


 I have this 2 arrays and i want to create a new 1 d array as follows:


    11  20  45
    12  21  48
    13  22  48.5
    15  23  50
    18  27  52


    0.5
    0.3
    0.2

   The new array would be as follows: 
    first row = (11*0.5) + (20*0.3) + (45*0.2)
    Second row = (12*0.5) + (21*0.3) + (48*0.2)
    third row = (13**0.5) + (22*0.3) + (48.5*0.2) and so on..


But i am not getting the intended result.

Please help me on this multiplication. 

код работает нормально. это не дает никакой ошибки. я получаю результат как 0 во всех строках нового массива. пожалуйста, помогите мне.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...