Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.71 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. // Mrowiec Marek
  7. // INT1
  8. // VS2015
  9.  
  10. namespace D_18_INT1_052944_MM
  11. {
  12. class Program
  13. {
  14. static void Jordanek(int n, double[,] A)
  15. {
  16. int r;
  17. int pupa = n + 1;
  18. double max, p;
  19.  
  20. for (int k = 0; k < n; k++)
  21. {
  22. max = A[k, k];
  23. r = k;
  24.  
  25. for (int i = k; i < n; i++)
  26. {
  27. if (Math.Abs(A[i, k]) > Math.Abs(max))
  28. {
  29. max = A[i, k];
  30. r = i;
  31. }
  32. }
  33.  
  34. if (max == 0)
  35. {
  36. Console.WriteLine("Macierz układu osobliwa...");
  37. return;
  38. }
  39. else
  40. {
  41. for (int j = k; j < pupa; j++)
  42. {
  43. double pomoc = A[k, j];
  44. A[k, j] = A[r, j];
  45. A[r, j] = pomoc;
  46. }
  47.  
  48. for (int j = k; j < pupa; j++)
  49. {
  50. A[k, j] = A[k, j] / max;
  51. }
  52.  
  53. for (int i = 0; i < n; i++)
  54. {
  55. if (i != k)
  56. {
  57. p = A[i, k];
  58.  
  59. for (int j = k; j < pupa; j++)
  60. {
  61. A[i, j] = A[i, j] - p * A[k, j];
  62. }
  63. }
  64. }
  65. }
  66.  
  67. }
  68. }
  69. static double Sumowanie(double[,] t, int n, double x)
  70. {
  71. double suma = 0;
  72. for (int i = 0; i < n; i++)
  73. {
  74. suma += t[i,n] * Math.Pow(x, i);
  75. }
  76. return suma;
  77. }
  78.  
  79. static double Sumowanko(int n, double x, double[] An)
  80. {
  81. double p = An[n-1];
  82. for (int i = n-2; i >= 0; i--)
  83. {
  84. p = p * x + An[i];
  85. }
  86. return p;
  87. }
  88. static void Main(string[] args)
  89. {
  90. int n = 5; // stopień wielomianu int.
  91. double[] Xi = { 1.5, 2, 2.5, 3.5, 3.8, 4.1 }; // n+1
  92. double[] Yi = { 2, 5, -1, 0.5, 3, 7 }; // n+1
  93. double[,] tab = new double[n + 1, n + 2];
  94.  
  95. for (int i = 0; i < n+1; i++)
  96. {
  97. tab[i, 0] = 1;
  98. tab[i, n + 1] = Yi[i];
  99. }
  100.  
  101. for (int i = 0; i < n+1; i++)
  102. {
  103. for (int j = 1; j < n+1; j++)
  104. {
  105. tab[i,j] = Xi[i] * tab[i,j - 1];
  106. }
  107. }
  108.  
  109. //foreach (var x in tab)
  110. //{
  111. // Console.WriteLine(x);
  112. //}
  113.  
  114. Jordanek(n + 1, tab);
  115.  
  116. //foreach (var x in tab)
  117. //{
  118. // Console.WriteLine(x);
  119. //}
  120. double x = 1;
  121.  
  122. double[] An = new double[n + 1];
  123.  
  124. for (int i = 0; i < An.Length; i++)
  125. {
  126. An[i] = tab[i, n + 1];
  127. }
  128.  
  129.  
  130. string pomocy;
  131. do
  132. {
  133. Console.WriteLine("Wpisz wartość od 1.5 do 4.1 ( 0 = wyjście z pętli)");
  134. pomocy = Console.ReadLine();
  135. x = Convert.ToDouble(pomocy);
  136. Console.WriteLine("Wartość: " + Sumowanko(n+1,x,An));
  137.  
  138. } while (x != 0);
  139.  
  140. }
  141. }
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement