Form1_Lab4.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Xml.Resolvers;
  11. using static System.Windows.Forms.VisualStyles.VisualStyleElement;
  12. namespace Ul_4
  13. {
  14. public partial class Form1 : Form
  15. {
  16. public Form1()
  17. {
  18. InitializeComponent();
  19. }
  20. private void Form1_Load(object sender, EventArgs e)
  21. {
  22. }
  23. private double CalculateFunction(double x, double b)
  24. {
  25. double result = Math.Pow(10, -3) * Math.Pow(Math.Abs(x), 5.0 / 2.0) + Math.Log(Math.Abs(x + b));
  26. return result;
  27. }
  28. private void button1_Click(object sender, EventArgs e)
  29. {
  30. double x0 = 1.75;
  31. double xk = -2.5;
  32. double dx = -0.25;
  33. double b = 35.4;
  34. int arrayLength = Convert.ToInt32(Math.Abs((xk - x0) / dx)) + 1;
  35. double[] results = new double[arrayLength];
  36. int index = 0;
  37. for (double x = x0; x >= xk; x += dx)
  38. {
  39. double result = CalculateFunction(x, b);
  40. results[index++] = result;
  41. }
  42. // вывод результатов на форму
  43. for (int i = 0; i < arrayLength; i++)
  44. {
  45. listBox1.Items.Add($"y = {x0 - i * dx:F2} - f(x) = {results[i]:F4}");
  46. }
  47. }
  48. }
  49. }