本文整理汇总了C#中Matrix.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# Matrix.ToString方法的具体用法?C# Matrix.ToString怎么用?C# Matrix.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Matrix
的用法示例。
在下文中一共展示了Matrix.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
private static void Main(string[] args)
{
const int columns = 11;
const int rows = 10;
double[,] array2D = new double[rows, columns];
int rowCount = array2D.GetLength(0); //calculate the counts here to avoid calling method through each pass of the loop
int columnCount = array2D.GetLength(1);
for (int i = 0; i < rowCount; i++)
for (int j = 0; j < columnCount; j++)
array2D[i, j] = i * j + i;
Matrix mat = new Matrix(array2D);
Console.WriteLine(mat.ToString());
mat.ReverseRows();
Console.WriteLine(mat.ToString());
//mat.Transpose();
//Console.WriteLine(mat.ToString()); //print the transposed matrix
Matrix eye = new IdentityMatrix(10);
Console.WriteLine(eye.ToString()); //print the 10 x 10 identity matrix
eye.ReverseRows();
Console.WriteLine(eye.ToString()); //print the identity matrix with rows reversed.
}
示例2: TestTraversalOfMatrixOfSizeOne
public void TestTraversalOfMatrixOfSizeOne()
{
Matrix matrix = new Matrix(1);
Assert.AreEqual(" 0", matrix.ToString());
matrix.Traverse();
Assert.AreEqual(" 1", matrix.ToString());
}
示例3: TestMatrixAverage
public void TestMatrixAverage()
{
Matrix mm = new Matrix(new SizeInt(5, 5));
mm[2, 2] = 16f;
mm[3, 4] = 32f;
Console.WriteLine(mm.ToString());
mm = mm.Average();
Console.WriteLine(mm.ToString());
Console.WriteLine("Done");
}
示例4: Main
static void Main()
{
// Решението работи само за матрици с еднакви размери!
Matrix matrix1 = new Matrix(2, 2);
Matrix matrix2 = new Matrix(2, 2);
Random rand = new Random();
for (int i = 0; i < matrix1.Rows; i++)
{
for (int j = 0; j < matrix1.Cols; j++)
{
matrix1[i, j] = rand.Next(-5, 15);
matrix2[i, j] = rand.Next(-5, 15);
}
}
// Addition Test
Console.WriteLine("Matrix Addition (+): \n");
Console.WriteLine(matrix1.ToString());
Console.WriteLine("+\n");
Console.WriteLine(matrix2.ToString());
Console.WriteLine("=\n");
Matrix sum = matrix1 + matrix2;
Console.WriteLine(sum.ToString());
Console.WriteLine(new string('-', 20));
// Subtraction Test
Console.WriteLine("Matrix Subtraction (-): \n");
Console.WriteLine(matrix1.ToString());
Console.WriteLine("-\n");
Console.WriteLine(matrix2.ToString());
Console.WriteLine("=\n");
Matrix sub = matrix1 - matrix2;
Console.WriteLine(sub.ToString());
Console.WriteLine(new string('-', 20));
// Multiplication Test
Console.WriteLine("Matrix Multiplication (*): \n");
Console.WriteLine(matrix1.ToString());
Console.WriteLine("*\n");
Console.WriteLine(matrix2.ToString());
Console.WriteLine("=\n");
Matrix multiply = matrix1 * matrix2;
Console.WriteLine(multiply.ToString());
Console.WriteLine(new string('-', 20));
}
示例5: Main
private static void Main()
{
Matrix matrix1 = new Matrix(3, 3);
matrix1.Randomize(0, 10);
Console.WriteLine("First matrix");
Console.WriteLine(matrix1.ToString());
Thread.Sleep(150);
Matrix matrix2 = new Matrix(3, 3);
matrix2.Randomize(0, 10);
Console.WriteLine("Second matrix");
Console.WriteLine(matrix2.ToString());
Matrix resultMatrix = matrix1 + matrix2;
Console.WriteLine("Add");
Console.WriteLine(resultMatrix.ToString());
resultMatrix = matrix1 - matrix2;
Console.WriteLine("Substract");
Console.WriteLine(resultMatrix.ToString());
resultMatrix = matrix1 * matrix2;
Console.WriteLine("Multiply");
Console.WriteLine(resultMatrix.ToString());
}
示例6: Main
static void Main()
{
Matrix<int> matrix1= new Matrix<int>(3,3);
matrix1.Add(1, 1, 3);
//Matrix<bool> boolMatrix = new Matrix<bool>(3, 3); //It can NOT be bool
//Matrix<StreamReader> stringMatrix = new Matrix<StreamReader>(3, 3);//It can NOT be string
Matrix<float> mat = new Matrix<float>(2, 2);
mat[0, 0] = 1;
mat[0, 1] = 3;
mat[1, 0] = 0;
mat[1, 1] = -2;
Matrix<float> mat2 = new Matrix<float>(2, 2);
mat2[0, 0] = 7;
mat2[0, 1] = 9;
mat2[1, 0] = 5;
mat2[1, 1] = 2;
Matrix<float> result = new Matrix<float>(2, 2);
result = mat * mat2;
Console.WriteLine(result.ToString());
if (mat2)
{
Console.WriteLine("The matrix is with non-zero elements");
}
else
{
Console.WriteLine("There is 0 in some of the cells");
}
}
示例7: Main
static void Main()
{
//initialize two instances of class Matrix
Matrix matr1 = new Matrix(2, 3);
Matrix matr2 = new Matrix(2, 3);
for (int row = 0; row < 2; row++)
{
for (int col = 0; col < 3; col++)
{
matr1[row, col] = col + 1;
matr2[row, col] = row + 1;
}
}
//output
Console.WriteLine("Mattrix 1:");
Console.WriteLine(matr1.ToString());
Console.WriteLine("Matrix 2:");
Console.WriteLine(matr2.ToString());
//output sum
Console.WriteLine("Sum:");
Matrix sum = matr1 + matr2;
Console.WriteLine(sum.ToString());
//output multiplying
Matrix mult = matr1 * matr2;
Console.WriteLine("Matrix 1 * Matrix 2:");
Console.WriteLine(mult.ToString());
//output substraction
Matrix substr = matr1 - matr2;
Console.WriteLine("Matrix 1 - Matrix 2");
Console.WriteLine(substr.ToString());
}
示例8: Main
static void Main(string[] args)
{
Matrix<int> p = new Matrix<int>(4, 4);
Console.WriteLine(p.ToString());
int[,] test1 = { { 1,0,-2 }, { 0,3,-1 } };
int[,] test2 = { { 1,3,9 }, { -2,-1,11} };
Matrix<int> A = new Matrix<int>(test1);
Matrix<int> B = new Matrix<int>(test2);
Console.WriteLine(A);
Console.WriteLine(B);
Console.WriteLine(A+B);
Console.WriteLine(A-B);
int[,] test3 = { { 1, 0, -2 }, { 0, 3, -1 } };
int[,] test4 = { { 0, 3 }, { -2, -1},{0,4} };
Matrix<int> C = new Matrix<int>(test3);
Matrix<int> D = new Matrix<int>(test4);
Console.WriteLine(C*D);
if (B)
{
Console.WriteLine("true!");
}
else
{
Console.WriteLine("false!");
}
}
示例9: Traverse_WhenDimensionIs1
public void Traverse_WhenDimensionIs1()
{
Matrix matrix = new Matrix(1);
matrix.Traverse();
Assert.AreEqual("1", matrix.ToString());
}
示例10: Main
static void Main(string[] args)
{
Matrix matrix = new Matrix(8);
matrix.Traverse();
Console.WriteLine(matrix.ToString());
}
示例11: Main
static void Main()
{
double[,] first = { { 3, 4, 5, 6 }, { 1, 2, 3, 4 }, { 1, 2, 3, 4 }, { 1, 2, 3, 4 } };
double[,] second = { { 1, 2, 3, 4 }, { 1, 2, 3, 4 }, { 3, 4, 5, 6 }, {22.3, 5, 8, 12 } };
Matrix<double> arrFirst = new Matrix<double>(first);
Matrix<double> arrSecond = new Matrix<double>(second);
//checking if contain zero, return true, if not, return false if there is zero
if (arrFirst)
{
Console.WriteLine("No zero");
}
else
{
Console.WriteLine("There is at least one zero inside");
}
Console.WriteLine();
Console.WriteLine("Sum of the two matrices");
Console.WriteLine(arrFirst + arrSecond.ToString());
Console.WriteLine("Substraction of the two matrices");
Console.WriteLine(arrFirst - arrSecond);
Console.WriteLine("Multiplication of the two matrices");
Console.WriteLine(arrFirst * arrSecond);
}
示例12: Main
static void Main(string[] args)
{
Matrix<int> matrix = new Matrix<int>(3, 2);
matrix[0, 0] = 3;
matrix[0, 1] = -1;
matrix[1, 0] = -6;
matrix[1, 1] = 2;
matrix[2, 0] = -3;
matrix[2, 1] = 1;
Console.WriteLine(matrix.ToString());
Matrix<int> matrix1 = new Matrix<int>(2, 2);
matrix1[0, 0] = 2;
matrix1[0, 1] = -1;
matrix1[1, 0] = -1;
matrix1[1, 1] = -4;
Console.WriteLine(matrix1.ToString());
Console.WriteLine();
Matrix<int> sum = matrix * matrix1;
Console.WriteLine(sum.ToString());
if (matrix1)
{
Console.WriteLine("There are no zero elements!");
}
}
示例13: Main
static void Main(string[] args)
{
var m1 = new Matrix { A = 100, A1 = 200, B = 300, B1 = 400 };
var m2 = new Matrix { A = 10, A1 = 15, B = 8, B1 = 4 };
Console.WriteLine(m1.ToString());
Console.WriteLine(m2.ToString());
var m3 = m1 + m2;
Console.WriteLine(m3.ToString());
var m4 = m3++;
m4++;
Console.WriteLine(m4.ToString());
int x = m1;
Console.WriteLine(x);
Matrix m = (Matrix)x;
Console.WriteLine(m.ToString());
}
示例14: AssertEigenvectorsOrthoNormal
private void AssertEigenvectorsOrthoNormal(Matrix eigenvecs_a)
{
Matrix ident = eigenvecs_a.HermitianConjugate() * eigenvecs_a;
bool bad = false;
for (int i = 0; i < ident.Rows; i++)
{
for (int j = 0; j < ident.Columns; j++)
{
if (i == j && (ident[i, j] - 1).Magnitude > 1e-5)
bad = true;
else if (i != j && ident[i, j].Magnitude > 1e-5)
bad = true;
}
}
if (bad == true)
{
Console.WriteLine("Eigenvectors not orthonormal.");
Console.WriteLine(eigenvecs_a.ToString("0.0000"));
Console.WriteLine(ident.ToString("0.0000"));
throw new Exception("Eigenvectors not orthonormal.");
}
}
示例15: Main
static void Main()
{
Matrix<int> newMatrix = new Matrix<int>(5, 5);
dynamic count = 0;
for (int i = 0; i < newMatrix.RowSize; i++)
{
for (int j = 0; j < newMatrix.ColSize; j++)
{
newMatrix[i, j] = count;
count++;
}
}
Console.WriteLine(newMatrix.ToString());
Console.WriteLine();
Matrix<float> floatMatrix = new Matrix<float>(4, 4);
count = 0.5f;
for (int i = 0; i < floatMatrix.RowSize; i++)
{
for (int j = 0; j < floatMatrix.ColSize; j++)
{
floatMatrix[i, j] = count;
count++;
}
}
Console.WriteLine(floatMatrix.ToString());
}