using System using System Collections Generic using System Linq using

 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
44
45
46
47
48
49
50
51
52
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
delegate double fx(double i);
static double f(double x)
{
return x * x * x * x * x - 3 * x * x * x * x - 62 * x * x * x + 96 * x * x + 736 * x - 767.5;
}
static void PolDel(fx f, double a, double b, out double c)
{
double c1;
do
{
c1 = (a + b) / 2;
if (f(a) * f(c1) < 0)
b = c1;
else
a = c1;
} while (b - a > 0.0001);
c = c1;
}
static void Main(string[] args)
{
double a1 = -10, b1 = 10, x1;
double[] x = new double[5];
int n = 10, k = 0;
double c0 = (Math.Abs(a1) + Math.Abs(b1)) / n, c2;
for (int i = 0; i < n; i++)
{
c2 = a1 + c0;
if (f(a1) * f(c2) < 0)
{
PolDel(f, a1, c2, out x1);
x[k] = x1;
k++;
}
a1 = c2;
}
for (int i = 0; i < 5; i++)
{
Console.WriteLine("x({0}) = {1:f4}\tТочность до {2:f4}", i, x[i], Math.Abs(f(x[i])));
}
Console.ReadKey();
}
}
}