Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace MetodyNumeryczne
  7. {
  8. public class MetodaGaussa
  9. {
  10. public static int Gauss(double [,] A,double [] B, double [] X, double eps )
  11. {
  12. //Wybór Elementu Głównego
  13. double T, ZS, MA;
  14. int k, i, j, N;
  15. N = A.GetLength(0) - 1;
  16. for (i = 1; i <= N; i++)
  17. {
  18. T = Math.Abs(A[i, i]);
  19. k = i;
  20. for (j = i + 1; j <= N; j++)
  21. {
  22. MA = Math.Abs(A[j, i]);
  23. if (MA > T)
  24. {
  25. T = MA;
  26. k = j;
  27. }
  28. }
  29. ZS = B[k];
  30. B[k] = B[i];
  31. B[i] = ZS;
  32. for (j = N; j >= 1; j--)
  33. {
  34. ZS = A[k, j];
  35. A[k, j] = A[i, j];
  36. A[i, j] = ZS;
  37. }
  38.  
  39. }
  40.  
  41. //Przekształcenie Macierzy
  42. double m;
  43. for (i = 1; i <= N; i++)
  44. {
  45. for (j = i + 1; j <= N; j++)
  46. {
  47. m = A[j, i] / A[i, i];
  48. B[j] -= B[i] * m;
  49. for (k = 1; k <= N; k++)
  50. A[j, k] -= A[i, k] * m;
  51. }
  52. }
  53. //Metoda Eliminacji Wstecznej
  54. double Z;
  55. for (i = N; i >= 1; i--)
  56. {
  57. Z = B[i];
  58. for (j = i + 1; j <= N; j++)
  59. Z -= A[i, j] * X[j];
  60. X[i] = Z / A[i, i];
  61.  
  62. }
  63.  
  64. for (j = 1; j <= B.GetLength(0) - 1; j++)
  65. {
  66.  
  67. }
  68.  
  69. return 0;
  70.  
  71. }
  72.  
  73. }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement