高效率地 - 对称矩阵乘法在C#两个向量 [英] Make efficient - A symmetric matrix multiplication with two vectors in c#

查看:290
本文介绍了高效率地 - 对称矩阵乘法在C#两个向量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

按以下的inital线程使高效从cMinor C-锐对称矩阵的副本。

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 !

推荐答案

行向量倍对称矩阵等于矩阵倍列向量的转置。所以只需要列向量的情况下加以考虑。

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.

本来 I 的个元素 Y = A * X 定义为

y[i] = SUM( A[i,j]*x[j], j=0..N-1 )

但由于 A 是对称的,总和被分成金额,以下任一对角线及以上

but since A is symmetric, the sum be split into sums, one below the diagonal and the other above

y[i] = SUM( A[i,j]*x[j], j=0..i-1) + SUM( A[i,j]*x[j], j=i..N-1 )

从其他张贴矩阵指数

A[i,j] = A[i*N-i*(i+1)/2+j]  // j>=i
A[i,j] = A[j*N-j*(j+1)/2+i]  // j< i



对于 N×N 对称矩阵 A =新的双[N *(N + 1)/ 2];

C#代码:

int k;
for(int i=0; i<N; i++)
{
    // start sum with zero
    y[i]=0;
    // below diagonal
    k=i;
    for(int j=0; j<=i-1; j++)
    {                    
        y[i]+=A[k]*x[j];
        k+=N-j-1;
    }
    // above diagonal
    k=i*N-i*(i+1)/2+i;
    for(int j=i; j<=N-1; j++)
    {
        y[i]+=A[k]*x[j];
        k++;
    }
}



例子你可以试试:

Example for you to try:

| -7  -6  -5  -4  -3 | | -2 |   | 10 |
| -6  -2  -1   0   1 | | -1 |   | 16 |
| -5  -1   2   3   4 | |  0 | = | 22 |
| -4   0   3   5   6 | |  1 |   | 25 |
| -3   1   4   6   7 | |  7 |   | 25 |

要获得二次形式做点积的乘法结果的vector X ·A·Y =点(X,A * Y)

To get the quadratic form do a dot product with the multiplication result vector x·A·y = Dot(x,A*y)

这篇关于高效率地 - 对称矩阵乘法在C#两个向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆