本文整理汇总了C#中SparseMatrix.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# SparseMatrix.ToString方法的具体用法?C# SparseMatrix.ToString怎么用?C# SparseMatrix.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SparseMatrix
的用法示例。
在下文中一共展示了SparseMatrix.ToString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
// create SparseMatrix
Console.WriteLine("Create SparseMatrix ...");
SparseMatrix<string> matrix = new SparseMatrix<string>();
matrix[0] = new SparseVector<string>(new IdxDat<string>[] {
new IdxDat<string>(1, "a"),
new IdxDat<string>(3, "b"),
new IdxDat<string>(4, "c") });
matrix[2] = new SparseVector<string>(new IdxDat<string>[] {
new IdxDat<string>(2, "d"),
new IdxDat<string>(4, "e"),
new IdxDat<string>(5, "f") });
matrix[3] = new SparseVector<string>(new IdxDat<string>[] {
new IdxDat<string>(0, "g"),
new IdxDat<string>(3, "h"),
new IdxDat<string>(5, "i") });
matrix[4] = new SparseVector<string>(new IdxDat<string>[] {
new IdxDat<string>(1, "j"),
new IdxDat<string>(2, "k"),
new IdxDat<string>(4, "l") });
Console.WriteLine(matrix.ToString("E"));
// get rows
Console.WriteLine("Get rows ...");
Console.WriteLine(matrix[0]);
Console.WriteLine(matrix[3]);
// set rows
Console.WriteLine("Set rows ...");
matrix[1] = new SparseVector<string>(new IdxDat<string>[] { new IdxDat<string>(0, "j"), new IdxDat<string>(3, "k") });
matrix[2] = null;
matrix[4] = null;
Console.WriteLine(matrix.ToString("E"));
// count rows
Console.WriteLine("Count rows ...");
Console.WriteLine("{0} != {1}", matrix.GetRowCount(), matrix.GetLastNonEmptyRowIdx() + 1);
// trim rows
Console.WriteLine("Trim rows ...");
matrix.TrimRows();
Console.WriteLine(matrix.ToString("E"));
// add more items
Console.WriteLine("Add more items ...");
matrix[0].Add("*");
matrix[3].AddRange(new IdxDat<string>[] {
new IdxDat<string>(1, "!"),
new IdxDat<string>(2, "?"),
new IdxDat<string>(4, "&") });
matrix[2] = new SparseVector<string>(new IdxDat<string>[] {
new IdxDat<string>(2, "d"),
new IdxDat<string>(4, "e"),
new IdxDat<string>(5, "f") });
Console.WriteLine(matrix.ToString("E"));
// get items
Console.WriteLine("Get items ...");
Console.WriteLine(matrix[0, 1]);
Console.WriteLine(matrix[2, 2]);
Console.WriteLine(matrix[2][4]);
Console.WriteLine(matrix.TryGet(2, 4, "missing"));
Console.WriteLine(matrix.TryGet(2, 6, "missing"));
// set items
Console.WriteLine("Set items ...");
matrix[0, 1] = "l";
matrix[2, 3] = "m";
matrix[3][4] = "n";
Console.WriteLine(matrix.ToString("E"));
// check for items
Console.WriteLine("Check for items ...");
Console.WriteLine(matrix.ContainsAt(0, 1));
Console.WriteLine(matrix.ContainsAt(1, 1));
Console.WriteLine(matrix.Contains("c"));
Console.WriteLine(matrix.Contains("C"));
int rowIdx = -1, colIdx = -1;
matrix.IndexOf("c", ref rowIdx, ref colIdx);
Console.WriteLine("{0}, {1}", rowIdx, colIdx);
// check for rows and columns
Console.WriteLine("Check for rows and columns ...");
Console.WriteLine(matrix.ContainsColAt(0));
Console.WriteLine(matrix.ContainsColAt(100));
Console.WriteLine(matrix.ContainsRowAt(0));
Console.WriteLine(matrix.ContainsRowAt(100));
// get first and last non-empty row and column index
Console.WriteLine("Get first and last non-empty row and column index ...");
Console.WriteLine(matrix.GetFirstNonEmptyRowIdx());
Console.WriteLine(matrix.GetLastNonEmptyRowIdx());
Console.WriteLine(matrix.GetFirstNonEmptyColIdx());
Console.WriteLine(matrix.GetLastNonEmptyColIdx());
// get first and last item in row
Console.WriteLine("Get first and last item in row ...");
Console.WriteLine(matrix[0].First);
Console.WriteLine(matrix[3].Last);
// create another SparseMatrix
Console.WriteLine("Create another SparseMatrix ...");
SparseMatrix<string> matrix2 = new SparseMatrix<string>();
matrix2[0] = new SparseVector<string>(new IdxDat<string>[] {
new IdxDat<string>(0, "A"),
new IdxDat<string>(2, "B"),
new IdxDat<string>(3, "C") });
matrix2[2] = new SparseVector<string>(new IdxDat<string>[] {
new IdxDat<string>(1, "D"),
new IdxDat<string>(3, "E") });
matrix2[3] = new SparseVector<string>(new IdxDat<string>[] {
//.........这里部分代码省略.........
示例2: button6_Click
private void button6_Click(object sender, EventArgs e)
{
DateTime dt = DateTime.Now;
eps = Math.Pow(10, -Convert.ToInt32(tbeps.Text));
button7.Enabled = false;
button8.Enabled = false;
button9.Enabled = false;
double[,] mat = tomat(tbA.Text);
lA = new SparseMatrix(mat);
n=lA.Rows;
show("Lib A initiated !");
lB = new SparseMatrix(n, 1);
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
lB[i, 0] += mat[i, j] * (j + 1);
tbB.Clear();
tbB.AppendText(lB.ToString());
h = new Householder(lA);
tbR.Clear();
tbR.AppendText(h.R().ToString());
tbQ.Clear();
tbQ.AppendText(h.Q().ToString());
Matrix lQp = new SparseMatrix(n, n);
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
lQp[j, i] = h.Q()[i, j];
Matrix lBp = lQp.Multiply(lB);
tbBb.Clear();
tbBb.AppendText(lBp.ToString());
show("Lib Q,R calculated !");
button7.Enabled = true;
button9.Enabled = true;
tqr = DateTime.Now - dt;
}