Advertisement
ruchamcimatke

ukladrownan.cpp

Apr 4th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. #include "UkladRownanLiniowych.hh"
  2.  
  3. std::istream& operator >> (std::istream &Strm, UkladRownanLiniowych &UklRown)
  4. {
  5. Macierz a;
  6. Wektor b;
  7.  
  8. Strm >> a;
  9. Strm >> b;
  10.  
  11. UklRown.setU(a,b);
  12.  
  13. return Strm;
  14. }
  15. std::ostream& operator << (std::ostream &Strm, const UkladRownanLiniowych &UklRown)
  16. {
  17. Strm <<"Macierz:" <<endl << UklRown.getM() <<endl <<"Wektor wyrazow wolnych:"<<endl << UklRown.getW() <<endl;
  18.  
  19. return Strm;
  20. }
  21.  
  22. Macierz UkladRownanLiniowych:: ZmienKolumnyX()
  23. {
  24. Macierz tmp;
  25. tmp = this->A;
  26.  
  27. for(int i=0; i< ROZMIAR; i++)
  28. {
  29. tmp(0,i)=this->B[i];
  30. }
  31. return tmp;
  32. }
  33.  
  34. Macierz UkladRownanLiniowych:: ZmienKolumnyY()
  35. {
  36. Macierz tmp;
  37. tmp = this->A;
  38.  
  39. for(int i=0; i< ROZMIAR; i++)
  40. {
  41. tmp(1,i)=this->B[i];
  42. }
  43. return tmp;
  44. }
  45.  
  46. Macierz UkladRownanLiniowych:: ZmienKolumnyZ()
  47. {
  48. Macierz tmp;
  49. tmp = this->A;
  50.  
  51. for(int i=0; i< ROZMIAR; i++)
  52. {
  53. tmp(2,i)=this->B[i];
  54. }
  55. return tmp;
  56. }
  57.  
  58. Wektor UkladRownanLiniowych:: rozwiaz()
  59. {
  60. Macierz tmp;
  61. Wektor rozw;
  62. double Wx,Wy,Wz,W;
  63.  
  64. tmp = this->A;
  65.  
  66. W = tmp.Wyznacznik();
  67.  
  68. tmp = this->ZmienKolumnyX();
  69. Wx = tmp.Wyznacznik();
  70.  
  71. tmp = this->ZmienKolumnyY();
  72. Wy = tmp.Wyznacznik();
  73.  
  74. tmp = this -> ZmienKolumnyZ();
  75. Wz = tmp.Wyznacznik();
  76.  
  77. if( W != 0)
  78. {
  79. rozw[0] = Wx/W;
  80. rozw[1] = Wy/W;
  81. rozw[2] = Wz/W;
  82.  
  83. return rozw;
  84. }
  85. else if( W = 0 && (Wx !=0 || Wy !=0 || Wz !=0) )
  86. {
  87. cout << "Uklad sprzeczny. Brak rozwiazan" << endl;
  88. return rozw;
  89. }
  90. else
  91. {
  92. cout << "Uklad nieoznacznony. Nieskonczenie wiele rozwiazan" << endl;
  93. return rozw;
  94. }
  95. }
  96.  
  97. Wektor UkladRownanLiniowych:: Wektorbledu(Wektor W)
  98. {
  99. Wektor Wynik;
  100.  
  101. Wynik = (this -> A * W);
  102.  
  103. Wynik = Wynik - this->B;
  104.  
  105. return Wynik;
  106.  
  107.  
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement