Matrix 执行未知操作的矩阵操作代码
我无法理解以下所有代码。我想我指出的代码的中间部分是在执行乘法,但我不确定,有人能给我解释一下代码的中间部分试图实现什么吗 我了解数组元素的输入和输出部分,但不了解实际操作 我明白这一点:Matrix 执行未知操作的矩阵操作代码,matrix,matrix-multiplication,Matrix,Matrix Multiplication,我无法理解以下所有代码。我想我指出的代码的中间部分是在执行乘法,但我不确定,有人能给我解释一下代码的中间部分试图实现什么吗 我了解数组元素的输入和输出部分,但不了解实际操作 我明白这一点: #include "stdafx.h" #include<iostream> using namespace std; int main() { int i,j,k,n; float a[100][200],t; cout
#include "stdafx.h"
#include<iostream>
using namespace std;
int main()
{
int i,j,k,n;
float a[100][200],t;
cout<<"Enter order of matrix-";
cin>>n;
cout<<"Enter elements of matrix"<<endl;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
cin>>a[i][j];
#包括“stdafx.h”
#包括
使用名称空间std;
int main()
{
int i,j,k,n;
浮点数a[100][200],t;
coutn;
cout您的代码正在尝试反转矩阵。下面是代码正在执行的操作
假设您有一个nxn矩阵a,我们可以创建一个新的nx2n矩阵
B=人工智能
其中I是一个nxn单位矩阵。B的创建是这些行试图做的:
for(i=0;i<n;i++)
{
for(j=n;j<2*n;j++) // makes sure you are only accessing columns in the right hand part of the matrix
{
if(i==j-n)
a[i][j]=1;
else
a[i][j]=0;
}
}
for(i=0;i您的代码正在尝试反转矩阵。下面是代码正在执行的操作
假设您有一个nxn矩阵a,我们可以创建一个新的nx2n矩阵
B=人工智能
其中I是一个nxn单位矩阵。B的创建是这些行试图做的:
for(i=0;i<n;i++)
{
for(j=n;j<2*n;j++) // makes sure you are only accessing columns in the right hand part of the matrix
{
if(i==j-n)
a[i][j]=1;
else
a[i][j]=0;
}
}
for(i=0;iis)有一种更简单的方法可以做到这一点吗?一般来说不是。如果你的矩阵是2x2,你可以使用一种叫做cramer法则的东西,但通常你会被这种方法或“奇异值分解”所困扰要得到一个更复杂的伪逆。数字配方书中有SVD,这样你可以比较复杂度,如果你想的话。有没有更简单的方法来做到这一点?一般来说不是。如果你的矩阵是2x2,你可以使用一种叫做cramer规则的东西,但通常你会被这个或“奇异值分解”所困扰为了得到一个更复杂的伪逆,数字配方书中有SVD,所以你可以比较复杂度。
for(i=0;i<n;i++)
{
for(j=n;j<2*n;j++) // makes sure you are only accessing columns in the right hand part of the matrix
{
if(i==j-n)
a[i][j]=1;
else
a[i][j]=0;
}
}
for(i=0;i<n;i++) //transform B matrix into C matrix
{
t=a[i][i];
for(j=i;j<2*n;j++)
a[i][j]=a[i][j]/t;
for(j=0;j<n;j++)
{
if(i!=j)
{
t=a[j][i];
for(k=0;k<2*n;k++)
a[j][k]=a[j][k]-t*a[i][k];
}
}
}