本文整理汇总了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();
}
示例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);
}
}
}
示例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));
}