Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- using namespace std;
- int main ()
- {
- double A[3][3]={{1,2,3},{4,5,6},{7,8,9}}; //Matrix A
- double r[3]={2,0,0}; //Vektor r
- double z[3]; //Zum rechnen mit r, ohne dass es sich verändert
- double b; //Betrag von r
- double v[3]={2,0,0}; //Vergleichswert für r, Startwert ist r
- int n=0; //Zählt die Rechenschritte
- bool vergleich = false;
- while(!vergleich)
- {
- n+=1;
- z[0]=(A[0][0]*r[0]+A[0][1]*r[1]+A[0][2]*r[2]);
- z[1]=(A[1][0]*r[0]+A[1][1]*r[1]+A[1][2]*r[2]);
- z[2]=(A[2][0]*r[0]+A[2][1]*r[1]+A[2][2]*r[2]);
- r[0]=z[0];
- r[1]=z[1];
- r[2]=z[2];
- b=(sqrt(r[0]*r[0]+r[1]*r[1]+r[2]*r[2]));
- r[0]=(r[0]/b);
- r[1]=(r[1]/b);
- r[2]=(r[2]/b);
- if((r[0]==v[0]) && (r[1]==v[1]) && (r[2]==v[2]))
- vergleich = true;
- v[0]=r[0]; v[1]=r[1]; v[2]=r[2];
- }
- cout << "Vektor r nach " << n << " Wiederholungen stationär." << endl << endl;
- cout << " " << r[0] << endl;
- cout << "r=" << r[1] << endl;
- cout << " " << r[2] << endl << endl;
- cout << "r ist Eigenvektor von A." << endl;
- cout << endl << " \u25b2" << endl;
- cout << "\u25b2 \u25b2" << endl << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement