As per following the inital thread make efficient the copy of symmetric matrix in c-sharp from cMinor.
I would be quite interesting with some inputs in how to build a symmetric square matrix multiplication with one line vector and one column vector by using an array implementation of the matrix, instead of the classical
long s = 0;
List<double> columnVector = new List<double>(N);
List<double> lineVector = new List<double>(N);
//- init. vectors and symmetric square matrix m
for (int i=0; i < N; i++)
{
for(int j=0; j < N; j++){
s += lineVector[i] * columnVector[j] * m[i,j];
}
}
Thanks for your input !
You could make matrix multiplication pretty fast with unsafe code. I have blogged about it.
The line vector times symmetric matrix equals to the transpose of the matrix times the column vector. So only the column vector case needs to be considered.
Originally the
i
-th element ofy=A*x
is defined asbut since
A
is symmetric, the sum be split into sums, one below the diagonal and the other aboveFrom the other posting the matrix index is
For a
N×N
symmetric matrixA = new double[N*(N+1)/2];
In
C#
code the above is:Example for you to try:
To get the quadratic form do a dot product with the multiplication result vector
x·A·y = Dot(x,A*y)
Making matrix multiplication as fast as possible is easy: Use a well-known library. Insane amounts of performance work has gone into such libraries. You cannot compete with that.