您如何将矩阵本身相乘? [英] How do you multiply a matrix by itself?

查看:190
本文介绍了您如何将矩阵本身相乘?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我到目前为止所拥有的,但我认为这是不对的.

This is what i have so far but I do not think it is right.

for (int i = 0 ; i < 5; i++)
{
    for (int j = 0;  j < 5; j++)
    {
        matrix[i][j] += matrix[i][j] * matrix[i][j];
    }
}

推荐答案

我认为您不能就地自行乘以矩阵.

I don't think you can multiply a matrix by itself in-place.

for (i = 0; i < 5; i++) {
    for (j = 0; j < 5; j++) {
        product[i][j] = 0;
        for (k = 0; k < 5; k++) {
            product[i][j] += matrix[i][k] * matrix[k][j];
        }
    }
}

即使您使用了较少的朴素矩阵乘法(即除O(n 3 )算法之外的其他算法),您仍然需要额外的存储空间.

Even if you use a less naïve matrix multiplication (i.e. something other than this O(n3) algorithm), you still need extra storage.

这篇关于您如何将矩阵本身相乘?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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