1

Using the Matrix<double> from Mathdotnet.Numerics, I am willing to apply a custom aggregating function for each cell of the resulting matrix of a multiply operation.

For instance, on a 2x2 matrix:

enter image description here

My will is to have a specific f function (the one above, shown as example, is the default matrix/vector multiplication).

Is there an existing method in the Matrix world that takes such a Func<Vector<double>, Vector<double>, double> argument?

Askolein
  • 3,250
  • 3
  • 28
  • 40

1 Answers1

1

Based on your diagram, it looks like you're trying to get the dot product of two vectors.

MathDotNet provides a function for DotProduct. It would look like this:

Vector<double> v1;
Vector<double> v2;
double result = v1.DotProduct(v2);

And it returns the sum of v1[i]*v2[i] for all i.

See the documentation here.

If you would like to create your own function to manipulate two vectors and return a double, that would be fairly easy.

double MyNewFunction(Vector v1, Vector v2) 
{
    // your code here, as an example here is the matrix multiplication
    double returnValue;
    if (v1.Count!= v2.Count) 
    {
        // process error
    }
    for (int i = 0; i< v1.Count; i++) 
    {
        returnValue += v1.Item[i] * v2.Item[i];
    }
    return returnValue;
}
Olivier De Meulder
  • 2,493
  • 3
  • 25
  • 30
  • I'm willing to apply my own `f` method. Not the default one, that is, indeed, the `dot`as you wrote (or simply put: the matrix mulitplication). It seems my question was not well phrased (question updated for disambiguation). – Askolein Nov 23 '15 at 07:37
  • @Askolein I updated my answer, I hope that answers your question. – Olivier De Meulder Nov 23 '15 at 14:34
  • The question is about finding a way to use your `MyNewFunction` in a Matrix method. As a parameter. Look at Matrix.Map2(...). It's an example of usage. But I need a equivalent that matches 2 vectors (row + column) instead of just two cells. – Askolein Nov 24 '15 at 10:30