当前位置: 首页>>代码示例>>C#>>正文


C# Matrix.getLength方法代码示例

本文整理汇总了C#中Matrix.getLength方法的典型用法代码示例。如果您正苦于以下问题:C# Matrix.getLength方法的具体用法?C# Matrix.getLength怎么用?C# Matrix.getLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Matrix的用法示例。


在下文中一共展示了Matrix.getLength方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: multiply

    public void multiply(Matrix multipliedMatrix)
    {
        if (multipliedMatrix.getLength(0) != matrix.GetLength(1))
        {
            throw new IndexOutOfRangeException();
        }

        Matrix newMatrix = new Matrix(matrix.GetLength(0), multipliedMatrix.getLength(1));

        for (int row = 0; row < matrix.GetLength(0); row++)
        {
            for (int col = 0; col < multipliedMatrix.getLength(1); col++)
            {
                int result = 0;
                for (int multipliedRow = 0; multipliedRow < matrix.GetLength(1); multipliedRow++)
                {
                    result += matrix[row, multipliedRow] * multipliedMatrix.get(multipliedRow, col);
                }

                newMatrix.set(row, col, result);
            }
        }

        matrix = newMatrix.getMatrix();
    }
开发者ID:shnogeorgiev,项目名称:Software-University-Courses,代码行数:25,代码来源:Matrix.cs

示例2: add

    public void add(Matrix addedMatrix)
    {
        if (addedMatrix.getLength(0) != matrix.GetLength(0) &&
            addedMatrix.getLength(1) != matrix.GetLength(1))
        {
            throw new IndexOutOfRangeException();
        }

        for (int row = 0; row < matrix.GetLength(0); row++)
        {
            for (int col = 0; col < matrix.GetLength(1); col++)
            {
                matrix[row, col] += addedMatrix.get(row, col);
            }
        }
    }
开发者ID:shnogeorgiev,项目名称:Software-University-Courses,代码行数:16,代码来源:Matrix.cs

示例3: Main

    static void Main()
    {
        Matrix matrix = new Matrix(4, 4);

        for (int row = 0; row < matrix.getLength(0); row++)
        {
            for (int col = 0; col < matrix.getLength(1); col++)
            {
                matrix.set(row, col, randGenerator.Next(10));
            }
        }

        Matrix secondMatrix = new Matrix(4, 4);

        for (int row = 0; row < secondMatrix.getLength(0); row++)
        {
            for (int col = 0; col < secondMatrix.getLength(1); col++)
            {
                secondMatrix.set(row, col, randGenerator.Next(10));
            }
        }

        Console.WriteLine("First: ");
        Console.WriteLine(matrix.toString());
        Console.WriteLine(new string('-', 20));
        Console.WriteLine("Second:");
        Console.WriteLine(secondMatrix.toString());
        Console.WriteLine(new string('-', 20));

        matrix.add(secondMatrix);
        Console.WriteLine("Added: ");
        Console.WriteLine(matrix.toString());
        Console.WriteLine(new string('-', 20));
        
        matrix.subtract(secondMatrix);
        Console.WriteLine("Subtracted: ");
        Console.WriteLine(matrix.toString());
        Console.WriteLine(new string('-', 20));

        matrix.multiply(secondMatrix);
        Console.WriteLine("Multiplied: ");
        Console.WriteLine(matrix.toString());
        Console.WriteLine(new string('-', 20));
    }
开发者ID:shnogeorgiev,项目名称:Software-University-Courses,代码行数:44,代码来源:ClassMatrix.cs


注:本文中的Matrix.getLength方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。