Advertisement
maxrusmos

Untitled

Apr 11th, 2020
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.15 KB | None | 0 0
  1. using System;
  2. using MatrixOp;
  3. using CExeption;
  4. using PolynomOp;
  5.  
  6. namespace lab10 {
  7. class Program {
  8. static void Main(string[] args) {
  9. Console.ForegroundColor = ConsoleColor.Red;
  10. Console.WriteLine($"МАТРИЦЫ {Environment.NewLine}");
  11. Console.ForegroundColor = ConsoleColor.Magenta;
  12. Console.WriteLine("Матрица A:");
  13. Matrix A = new Matrix(3);
  14. Console.WriteLine(A.ToString());
  15. Console.WriteLine("Транспонированая матрица:");
  16. Console.WriteLine(Matrix.TranspositionMatrix(A).ToString());
  17. Console.WriteLine("A * 34:" + Environment.NewLine + (A * 34).ToString() + Environment.NewLine);
  18. Console.WriteLine("A ^ 4:" + Environment.NewLine + Matrix.MatrixPow(A, 4).ToString());
  19. Console.WriteLine($"Определитель матрицы A = {Matrix.DeterminantMatrix(A)} {Environment.NewLine}");
  20. Console.WriteLine("Обратная матрица:");
  21. try {
  22. Console.WriteLine(Matrix.ReverseMatrix(A));
  23. } catch (CustomException ex) {
  24. Console.ForegroundColor = ConsoleColor.Red;
  25. Console.WriteLine(ex.Message);
  26. }
  27.  
  28. Console.ForegroundColor = ConsoleColor.Red;
  29. Console.WriteLine("-----------------------------------" + Environment.NewLine);
  30.  
  31. Console.ForegroundColor = ConsoleColor.Cyan;
  32. Console.WriteLine("Матрица B:");
  33. Matrix B = new Matrix(2);
  34. Console.WriteLine(B.ToString());
  35. Console.WriteLine("Транспонированая матрица:");
  36. Console.WriteLine(Matrix.TranspositionMatrix(B).ToString());
  37. Console.WriteLine("B * 11:" + Environment.NewLine + (B * 11).ToString() + Environment.NewLine);
  38. Console.WriteLine("B ^ 2:" + Environment.NewLine + Matrix.MatrixPow(B, 2).ToString());
  39. Console.WriteLine($"Определитель матрицы B = {Matrix.DeterminantMatrix(B)} {Environment.NewLine}");
  40. Console.WriteLine("Обратная матрица:");
  41. try {
  42. Console.WriteLine(Matrix.ReverseMatrix(B));
  43. } catch (CustomException ex) {
  44. Console.ForegroundColor = ConsoleColor.Red;
  45. Console.WriteLine(ex.Message);
  46. }
  47.  
  48. Console.ForegroundColor = ConsoleColor.Red;
  49. Console.WriteLine("-----------------------------------" + Environment.NewLine);
  50.  
  51. Console.ForegroundColor = ConsoleColor.Yellow;
  52. Console.WriteLine($"Операции с матрицами A и B: {Environment.NewLine}");
  53. try {
  54. Console.WriteLine($"A + B: {Environment.NewLine}{(A + B).ToString()}");
  55. Console.WriteLine($"A * B: {Environment.NewLine}{(A * B).ToString()}");
  56. } catch (CustomException ex) {
  57. Console.WriteLine(ex.Message);
  58. }
  59. try {
  60. Console.WriteLine($"A / B: {Environment.NewLine}{(A / B).ToString()}");
  61. }
  62. catch (CustomException ex) {
  63. Console.ForegroundColor = ConsoleColor.Red;
  64. Console.WriteLine(ex.Message);
  65. }
  66.  
  67. Console.ForegroundColor = ConsoleColor.Red;
  68. Console.WriteLine("-----------------------------------" + Environment.NewLine);
  69.  
  70. Console.WriteLine($"ПОЛИНОМЫ С ОБЫЧНЫМИ КОЭФФИЦИЕНТАМИ {Environment.NewLine}");
  71. Console.ForegroundColor = ConsoleColor.Magenta;
  72.  
  73. var matrixArr1 = new Matrix[2]{ A, B };
  74. var matrixArr2 = new Matrix[2] { B, B };
  75.  
  76. var aPolynom = new Polynom<int>(2, 1, 5, 3);
  77. Console.WriteLine($"Полином Ap = {aPolynom.ToString()}");
  78. Console.WriteLine($"Ap * 2 = {(aPolynom * 2).ToString()}");
  79. Console.WriteLine($"Значение полинома в точке 4 = {aPolynom.PolynomInDot(4).ToString()}");
  80. Console.WriteLine($"Ap^4 = {Polynom<int>.PolynomPow(aPolynom, 4).ToString()}{Environment.NewLine}");
  81.  
  82. Console.ForegroundColor = ConsoleColor.Red;
  83. Console.WriteLine("-----------------------------------" + Environment.NewLine);
  84.  
  85. Console.ForegroundColor = ConsoleColor.Cyan;
  86. var bPolynom = new Polynom<int>(1, 1, 3);
  87. Console.WriteLine($"Полином Bp = {bPolynom.ToString()}");
  88. Console.WriteLine($"Bp * 3 = {(bPolynom * 3).ToString()}");
  89. Console.WriteLine($"Значение полинома в точке 2 = {(bPolynom.PolynomInDot(2)).ToString()}");
  90. Console.WriteLine($"Bp^2 = {Polynom<int>.PolynomPow(bPolynom, 2).ToString()}{Environment.NewLine}");
  91.  
  92. Console.ForegroundColor = ConsoleColor.Red;
  93. Console.WriteLine("-----------------------------------" + Environment.NewLine);
  94.  
  95. Console.ForegroundColor = ConsoleColor.Yellow;
  96. Console.WriteLine("Операции с полиномами Ap и Bp:");
  97. Console.WriteLine($"Ap + Bp = {(aPolynom + bPolynom).ToString()}");
  98. Console.WriteLine($"Ap - Bp = {(aPolynom - bPolynom).ToString()}");
  99. Console.WriteLine($"Ap * Bp = {(aPolynom * bPolynom).ToString()}");
  100. Console.WriteLine($"Композиция полиномов: {Polynom<int>.CompositionPolynimWithPolynom(aPolynom, bPolynom).ToString()}{Environment.NewLine}");
  101.  
  102. Console.ForegroundColor = ConsoleColor.Red;
  103. Console.WriteLine("-----------------------------------" + Environment.NewLine);
  104.  
  105. Console.WriteLine($"ПОЛИНОМЫ С МАТРИЧНЫМИ КОЭФФИЦИЕНТАМИ {Environment.NewLine}");
  106. Console.ForegroundColor = ConsoleColor.Magenta;
  107.  
  108. var cPolynom = new Polynom<Matrix>(2, A, B, B);
  109. Console.WriteLine($"Полином Сp:{Environment.NewLine}{cPolynom.ToString()}");
  110. try {
  111. Console.WriteLine($"Cp^4:{Environment.NewLine}{Polynom<Matrix>.PolynomPow(cPolynom, 4).ToString()}{Environment.NewLine}");
  112. } catch (CustomException ex) {
  113. Console.WriteLine(ex.Message);
  114. }
  115.  
  116. Console.ForegroundColor = ConsoleColor.Cyan;
  117. var dPolynom = new Polynom<Matrix>(1, B, A);
  118. Console.WriteLine($"Полином Dp:{Environment.NewLine}{dPolynom.ToString()}");
  119.  
  120. try {
  121. Console.WriteLine($"Dp^2:{Environment.NewLine}{Polynom<Matrix>.PolynomPow(dPolynom, 2).ToString()}{Environment.NewLine}");
  122. } catch (CustomException ex) {
  123. Console.WriteLine(ex.Message);
  124. }
  125.  
  126.  
  127. Console.ForegroundColor = ConsoleColor.Red;
  128. Console.WriteLine("-----------------------------------" + Environment.NewLine);
  129.  
  130. Console.ForegroundColor = ConsoleColor.Yellow;
  131. Console.WriteLine("Операции с полиномами Cp и Dp:");
  132. try {
  133. Console.WriteLine($"Cp + Dp:{Environment.NewLine}{(cPolynom + dPolynom).ToString()}");
  134. Console.WriteLine($"Cp - Dp:{Environment.NewLine}{(cPolynom - dPolynom).ToString()}");
  135. Console.WriteLine($"Cp * Dp:{Environment.NewLine}{(cPolynom * dPolynom).ToString()}");
  136. } catch(CustomException ex) {
  137. Console.WriteLine(ex.Message);
  138. }
  139.  
  140. //Console.WriteLine($"Композиция полиномов: {Polynom<Matrix>.CompositionPolynimWithPolynom(cPolynom, dPolynom).ToString()}{Environment.NewLine}");
  141. //Console.WriteLine(Polynom<int>.CompositionPolynimWithPolynom(bPolynom, aPolynom).ToString());
  142. //Console.WriteLine(Polynom<int>.PolynomComposition(dPolynom, cPolynom).ToString());
  143. }
  144. }
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement