Page3.xaml.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15. namespace WpfApp1
  16. {
  17. /// <summary>
  18. /// Логика взаимодействия для Page3.xaml
  19. /// </summary>
  20. public partial class Page3 : Page
  21. {
  22. public Page3()
  23. {
  24. InitializeComponent();
  25. }
  26. private void RunExperiments_Click(object sender, RoutedEventArgs e)
  27. {
  28. if (double.TryParse(ParamATextBox.Text, out double a) &&
  29. double.TryParse(ParamCTextBox.Text, out double c) &&
  30. double.TryParse(ParamBTextBox.Text, out double b) &&
  31. double.TryParse(ParamKTextBox.Text, out double k))
  32. {
  33. double maxK = FindMaxK(a, c);
  34. double maxA = FindMaxA(c, k);
  35. double maxKModified = FindMaxKModified(a, c, b);
  36. ResultsTextBox.Text = $"Эксперимент 1: Наибольшее значение коэффициента вылова k: {maxK}\n" +
  37. $"Эксперимент 2: Наибольшее значение параметра a: {maxA}\n" +
  38. $"Модификация 1: Наибольшее значение коэффициента вылова k \n" +
  39. $"В модифицированной модели: {maxKModified}";
  40. }
  41. else
  42. {
  43. MessageBox.Show("Пожалуйста, введите числовые значения для всех параметров.", "Ошибка ввода!", MessageBoxButton.OK, MessageBoxImage.Error);
  44. }
  45. }
  46. private double FindMaxK(double a, double c)
  47. {
  48. double k = 0;
  49. while (true)
  50. {
  51. double nextPopulation = c + a * c - k * c;
  52. if (nextPopulation <= 0)
  53. break;
  54. k++;
  55. }
  56. return k - 1;
  57. }
  58. private double FindMaxA(double c, double k)
  59. {
  60. double a = 0;
  61. while (true)
  62. {
  63. double nextPopulation = c + a * c - k * c;
  64. if (nextPopulation <= 0)
  65. break;
  66. a++;
  67. }
  68. return a - 1;
  69. }
  70. private double FindMaxKModified(double a, double c, double b)
  71. {
  72. double k = 0;
  73. while (true)
  74. {
  75. double nextPopulation = c + a * c - (k + b) * c;
  76. if (nextPopulation <= 0)
  77. break;
  78. k++;
  79. }
  80. return k - 1;
  81. }
  82. private void Button_Click_1(object sender, RoutedEventArgs e)
  83. {
  84. ParamATextBox.Text = string.Empty;
  85. ParamCTextBox.Text= string.Empty;
  86. ParamBTextBox.Text= string.Empty;
  87. ParamKTextBox.Text= string.Empty;
  88. ResultsTextBox.Text= string.Empty;
  89. }
  90. }
  91. }