Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. using namespace std;
  4.  
  5. int main ()
  6. {
  7.  
  8. double A[3][3]={{1,2,3},{4,5,6},{7,8,9}}; //Matrix A
  9. double r[3]={2,0,0}; //Vektor r
  10. double z[3]; //Zum rechnen mit r, ohne dass es sich verändert
  11. double b; //Betrag von r
  12. double v[3]={2,0,0}; //Vergleichswert für r, Startwert ist r
  13. int n=0; //Zählt die Rechenschritte
  14.  
  15. bool vergleich = false;
  16.  
  17. while(!vergleich)
  18. {
  19. n+=1;
  20.  
  21. z[0]=(A[0][0]*r[0]+A[0][1]*r[1]+A[0][2]*r[2]);
  22. z[1]=(A[1][0]*r[0]+A[1][1]*r[1]+A[1][2]*r[2]);
  23. z[2]=(A[2][0]*r[0]+A[2][1]*r[1]+A[2][2]*r[2]);
  24.  
  25. r[0]=z[0];
  26. r[1]=z[1];
  27. r[2]=z[2];
  28.  
  29. b=(sqrt(r[0]*r[0]+r[1]*r[1]+r[2]*r[2]));
  30.  
  31. r[0]=(r[0]/b);
  32. r[1]=(r[1]/b);
  33. r[2]=(r[2]/b);
  34.  
  35. if((r[0]==v[0]) && (r[1]==v[1]) && (r[2]==v[2]))
  36. vergleich = true;
  37.  
  38. v[0]=r[0]; v[1]=r[1]; v[2]=r[2];
  39. }
  40.  
  41. cout << "Vektor r nach " << n << " Wiederholungen stationär." << endl << endl;
  42. cout << " " << r[0] << endl;
  43. cout << "r=" << r[1] << endl;
  44. cout << " " << r[2] << endl << endl;
  45. cout << "r ist Eigenvektor von A." << endl;
  46. cout << endl << " \u25b2" << endl;
  47. cout << "\u25b2 \u25b2" << endl << endl;
  48.  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement