本文整理汇总了C#中MathNet.Numerics.LinearAlgebra.Double.DenseMatrix.LeftMultiply方法的典型用法代码示例。如果您正苦于以下问题:C# DenseMatrix.LeftMultiply方法的具体用法?C# DenseMatrix.LeftMultiply怎么用?C# DenseMatrix.LeftMultiply使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MathNet.Numerics.LinearAlgebra.Double.DenseMatrix
的用法示例。
在下文中一共展示了DenseMatrix.LeftMultiply方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
/// <summary>
/// Run example
/// </summary>
/// <seealso cref="http://en.wikipedia.org/wiki/Matrix_multiplication#Scalar_multiplication">Multiply matrix by scalar</seealso>
/// <seealso cref="http://reference.wolfram.com/mathematica/tutorial/MultiplyingVectorsAndMatrices.html">Multiply matrix by vector</seealso>
/// <seealso cref="http://en.wikipedia.org/wiki/Matrix_multiplication#Matrix_product">Multiply matrix by matrix</seealso>
/// <seealso cref="http://en.wikipedia.org/wiki/Matrix_multiplication#Hadamard_product">Pointwise multiplies matrix with another matrix</seealso>
/// <seealso cref="http://en.wikipedia.org/wiki/Matrix_%28mathematics%29#Basic_operations">Addition and subtraction</seealso>
public void Run()
{
// Initialize IFormatProvider to print matrix/vector data
var formatProvider = (CultureInfo)CultureInfo.InvariantCulture.Clone();
formatProvider.TextInfo.ListSeparator = " ";
// Create matrix "A"
var matrixA = new DenseMatrix(new[,] { { 1.0, 2.0, 3.0 }, { 4.0, 5.0, 6.0 }, { 7.0, 8.0, 9.0 } });
Console.WriteLine(@"Matrix A");
Console.WriteLine(matrixA.ToString("#0.00\t", formatProvider));
Console.WriteLine();
// Create matrix "B"
var matrixB = new DenseMatrix(new[,] { { 1.0, 3.0, 5.0 }, { 2.0, 4.0, 6.0 }, { 3.0, 5.0, 7.0 } });
Console.WriteLine(@"Matrix B");
Console.WriteLine(matrixB.ToString("#0.00\t", formatProvider));
Console.WriteLine();
// Multiply matrix by scalar
// 1. Using operator "*"
var resultM = 3.0 * matrixA;
Console.WriteLine(@"Multiply matrix by scalar using operator *. (result = 3.0 * A)");
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(3.0);
Console.WriteLine(@"Multiply matrix by scalar using method Multiply. (result = A.Multiply(3.0))");
Console.WriteLine(resultM.ToString("#0.00\t", formatProvider));
Console.WriteLine();
// 3. Using Multiply method and updating matrix itself
matrixA.Multiply(3.0, matrixA);
Console.WriteLine(@"Multiply matrix by scalar using method Multiply. (A.Multiply(3.0, A))");
Console.WriteLine(matrixA.ToString("#0.00\t", formatProvider));
Console.WriteLine();
// Multiply matrix by vector (right-multiply)
var vector = new DenseVector(new[] { 1.0, 2.0, 3.0 });
Console.WriteLine(@"Vector");
Console.WriteLine(vector.ToString("#0.00\t", formatProvider));
Console.WriteLine();
// 1. Using operator "*"
var resultV = matrixA * vector;
Console.WriteLine(@"Multiply matrix by vector using operator *. (result = A * vec)");
Console.WriteLine(resultV.ToString("#0.00\t", formatProvider));
Console.WriteLine();
// 2. Using Multiply method and getting result into different vector instance
resultV = (DenseVector)matrixA.Multiply(vector);
Console.WriteLine(@"Multiply matrix by vector using method Multiply. (result = A.Multiply(vec))");
Console.WriteLine(resultV.ToString("#0.00\t", formatProvider));
Console.WriteLine();
// 3. Using Multiply method and updating vector itself
matrixA.Multiply(vector, vector);
Console.WriteLine(@"Multiply matrix by vector using method Multiply. (A.Multiply(vec, vec))");
Console.WriteLine(vector.ToString("#0.00\t", formatProvider));
Console.WriteLine();
// Multiply vector by matrix (left-multiply)
// 1. Using operator "*"
resultV = vector * matrixA;
Console.WriteLine(@"Multiply vector by matrix using operator *. (result = vec * A)");
Console.WriteLine(resultV.ToString("#0.00\t", formatProvider));
Console.WriteLine();
// 2. Using LeftMultiply method and getting result into different vector instance
resultV = (DenseVector)matrixA.LeftMultiply(vector);
Console.WriteLine(@"Multiply vector by matrix using method LeftMultiply. (result = A.LeftMultiply(vec))");
Console.WriteLine(resultV.ToString("#0.00\t", formatProvider));
Console.WriteLine();
// 3. Using LeftMultiply method and updating vector itself
matrixA.LeftMultiply(vector, vector);
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();
//.........这里部分代码省略.........
示例2: ColorizeVectors
public Color[,] ColorizeVectors(Color[,] input)
{
if (LongestChord.firstPixel == null || LongestChord.secondPixel == null
|| LongestPerpendicularChord.firstPixel == null || LongestPerpendicularChord.secondPixel == null)
return input;
Color[,] output = (Color[,])input.Clone();
double angle = LongestChord.orientation;
double uv1CosAngle = Math.Cos(angle);
double uv1SinAngle = Math.Sin(angle);
double pAngle = Math.PI / 2;
double[] rotationArray = new double[] { Math.Cos(pAngle), -1.0 * Math.Sin(pAngle), Math.Sin(pAngle), Math.Cos(pAngle) };
Matrix<double> rotationMatrix = new DenseMatrix(2, 2, rotationArray);
Vector<double> unitVector1 = new DenseVector(new double[] { uv1CosAngle, uv1SinAngle });
Vector<double> unitVector2 = new DenseVector(new double[2]);
rotationMatrix.LeftMultiply(unitVector1, unitVector2);
double uv2CosAngle = unitVector2[0];
double uv2SinAngle = unitVector2[1];
int lcX = 0;
if (uv1CosAngle > 0)
if (LongestChord.firstPixel.X < LongestChord.secondPixel.X)
lcX = LongestChord.firstPixel.X;
else
lcX = LongestChord.secondPixel.X;
else
if (LongestChord.firstPixel.X < LongestChord.secondPixel.X)
lcX = LongestChord.secondPixel.X;
else
lcX = LongestChord.firstPixel.X;
int lcY = 0;
if (uv1SinAngle > 0)
if (LongestChord.firstPixel.Y < LongestChord.secondPixel.Y)
lcY = LongestChord.firstPixel.Y;
else
lcY = LongestChord.secondPixel.Y;
else
if (LongestChord.firstPixel.Y < LongestChord.secondPixel.Y)
lcY = LongestChord.secondPixel.Y;
else
lcY = LongestChord.firstPixel.Y;
for (int i = 0; i < LongestChord.distance; i++)
{
int uv1X = OffsetX + lcX + ((int)Math.Round(uv1CosAngle * i));
int uv1Y = OffsetY + lcY + ((int)Math.Round(uv1SinAngle * i));
output[uv1X, uv1Y] = Color.Red;
}
int lpcX = 0;
if (uv2CosAngle > 0)
if (LongestPerpendicularChord.firstPixel.X < LongestPerpendicularChord.secondPixel.X)
lpcX = LongestPerpendicularChord.firstPixel.X;
else
lpcX = LongestPerpendicularChord.secondPixel.X;
else
if (LongestPerpendicularChord.firstPixel.X < LongestPerpendicularChord.secondPixel.X)
lpcX = LongestPerpendicularChord.secondPixel.X;
else
lpcX = LongestPerpendicularChord.firstPixel.X;
int lpcY = 0;
if (uv2SinAngle > 0)
if (LongestPerpendicularChord.firstPixel.Y < LongestPerpendicularChord.secondPixel.Y)
lpcY = LongestPerpendicularChord.firstPixel.Y;
else
lpcY = LongestPerpendicularChord.secondPixel.Y;
else
if (LongestPerpendicularChord.firstPixel.Y < LongestPerpendicularChord.secondPixel.Y)
lpcY = LongestPerpendicularChord.secondPixel.Y;
else
lpcY = LongestPerpendicularChord.firstPixel.Y;
for (int i = 0; i < LongestPerpendicularChord.distance; i++)
{
int uv2X = OffsetX + lpcX + ((int)Math.Round(uv2CosAngle * i));
int uv2Y = OffsetY + lpcY + ((int)Math.Round(uv2SinAngle * i));
output[uv2X, uv2Y] = Color.Blue;
}
return output;
}