有谁知道网络的苏里奥方法nding任何N×N矩阵的特征多项式? 我发现第一个系数,是显而易见的,但我怎么能找到其他系数? 之后,我需要逆矩阵,但我知道怎么办。
#include <iostream>
#include <fstream>
using namespace std;
double trace(double a[5][5],int n){
int i;
double trace=0;
for(i=0;i<n;i++)
trace+=a[i][i];
return trace;
}
double prod(double a[5][5],double b[5][5],int n) {
double c[5][5];
int i,j,k;
cout << "\nProd:\n";
for(i=0;i<n;++i){
for(j=0;j<n;++j){
c[i][j]=0;
for(k=0;k<n;++k)
c[i][j]=c[i][j]+(a[i][k]*b[k][j]);
cout << c[i][j] << " ";
}
cout << "\n";
}
return c[i][j];
}
double theta(double a[5][5], int n){
int i;
double theta[5];
theta[1]=-trace(a,n);
for(i=0;i<n;i++)
cout << "Theta[" << i+1 << "]=" << theta[i+1] << "\n";
return theta[i+1];
}
int main(){
ifstream f("a.txt");
ifstream g("b.txt");
double a[5][5],b[5][5];
int i,j,n;
f >> n;
g >> n;
for(i=0;i<n;++i)
for(j=0;j<n;++j)
f >> a[i][j];
cout << "Matrix A:"<<endl;
for(i=0;i<n;++i){
for(j=0;j<n;++j)
cout << a[i][j] << " ";
cout << endl;
}
cout << endl;
for(i=0;i<n;++i)
for(j=0;j<n;++j)
g >> b[i][j];
cout << "Matrix B:" << endl;
for(i=0;i<n;++i){
for(j=0;j<n;++j)
cout << b[i][j] << " ";
cout << endl;
}
cout << endl;
cout << "Trace = ";
cout << trace(a,n);
cout << endl;
prod(a,b,n);
cout << endl;
theta(a,n);
}