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
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Задание_6
{
class Program
{
public static int n;
public static double[] roots = new double[1000];
public static int rootSZ;
public static int alpha;
public static double Ln(double x, int n, int alpha)
{
int i;
double a, b, c;
double[] l = new double[1000];
l[0] = 1;
l[1] = 1 + alpha - x;
for (i = 2; i < n; i++)
{
a = i - 1;
b = i + alpha;
c = 2 * (i - 1) + alpha - x + 1;
l[i] = (c * l[i - 1] - b * l[i - 2]) / a;
}
return l[n];
}
public static double G(int n)
{
int i;
double fact;
fact = 1;
for (i = 2; i < n; i++)
{
fact = fact * i;
}
return fact;
}
public static double Lnp(double x, int n)
{
double[] l = new double[1000];
int i;
return -Ln(x, n - 1, alpha + 1);
}
public static double Pn(double x, int n)
{
double[] p = new double[1000];
p[0] = 1;
p[1] = x;
int i;
for (i = 2; i < n; i++)
{
p[i]=((2 * i - 1) / i) * x * p[i - 1] - ((i - 1) / i) * p[i - 2];
}
return p[n];
}
public static double Xn(double x, int n)
{
double[] h = new double[1000];
h[0] = 1;
h[1] = 2 * x;
int i;
for (i = 2; i < n; i++)
{
h[i]= 2 * x * h[i - 1] - 2 * (i - 1) * h[i - 2];
}
return h[n];
}
public static double Xnp(double x, int n)
{
return 2 * n * Hn(x, n - 1);
}
public static double Pnp(double x)
{
return (n / (1 - x * x)) * (Pn(x, n - 1) - x * Pn(x, n));
}
public static double BinarySearch(double l, double r, int numb)
{
int i;
double m, cm, cr, cl;
for (i = 1; i < 200; i++)
{
m= (l + r) / 2;
if (numb == 1)
{
cm = Pn(m, n);
cr = Pn(r, n);
cl = Pn(l, n);
}
if (numb == 4)
{
cm = Hn(m, n);
cr = Hn(r, n);
cl = Hn(l, n);
}
if (numb == 5)
{
cm = Ln(m, n, alpha);
cr = Ln(r, n, alpha);
cl = Ln(l, n, alpha);
}
if (cr > cl)
if (cm <= 0)
l = m;
else
r = m;
else
if (cm < 0)
r = m;
else
l = m;
}
return l;
}
static void FindRoots(int a, int b, int numb)
{
int i,m;
double h, l, r, root, cr, cl;
rootSZ=0;
m= 10000;
h= (b - a) / m;
for (i = 1; i < m; i++)
{
l= a + i * h;
r= l + h;
if (numb == 1)
{
cr=Pn(r, n);
cl=Pn(l, n);
}
if (numb == 4)
{
cr=Hn(r, n);
cl=Hn(l, n);
}
if (numb == 5)
{
cr=Ln(r, n, alpha);
cl=Ln(l, n, alpha);
}
if (cr * cl < 0)
{
root= BinarySearch(l, r, numb);
rootSZ= rootSZ + 1;
roots[rootSZ]= root;
}
}
}
}
static void Main(string[] args)
{
}
}
}