Form1(ПР7).cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System;
  2. using System.Windows.Forms;
  3. using System.Windows.Forms.DataVisualization.Charting;
  4. namespace Ul_4
  5. {
  6. public partial class Form1 : Form
  7. {
  8. public Form1()
  9. {
  10. InitializeComponent();
  11. }
  12. private void Form1_Load(object sender, EventArgs e)
  13. {
  14. }
  15. private double CalculateFunction(double x, double b)
  16. {
  17. double result = Math.Pow(10, -3) * Math.Pow(Math.Abs(x), 5.0 / 2.0) + Math.Log(Math.Abs(x + b));
  18. return result;
  19. }
  20. private void buttonCalculate_Click(object sender, EventArgs e)
  21. {
  22. double x0 = 1.75;
  23. double xk = -2.5;
  24. double dx = -0.25;
  25. double b = 35.4;
  26. int arrayLength = Convert.ToInt32(Math.Abs((xk - x0) / dx)) + 1;
  27. double[] results = new double[arrayLength];
  28. double[] xValues = new double[arrayLength];
  29. int index = 0;
  30. for (double x = x0; x >= xk; x += dx)
  31. {
  32. double result = CalculateFunction(x, b);
  33. results[index] = result;
  34. xValues[index] = x;
  35. index++;
  36. }
  37. // Очистка предыдущих данных графика
  38. chart1.Series.Clear();
  39. // Создание нового графика
  40. Series series = new Series("Функция");
  41. series.ChartType = SeriesChartType.Line;
  42. // Добавление точек на график
  43. for (int i = 0; i < arrayLength; i++)
  44. {
  45. series.Points.AddXY(xValues[i], results[i]);
  46. }
  47. // Добавление графика на элемент управления Chart
  48. chart1.Series.Add(series);
  49. }
  50. }
  51. }