本文整理汇总了C#中MathNet.Numerics.LinearAlgebra.Double.DenseMatrix.Add方法的典型用法代码示例。如果您正苦于以下问题:C# DenseMatrix.Add方法的具体用法?C# DenseMatrix.Add怎么用?C# DenseMatrix.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MathNet.Numerics.LinearAlgebra.Double.DenseMatrix
的用法示例。
在下文中一共展示了DenseMatrix.Add方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanAddSparseMatricesBothWays
public void CanAddSparseMatricesBothWays()
{
var m1 = new SparseMatrix(1, 3);
var m2 = Matrix<double>.Build.SparseOfArray(new double[,] { { 0, 1, 1 } });
var sum1 = m1 + m2;
var sum2 = m2 + m1;
Assert.IsTrue(sum1.Equals(m2));
Assert.IsTrue(sum1.Equals(sum2));
Matrix<double> sparseResult = new SparseMatrix(1, 3);
sparseResult.Add(m2, sparseResult);
Assert.IsTrue(sparseResult.Equals(sum1));
sparseResult = Matrix<double>.Build.SparseOfArray(new double[,] { { 0, 1, 1 } });
sparseResult.Add(m1, sparseResult);
Assert.IsTrue(sparseResult.Equals(sum1));
sparseResult = Matrix<double>.Build.SparseOfArray(new double[,] { { 0, 1, 1 } });
m1.Add(sparseResult, sparseResult);
Assert.IsTrue(sparseResult.Equals(sum1));
sparseResult = Matrix<double>.Build.SparseOfArray(new double[,] { { 0, 1, 1 } });
sparseResult.Add(sparseResult, sparseResult);
Assert.IsTrue(sparseResult.Equals(2*sum1));
Matrix<double> denseResult = new DenseMatrix(1, 3);
denseResult.Add(m2, denseResult);
Assert.IsTrue(denseResult.Equals(sum1));
denseResult = Matrix<double>.Build.DenseOfArray(new double[,] { { 0, 1, 1 } });
denseResult.Add(m1, denseResult);
Assert.IsTrue(denseResult.Equals(sum1));
var m3 = Matrix<double>.Build.DenseOfArray(new double[,] { { 0, 1, 1 } });
var sum3 = m1 + m3;
var sum4 = m3 + m1;
Assert.IsTrue(sum3.Equals(m3));
Assert.IsTrue(sum3.Equals(sum4));
}
示例2: Run
//.........这里部分代码省略.........
Console.WriteLine(@"Multiply vector by matrix using method LeftMultiply. (A.LeftMultiply(vec, vec))");
Console.WriteLine(vector.ToString("#0.00\t", formatProvider));
Console.WriteLine();
// Multiply matrix by matrix
// 1. Using operator "*"
resultM = matrixA * matrixB;
Console.WriteLine(@"Multiply matrix by matrix using operator *. (result = A * B)");
Console.WriteLine(resultM.ToString("#0.00\t", formatProvider));
Console.WriteLine();
// 2. Using Multiply method and getting result into different matrix instance
resultM = (DenseMatrix)matrixA.Multiply(matrixB);
Console.WriteLine(@"Multiply matrix by matrix using method Multiply. (result = A.Multiply(B))");
Console.WriteLine(resultM.ToString("#0.00\t", formatProvider));
Console.WriteLine();
// 3. Using Multiply method and updating matrix itself
matrixA.Multiply(matrixB, matrixA);
Console.WriteLine(@"Multiply matrix by matrix using method Multiply. (A.Multiply(B, A))");
Console.WriteLine(matrixA.ToString("#0.00\t", formatProvider));
Console.WriteLine();
// Pointwise multiplies matrix with another matrix
// 1. Using PointwiseMultiply method and getting result into different matrix instance
resultM = (DenseMatrix)matrixA.PointwiseMultiply(matrixB);
Console.WriteLine(@"Pointwise multiplies matrix with another matrix using method PointwiseMultiply. (result = A.PointwiseMultiply(B))");
Console.WriteLine(resultM.ToString("#0.00\t", formatProvider));
Console.WriteLine();
// 2. Using PointwiseMultiply method and updating matrix itself
matrixA.PointwiseMultiply(matrixB, matrixA);
Console.WriteLine(@"Pointwise multiplies matrix with another matrix using method PointwiseMultiply. (A.PointwiseMultiply(B, A))");
Console.WriteLine(matrixA.ToString("#0.00\t", formatProvider));
Console.WriteLine();
// Pointwise divide matrix with another matrix
// 1. Using PointwiseDivide method and getting result into different matrix instance
resultM = (DenseMatrix)matrixA.PointwiseDivide(matrixB);
Console.WriteLine(@"Pointwise divide matrix with another matrix using method PointwiseDivide. (result = A.PointwiseDivide(B))");
Console.WriteLine(resultM.ToString("#0.00\t", formatProvider));
Console.WriteLine();
// 2. Using PointwiseDivide method and updating matrix itself
matrixA.PointwiseDivide(matrixB, matrixA);
Console.WriteLine(@"Pointwise divide matrix with another matrix using method PointwiseDivide. (A.PointwiseDivide(B, A))");
Console.WriteLine(matrixA.ToString("#0.00\t", formatProvider));
Console.WriteLine();
// Addition
// 1. Using operator "+"
resultM = matrixA + matrixB;
Console.WriteLine(@"Add matrices using operator +. (result = A + B)");
Console.WriteLine(resultM.ToString("#0.00\t", formatProvider));
Console.WriteLine();
// 2. Using Add method and getting result into different matrix instance
resultM = (DenseMatrix)matrixA.Add(matrixB);
Console.WriteLine(@"Add matrices using method Add. (result = A.Add(B))");
Console.WriteLine(resultM.ToString("#0.00\t", formatProvider));
Console.WriteLine();
// 3. Using Add method and updating matrix itself
matrixA.Add(matrixB, matrixA);
Console.WriteLine(@"Add matrices using method Add. (A.Add(B, A))");
Console.WriteLine(matrixA.ToString("#0.00\t", formatProvider));
Console.WriteLine();
// Subtraction
// 1. Using operator "-"
resultM = matrixA - matrixB;
Console.WriteLine(@"Subtract matrices using operator -. (result = A - B)");
Console.WriteLine(resultM.ToString("#0.00\t", formatProvider));
Console.WriteLine();
// 2. Using Subtract method and getting result into different matrix instance
resultM = (DenseMatrix)matrixA.Subtract(matrixB);
Console.WriteLine(@"Subtract matrices using method Subtract. (result = A.Subtract(B))");
Console.WriteLine(resultM.ToString("#0.00\t", formatProvider));
Console.WriteLine();
// 3. Using Subtract method and updating matrix itself
matrixA.Subtract(matrixB, matrixA);
Console.WriteLine(@"Subtract matrices using method Subtract. (A.Subtract(B, A))");
Console.WriteLine(matrixA.ToString("#0.00\t", formatProvider));
Console.WriteLine();
// Divide by scalar
// 1. Using Divide method and getting result into different matrix instance
resultM = (DenseMatrix)matrixA.Divide(3.0);
Console.WriteLine(@"Divide matrix by scalar using method Divide. (result = A.Divide(3.0))");
Console.WriteLine(resultM.ToString("#0.00\t", formatProvider));
Console.WriteLine();
// 2. Using Divide method and updating matrix itself
matrixA.Divide(3.0, matrixA);
Console.WriteLine(@"Divide matrix by scalar using method Divide. (A.Divide(3.0, A))");
Console.WriteLine(matrixA.ToString("#0.00\t", formatProvider));
Console.WriteLine();
}
示例3: StructureRecurse
public void StructureRecurse(DenseMatrix X, DenseMatrix Psi, DenseVector d, int n, ref DenseMatrix Q,
ref DenseMatrix O, ref DenseMatrix pT_n)
{
//O = O(t-1) O_enxt = O(t)
//o should be a column vector ( in matrix form)
var x = new DenseVector(X.RowCount);
var psi = new DenseVector(Psi.ColumnCount);
X.Column(n, x);
Psi.Row(n, psi);
DenseMatrix p_n = CalculateGreatPsi((DenseMatrix) x.ToColumnMatrix(), (DenseMatrix) psi.ToRowMatrix());
pT_n = (DenseMatrix) p_n.Transpose();
double ee = Math.Abs(d[n] - (pT_n.Multiply(O))[0, 0]);
double temp = 1 + (pT_n.Multiply(Q)).Multiply(p_n)[0, 0];
double ae = Math.Abs(ee/temp);
if (ee >= ae)
{
var L = (DenseMatrix) Q.Multiply(p_n).Multiply(1/temp);
Q = (DenseMatrix) ((DenseMatrix.Identity(Q.RowCount).Subtract(L.Multiply(pT_n))).Multiply(Q));
O = (DenseMatrix) O.Add(L*ee);
}
else
{
Q = (DenseMatrix) DenseMatrix.Identity(Q.RowCount).Multiply(Q);
}
}