有谁知道寻找任何 n × n 矩阵的特征多项式的 Souriau 方法?我找到了第一个系数,很明显,但是我怎样才能找到其他系数呢?在我需要对矩阵求逆但我知道怎么做之后。
#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);
}