Palson

ukł liniowe

Mar 19th, 2019
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.01 KB | None | 0 0
  1. namespace Uklady_liniowe_Re
  2. {
  3. public partial class Form1 : Form
  4. {
  5.  
  6. int N;
  7. double[,] A;
  8. double[] B, X;
  9. string TypMacierzy;
  10.  
  11.  
  12.  
  13. public Form1()
  14. {
  15.  
  16.  
  17. InitializeComponent();
  18. }
  19.  
  20. private void Form1_Load(object sender, EventArgs e)
  21. {
  22. numericUpDown1_ValueChanged(sender, e);
  23. }
  24.  
  25. private void button1_Click(object sender, EventArgs e)
  26. {
  27.  
  28. double Ax, suma = 0;
  29. Random R = new Random();
  30. TypMacierzy = "rzeczywista";
  31. A = new Double[N + 1, N + 1];
  32. B = new Double[N + 1];
  33. X = new Double[N + 1];
  34.  
  35. for(int i=1; i<=N; i ++)
  36. {
  37. suma = 0;
  38. for(int j=1; j<=N; j++){
  39. Ax = R.Next(1,10);
  40. if(i!=j)
  41. {
  42. MacierzA[j-1, i-1].Value = Ax.ToString();
  43. A[i,j] = Ax;
  44. suma += Ax;
  45. }
  46. else
  47.  
  48. {
  49. MacierzA[j-1, i-1].Value = (10.0 * Ax).ToString();
  50. A[i,j] = 10.0 * Ax;
  51. suma += 10.0 * Ax;
  52.  
  53. }
  54. }
  55. B[i]=suma;
  56. WektorB[0, i -1].Value = suma.ToString();
  57. }
  58. button2.Enabled = true;
  59. }
  60.  
  61. private void numericUpDown1_ValueChanged(object sender, EventArgs e)
  62. {
  63. N = (int)numericUpDown1.Value;
  64. ustawTablice();
  65. }
  66.  
  67. private void ustawTablice()
  68. {
  69. MacierzA.ColumnCount = N;
  70. MacierzA.RowCount = N;
  71. WektorX.RowCount = N;
  72. WektorB.RowCount = N;
  73.  
  74. for (int i = 0; i < N; i++)
  75. {
  76. MacierzA.Columns[i].HeaderText = (i + 1).ToString();
  77. MacierzA.Rows[i].HeaderCell.Value = (i + 1).ToString();
  78. MacierzA.Columns[i].Width = 35;
  79. }
  80. }
  81.  
  82. private void MacierzA_Scroll(object sender, ScrollEventArgs e)
  83. {
  84. WektorX.FirstDisplayedScrollingRowIndex = WektorB.FirstDisplayedScrollingRowIndex
  85. = MacierzA.FirstDisplayedScrollingRowIndex;
  86. }
  87.  
  88. private void button2_Click(object sender, EventArgs e)
  89. {
  90. int blad = 0;
  91. if (TypMacierzy == "rzeczywista")
  92. {
  93. if (radioButton1.Checked) blad = Class1.RozRowMacGaussa(A, B, X, 1e-30);
  94. //jakas insturkteutac glupia byla
  95. if (blad == 0)
  96. for (int i = 1; i <= N; i++)
  97. WektorX[0, i - 1].Value = X[i].ToString("0.000000");
  98. }
  99. // else{
  100. // if(radioButton1.Checked) blad = Class1.RozRowMacGaussa(A, B, X, 1e-30);
  101. //znowu ta instrukacj
  102. // if(blad==0)
  103.  
  104. }
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111. }
  112.  
  113.  
  114.  
  115.  
  116. }
Add Comment
Please, Sign In to add comment