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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace test
{
class Program
{
static double func(double x)
{
return x * x * x * x + 7 * x * x * x - 51 * x * x - 207 * x + 812.5;
}
static double pr(double x)
{
return 4 * x * x * x + 21 * x * x - 102 * x - 207;
}
static double second_pr(double x)
{
return 12 * x * x + 42 * x - 102;
}
static double newton(double x, double eps)
{
bool ex = true;
do
{
double x1 = x - func(x) / pr(x);
if (Math.Abs(x - x1) < eps)
ex = false;
x = x1;
} while (ex);
return x;
}
static void Main(string[] args)
{
double[] x = new double[4];
double a = -10;
double b = 10;
double s = 0;
double dx = 1.5;
double eps = 0.0001;
do
{
double x1 = a;
int i = 0;
s = 0;
do
{
if (func(x1) * func(x1 + dx) < 0)
{
if (func(x1) * second_pr(x1) > 0)
{
x[i] = x1;
i++;
s++;
}
else
{
x[i] = x1 + dx;
i++;
s++;
}
}
x1 = x1 + dx;
} while (x1 < b);
dx = dx / 2;
} while (s < 4);
for (int i = 0; i < x.Length; i++)
x[i] = newton(x[i], eps);
for (int i = 0; i < x.Length; i++)
Console.WriteLine("Корень {0:d} = {1:f3}", i, x[i]);
Console.ReadKey();
}
}
}