Announcement

Collapse
No announcement yet.

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

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      149 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      85 views
      1 like
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      129 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      125 views
      1 like
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      102 views
      0 likes
      Last Post CarlTrading  
      Working...
      X