using System using System Collections Generic using System ComponentMo

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Метод_половинного_деления
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
double f(double x) {
return 3.0 * x * x * x + 2.0 * x * x + x - 5;
}
private void Form1_Load(object sender, EventArgs e)
{
double l = 0.0, r = 5.0, m, x = 0.0;
while (r - l > 1e-8)
{
m = (l + r) / 2.0;
if (f(m) < 0.0)
{
l = m;
}
else
{
r = m;
}
chart1.Series[0].Points.AddXY(x, m);
x += 1.0;
}
}
}
}