本文整理汇总了C#中Matrix.SubMatrix方法的典型用法代码示例。如果您正苦于以下问题:C# Matrix.SubMatrix方法的具体用法?C# Matrix.SubMatrix怎么用?C# Matrix.SubMatrix使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Matrix
的用法示例。
在下文中一共展示了Matrix.SubMatrix方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestMethodMatrix
public void TestMethodMatrix()
{
Matrix matrix1 = new Matrix(2, 3);
Assert.AreEqual(matrix1.Row, 2);
Assert.AreEqual(matrix1.Column, 3);
Matrix matrix2 = new Matrix(new double[,] { { 1, 2, 0 }, { 3, 4, 5 } });
Assert.AreEqual(matrix2.Row, 2);
Assert.AreEqual(matrix2.Column, 3);
matrix2.Resize(2, 2);
Matrix matrix3 = new Matrix(new double[,] { { 1, 2 }, { 3, 4 } });
Assert.AreEqual(matrix2.GetHashCode(), matrix3.GetHashCode());
Assert.IsTrue(matrix2.Equals(matrix3));
matrix3.AddRowToRow(0, 1, -1);
Assert.AreEqual(matrix3, new Matrix(new double[,] { { 1, 2 }, { 2, 2 } }));
matrix3.AddRowToRow(1, 0, 1);
Assert.AreEqual(matrix3, new Matrix(new double[,] { { 3, 4 }, { 2, 2 } }));
matrix3.MultiplyFactorToRow(1, 0.5);
Assert.AreEqual(matrix3, new Matrix(new double[,] { { 3, 4 }, { 1, 1 } }));
matrix3.AddNewRowToEnd(new Vector(new double[] { 5, 6 }));
Assert.AreEqual(matrix3[2, 0], 5);
Assert.AreEqual(matrix3[2, 1], 6);
Matrix matrix4 = matrix3.SubMatrix(1, 1, 2, 1);
Assert.AreEqual(matrix4, new Matrix(new double[,] { { 1 }, { 6 } }));
Assert.AreEqual(matrix3, new Matrix(new double[,] { { 3, 4 }, { 1, 1 }, { 5, 6 } }));
matrix3.DelRowFromEnd();
Assert.AreEqual(matrix3, new Matrix(new double[,] { { 3, 4 }, { 1, 1 } }));
Matrix matrix5 = new Matrix(new double[,] { { 1, 2 }, { 1, 2 } });
Assert.AreEqual(matrix3 + matrix5, new Matrix(new double[,] { { 4, 6 }, { 2, 3 } }));
Assert.AreEqual(matrix3 - matrix5, new Matrix(new double[,] { { 2, 2 }, { 0, -1 } }));
Assert.AreEqual(matrix3 * matrix5, new Matrix(new double[,] { { 7, 14 }, { 2, 4 } }));
Assert.AreEqual(matrix5 * matrix3, new Matrix(new double[,] { { 5, 6 }, { 5, 6 } }));
Assert.AreEqual(matrix3 * matrix4, new Matrix(new double[,] { { 27 }, { 7 } }));
}
示例2: ComputeShift
/// <summary>
/// The shift is generally taken to be the smallest eigenvalue of the 2 × 2 matrix in the bottom.
/// </summary>
/// <returns></returns>
private Complex ComputeShift(Matrix mat)
{
try {
Matrix subMat = mat.SubMatrix(mat.Height - 2, mat.Height, mat.Width - 2, mat.Width);
Complex trace = subMat.Trace();
Complex det = subMat.Determinant();
Complex eig1 = (trace + ComplexMath.Sqrt(trace * trace - 4 * det)) / 2;
Complex eig2 = (trace - ComplexMath.Sqrt(trace * trace - 4 * det)) / 2;
Complex eigen = ComplexMath.Min(eig1, eig2);
return eigen;
} catch (MatrixException) {
return 0;
}
}
示例3: Divide8
private static IEnumerable<Tuple<Matrix, Matrix>> Divide8(Matrix a, Matrix b)
{
yield return
Tuple.Create(a.SubMatrix(0, 0, a.Height/2, a.Width/2), b.SubMatrix(0, 0, b.Height/2, b.Width/2));
yield return
Tuple.Create(a.SubMatrix(0, a.Width/2, a.Height/2, a.Width/2 + a.Width%2),
b.SubMatrix(b.Height/2, 0, b.Height/2 + b.Height%2, b.Width/2));
yield return
Tuple.Create(a.SubMatrix(0, 0, a.Height/2, a.Width/2),
b.SubMatrix(0, b.Width/2, b.Height/2, b.Width/2 + b.Width%2));
yield return Tuple.Create(a.SubMatrix(0, a.Width/2, a.Height/2, a.Width/2 + a.Width%2),
b.SubMatrix(b.Height/2, b.Width/2, b.Height/2 + b.Height%2, b.Width/2 + b.Width%2));
yield return
Tuple.Create(a.SubMatrix(a.Height/2, 0, a.Height/2 + a.Height%2, a.Width/2),
b.SubMatrix(0, 0, b.Height/2, b.Width/2));
yield return Tuple.Create(a.SubMatrix(a.Height/2, a.Width/2, a.Height/2 + a.Height%2,
a.Width/2 + a.Width%2), b.SubMatrix(b.Height/2, 0, b.Height/2 + b.Height%2, b.Width/2));
yield return
Tuple.Create(a.SubMatrix(a.Height/2, 0, a.Height/2 + a.Height%2, a.Width/2),
b.SubMatrix(0, b.Width/2, b.Height/2, b.Width/2 + b.Width%2));
yield return Tuple.Create(a.SubMatrix(a.Height/2, a.Width/2, a.Height/2 + a.Height%2,
a.Width/2 + a.Width%2), b.SubMatrix(b.Height/2, b.Width/2, b.Height/2 + b.Height%2,
b.Width/2 + b.Width%2));
}
示例4: InvertByRowOperations
public Matrix InvertByRowOperations()
{
if (!IsSquare)
throw new Exception("Matrix not square!");
Matrix retval = new Matrix(Rows, Columns * 2);
// build the inversion matrix
for (int i = 0; i < Columns; i++)
for (int j = 0; j < Rows; j++)
retval[j, i] = this[j, i];
for (int i = Columns; i < Columns * 2; i++)
for (int j = 0; j < Rows; j++)
retval[j, i] = ((i - Columns) == j) ? 1 : 0;
// do the columns one by one
for (int col = 0; col < Columns; col++)
{
if (retval[col, col] == new Complex(0, 0))
{
for (int row = col + 1; row < Rows; row++)
{
if (retval[row, col] != new Complex(0, 0))
{
retval.AddRow(col, row, 1);
}
}
}
if (retval[col, col] == new Complex(0, 0))
{
// apparently we are singular.
throw new Exception("Singular matrix.");
}
retval.ScaleRow(col, 1 / retval[col, col]);
for (int row = 0; row < Rows; row++)
{
if (row == col)
continue;
Complex scale = -retval[row, col];
retval.AddRow(row, col, scale);
}
}
// extract the actual inversion matrix
return retval.SubMatrix(0, Columns, Rows, Columns);
}
示例5: TestMatrixSubtraction
public void TestMatrixSubtraction()
{
Matrix m1, m2;
m1 = new Matrix(2, 2);
m2 = new Matrix(2, 2);
// init m1
m1.SetValue(0, 0, 1);
m1.SetValue(0, 1, 1);
m1.SetValue(1, 0, 1);
m1.SetValue(1, 1, 1);
// init m2
m2.SetValue(0, 0, 2);
m2.SetValue(0, 1, 2);
m2.SetValue(1, 0, 2);
m2.SetValue(1, 1, 2);
Matrix diff = m1.SubMatrix(m2);
Matrix result;
result = new Matrix(2, 2);
result.SetValue(0, 0, -1);
result.SetValue(0, 1, -1);
result.SetValue(1, 0, -1);
result.SetValue(1, 1, -1);
Assert.AreEqual(result, diff);
// test minus operator
diff = m1 - m2;
Assert.AreEqual(result, diff);
}
示例6: TransformDx2y2
private static OrbitalDesignation TransformDx2y2(Matrix sym)
{
if (sym.SubMatrix(0, 0, 2, 2).IsDiagonal)
return OrbitalDesignation.dx2y2;
return OrbitalDesignation.none;
}