question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to multiply Matrix and Vector?

See original GitHub issue
var bArray = new Entity[size];
Array.Fill(bArray, Entity.Number.Integer.One);

var bVector = MathS.Matrices.Vector(bArray);

for (int i = 0; i < 10000; i++)
{
    var product = MathS.Matrices.ScalarProduct(bVector, bVector);
    var normedVector = (bVector / MathS.Sqrt(product)).EvalTensor();
    var vector =  MatrixVectorMultiplication(tensor, normedVector);
    bVector = vector;
}

I see no way to implement MatrixVectorMultiplication (N*M x M*1 = N*1), except for manual row iteration and dot products. I tried overriden operator* and TensorVectorDotProduct, both are inapplicable (unless I create a copy of the vector as matrix with 1 column). I’d expect both GenericTensor and AngouriMath to support such basic operation.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
WhiteBlackGoosecommented, Mar 25, 2021

In case you missed, the new version is published. Wiki for it is here.

1reaction
WhiteBlackGoosecommented, Mar 23, 2021

Now you can create matrices and vectors in a more convenient way, as well as work with them. Say,

var m1 = MathS.Matrix(new Entity[,]
{
    { 1, 2 },
    { 3, 4 }
});
var v = MathS.Vector(0, 1);

var m2 = m1 * v; // performs a matrix multiplication
var len = MathS.Abs(m2).Evaled; // finds the length of a vector as square root of the sum of the squared values of the vector

To perform scalar product of two vectors, simply transpose one of them

var v1 = MathS.Vector(1, 2);
var v2 = MathS.Vector(3, 4);
var v3 = v1.T * v2;
Console.WriteLine(v3.InnerSimplified);

P. S. These updates will be relevant since 1.3-preview.2. But they’re already on the master branch

Read more comments on GitHub >

github_iconTop Results From Across the Web

Multiplying matrices and vectors
Although it may look confusing at first, the process of matrix-vector multiplication is actually quite simple. One takes the dot product of x...
Read more >
Multiplying a Vector by a Matrix
Let us define the multiplication between a matrix A and a vector x in which the number of columns in A equals the...
Read more >
Matrix-vector multiplication
As a “row-wise”, vector-generating process: Matrix-vector multiplication defines a process for creating a new vector using an existing vector ...
Read more >
Matrix-Vector Multiplication
We can only multiply an m × n matrix by a vector in Rn. That is, in Ax the matrix must have as...
Read more >
Matrix multiplication
In mathematics, particularly in linear algebra, matrix multiplication is a binary operation that produces a matrix from two matrices.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found