Advertisement
Guest User

Untitled

a guest
Nov 14th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.14 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <ctime>
  3. #include <iostream>
  4. #include <algorithm>
  5. #include <cmath>
  6. #include <conio.h>
  7. #include <stdio.h>
  8. #include <Windows.h>
  9. #include <vector>
  10. #include <set>
  11. #include <tuple>
  12.  
  13. using namespace std;
  14.  
  15. const int MAX_SIZE = 100;
  16. const double eps = 1e-6;
  17.  
  18.  
  19. struct matrix{
  20. int x = 0, y = 0;
  21. double det = 1;
  22. double a[101][101],b[101][101];
  23.  
  24. matrix(){};
  25. matrix(int x, int y) : x(x), y(y) {
  26.  
  27. for (int i = 0; i < y;i++)
  28. for (int j = 0; j < x; j++)
  29. scanf("%lf",&this->a[i][j]);
  30. };
  31.  
  32. matrix(double q[101][101], int x, int y) : x(x), y(y){
  33. for (int i = 0; i < y; i++)
  34. for (int j = 0; j < x; j++)
  35. this->a[i][j] = q[i][j];
  36. }
  37.  
  38. void print_matrix(){
  39. for (int i = 0; i < this->y; i++){
  40. for (int j = 0; j < this->x; j++)
  41. printf("%lf ", this->a[i][j]);
  42. printf("\n");
  43. }
  44. printf("\n");
  45. }
  46.  
  47. void transposition(){
  48. for (int i = 0; i < this->y;i++)
  49. for (int j = i; j < this->x ; j++)
  50. {
  51. double p = this->a[i][j];
  52. this->a[i][j] = this->a[j][i];
  53. this->a[j][i] = p;
  54. }
  55.  
  56. swap(this->x, this->y);
  57.  
  58. }
  59.  
  60. void calc_reverse(){
  61. this->det = 1;
  62. for (int i = 0; i < this->y; i++)
  63. for (int j = 0; j < this->x; j++)
  64. this->b[i][j] = this->a[i][j];
  65.  
  66. for (int i = 0; i < this->y; i++){
  67.  
  68. }
  69.  
  70. }
  71.  
  72.  
  73.  
  74. public:
  75.  
  76. matrix & operator = (matrix & A2){
  77. for (int i = 0; i < A2.y; i++)
  78. for (int j = 0; j < A2.x; j++){
  79. this->a[i][j] = A2.a[i][j];
  80. }
  81. return *this;
  82. }
  83.  
  84. matrix & operator += (matrix & A2){
  85. if (this->x != A2.x || this->y != A2.y)return *this;
  86. for (int i = 0; i < this->y; i++)
  87. for (int j = 0; j < this->x; j++){
  88. this->a[i][j] += A2.a[i][j];
  89. }
  90. return *this;
  91. }
  92.  
  93. matrix & operator *= (matrix & A2){
  94. if (this->x != A2.y) return *this;
  95. double buffer[101][101] = { { } };
  96.  
  97. for (int i = 0; i < this->y; i++)
  98. for (int j = 0; j < A2.x; j++)
  99. for (int q = 0; q < this->x; q++)
  100. buffer[i][j] += this->a[i][q] * A2.a[q][j];
  101.  
  102. for (int i = 0; i < this->y; i++)
  103. for (int j = 0; j < A2.x; j++) this->a[i][j] = buffer[i][j];
  104.  
  105. return *this;
  106. }
  107.  
  108. matrix & operator * (matrix & A2){
  109. if (this->x != A2.y) return *this;
  110. double buffer[101][101] = { {} };
  111.  
  112. for (int i = 0; i < this->y; i++)
  113. for (int j = 0; j < A2.x; j++)
  114. for (int q = 0; q < this->x; q++)
  115. buffer[i][j] += this->a[i][q] * A2.a[q][j];
  116.  
  117. return * new matrix(buffer,A2.x,this->y);
  118. }
  119.  
  120. matrix & operator + (matrix & A2){
  121. if (this->x != A2.x || this->y != A2.y)return *this;
  122.  
  123. double buffer[101][101] = { {} };
  124.  
  125. for (int i = 0; i < this->y; i++)
  126. for (int j = 0; j < this->x; j++){
  127. buffer[i][j] = this->a[i][j] + A2.a[i][j];
  128. }
  129.  
  130. return *new matrix(buffer, A2.x, this->y);
  131. }
  132.  
  133. };
  134.  
  135. matrix pow_matrix(int val, matrix a){
  136. matrix b = a;
  137. while (val){
  138.  
  139. if (val & 1){
  140. a *= b;
  141. val--;
  142. }
  143.  
  144. else{
  145. a *= a;
  146. val /= 2;
  147. }
  148. return a;
  149. }
  150. }
  151.  
  152.  
  153.  
  154. int main() {
  155. int n, m, k, l, r;
  156. scanf("%i %i",&n,&m);
  157. matrix A(n, m);
  158.  
  159.  
  160. Sleep(10000000);
  161. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement