c++ - Souriau method for Characteristic Polynomial -
does know souriau method finding characteristic polynomial of n × n matrix? found out first coefficient, obvious, how can find out other coefficients? after need inverse matrix know how.
#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); }
taken https://math.stackexchange.com/a/405975/115115 J. M.
c=a; k=1,…,n if k>1 c=a*(c+c[n−k+1]*i); c[n−k]=−tr(c)/k; end
if can read german, there wiki page extended pseudo-code algortihm @ https://de.wikipedia.org/wiki/algorithmus_von_faddejew-leverrier (add 2017: or equally english version https://en.wikipedia.org/wiki/faddeev%e2%80%93leverrier_algorithm)
if want directly compute inverse matrix, have, in wiki page, use matrix b related matrix c above via c=ab. gives, can seen in wiki page, more complicated algorithm. however, last matrix b satisfies ab=-c[0]*i, inverse matrix, if there one, can directly computed.
Comments
Post a Comment