Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Matrix Multiplication in C#

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Matrix Multiplication in C#

    How do I get the length of rows and columns in a array with rows and columns

    the columns being the 2nd number in [2,3], or 3 in this case, with the rows on the first data item,2?

    Thanks

    Code:
    // matrix-matrix multiplication
    private double [,] MMulti( double [,]A,double [,]B)
    {
    //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.    
    
    //if(a[0].length != b.length) return null; //invalid dims
        
    int n=2;//no of columns A
    int m=1;//no of rows A
    int p=2;// number of colums B
        
    double [,]C = new double[m,p];
    
    for (int i = 0; i < m; ++i)
    {
        for (int j = 0; j < p; ++j)
        {
            C[i, j] = 0;
            for (int k = 0; k < n; ++k)
            {
                C[i, j] += A[i, k] * B[k, j];
            }
        }
    }
    return C;
    }

    #2
    I am totally a greenhand of matrix in C#.The data of matrix is a little complicated for me.I met the similiar problem,have you find your answer?
    I have a function which takes 2D array. I am wondering if there is anyway to get rows and columns of the 2D array without having to iterate on it. Method signature is not to be changes.
    Function is inside the ninetyDegRotator class.
    Code:
    public static int [][] rotate(int [][] matrix){      int [][] rotatedMatrix = new int[4][4];//need actual row n col count here     //logic     return rotatedMatrix;  }
    and main code is
    public static void main(String args[]){ int [][] matrix = new int[][]{ {1,2,3,4}, {5,6,7,8}, {9,0,1,2}, {3,4,5,6} }; System.out.println("length is " + matrix.length); int [][] rotatedMatrix = ninetyDegRotator.rotate(matrix); }
    Also matrix.length gives me 4. So I guess it is number of rows that it gives meaning number of references in 1D array which themselves contain arrays. So is there a way to get the count without iterating?

    Comment


      #3
      Hi Bob, this would not be directly a C# item we could fully support here, however I think those resources would help - http://stackoverflow.com/questions/6...-2-matrix-in-c
      BertrandNinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by adeelshahzad, Today, 03:54 AM
      5 responses
      32 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Started by stafe, 04-15-2024, 08:34 PM
      7 responses
      32 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by merzo, 06-25-2023, 02:19 AM
      10 responses
      823 views
      1 like
      Last Post NinjaTrader_ChristopherJ  
      Started by frankthearm, Today, 09:08 AM
      5 responses
      21 views
      0 likes
      Last Post NinjaTrader_Clayton  
      Started by jeronymite, 04-12-2024, 04:26 PM
      3 responses
      43 views
      0 likes
      Last Post jeronymite  
      Working...
      X