Guest User

Untitled

a guest
Jun 21st, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. //////////////////////////////////////////////////////////////////////////////
  2. // Praktikum Informatik 1
  3. // Versuch 7: Lˆsung eines mathematischen Anwendungsproblems
  4. //
  5. // Datei: main.cpp
  6. // Inhalt: Hauptprogramm
  7. //////////////////////////////////////////////////////////////////////////////
  8.  
  9. #include "QMatrix.h"
  10. #include "Vektor.h"
  11. #include "LR.h"
  12. #include "Gauss.h"
  13. #include "Cramer.h"
  14. #include <iostream>
  15.  
  16. using namespace std;
  17.  
  18. //////////////////////////////////////////////////////////////////////////////
  19. void Eingabe(QMatrix& A, int n);
  20. void Eingabe(Vektor& b, int n);
  21.  
  22. //////////////////////////////////////////////////////////////////////////////
  23.  
  24. /*
  25. Die Benennung der Variablen entspricht, in diesem Versuch,
  26. den mathematischen Bezeichnungen im Script.
  27. Matrizen haben einen Groflbuchstaben und
  28. Vektoren einen Kleinbuchstaben.
  29. */
  30.  
  31. //////////////////////////////////////////////////////////////////////////////
  32.  
  33. int main()
  34. {
  35. cout << "Wieviele Gleichungen/Unbekannte hat ihr LGS.." ;
  36. int dim;
  37. cin >> dim;
  38. QMatrix A(dim);
  39. Vektor b(dim);
  40. Vektor x(dim);
  41. Eingabe(A,dim);
  42. Eingabe(b,dim);
  43. cout << A;
  44.  
  45. LR system1(dim);
  46. x = system1.loese(A,b);
  47. cout << "Loesung nach LR-Zerlegung:" << endl;
  48. cout << x << endl;
  49.  
  50. Gauss system2(dim);
  51. x = system2.loese(A, b);
  52. cout << "Loesung nach Gauss:" << endl;
  53. cout << x << endl;
  54.  
  55. Cramer system3(dim);
  56. x = system3.loese(A, b);
  57. cout << "Loesung nach Cramer:" << endl;
  58. //cout << x << endl;
  59.  
  60. return 0;
  61. }
  62.  
  63. //////////////////////////////////////////////////////////////////////////////
  64. void Eingabe(QMatrix& A, int n)
  65. {
  66. double zahl;
  67. cout << "Bitte geben sie die Matrix(" << n << " Zeilen/Spalten) ein..." << endl;
  68. for (int i = 0; i < n; i++)
  69. {
  70. for (int j = 0; j < n; j++)
  71. {
  72. cout << "a" << (i+1) << (j+1) << ": ";
  73. cin >> zahl;
  74. A.set(i,j, zahl);
  75. }
  76. cout << endl;
  77. }
  78. }
  79.  
  80. //////////////////////////////////////////////////////////////////////////////
  81. void Eingabe(Vektor& b, int n)
  82. {
  83. double zahl;
  84. cout << "Bitte geben sie den Vektor b (" << n << " Eintraege) ein..." << endl;
  85. for (int i = 0; i < n; i++)
  86. {
  87. cout << "b" << (i+1) << ": ";
  88. cin >> zahl;
  89. b.set(i, zahl);
  90. }
  91.  
  92. }
Add Comment
Please, Sign In to add comment