
чм3
.pdfConsole.WriteLine($"x = {x}; y = {y}");
}
else if (x >= 2.8)
{
double y = (((x - X[13]) * (x - X[14])) / ((X[12] - X[13]) * (X[12] - X[14]))) * Y[12] +
(((x - X[12]) * (x - X[14])) / ((X[13] - X[12]) * (X[13] -
X[14]))) * Y[13] +
(((x - X[12]) * (x - X[13])) / ((X[14] - X[12]) * (X[14] -
X[13]))) * Y[14];
Console.WriteLine($"x = {x}; y = {y}");
}
else
{
for (int i = 1; i < 14; i++)
{
if (X[i - 1] < x && X[i + 1] > x)
{
double y = (((x - X[i]) * (x - X[i + 1])) / ((X[i - 1] - X[i]) * (X[i - 1] - X[i + 1]))) * Y[i - 1] +
(((x - X[i - 1]) * (x - X[i + 1])) / ((X[i] - X[i - 1]) *
(X[i] - X[i + 1]))) * Y[i] +
(((x - X[i - 1]) * (x - X[i])) / ((X[i + 1] - X[i - 1]) *
(X[i + 1] - X[i]))) * Y[i + 1];
Console.WriteLine($"x = {x}; y = {y}"); return;
}
}
}
}
Lagrange(0.0);
Lagrange(0.2);
Lagrange(0.4);
Lagrange(0.6);
Lagrange(0.8);
Lagrange(1.0);
Lagrange(1.2);
Lagrange(1.4);
Lagrange(1.6);
Lagrange(1.8);
Lagrange(2.0);
Lagrange(2.2);
Lagrange(2.4);
Lagrange(2.6);
Lagrange(2.8);
Console.WriteLine("------------------------");
Lagrange(1.1);
Console.WriteLine("------------------------");
Lagrange(3.0);
Lagrange(4.5);
Приложение Б
double[] X = { 0.0, 0.2, 0.4, 0.6, 0.8, 1.0, 1.2, 1.4, 1.6, 1.8, 2.0, 2.2, 2.4, 2.6, 2.8};
//y1
//double[] Y = { 1.172229425, 4.551715624, 7.466763616, 6.871556362, 4.374340838, 9.470381565, 10.72324083, 10.73028883, 10.19491856, 16.12438536, 23.9858893, 18.74725305, 22.75740465, 28.37326328, 35.7321433};
//y2
//double[] Y = { -2.302585093, 0.783901544, 1.453953010, 1.851599470, 2.135349174, 2.356125860, 2.536866389, 2.689886230, 2.822568655, 2.939690883, 3.044522438, 3.139399623, 3.226050029, 3.305787197, 3.379633204};
//y3
double[] Y = { 0.010796117, -0.982827061, -0.352638252, 0.860174137, 0.651819843, -0.633461325, -0.872147284, 0.330115293, 0.986966382, 0.013166561, -0.982386853, -0.354855585, 0.858962707, 0.653615822, - 0.631625227 };
double total_x1 = 0;
double total_x2 = 0;
double total_x3 = 0;
double total_x4 = 0;
double total_y1 = 0;
double total_yx1 = 0;
double total_yx2 = 0;
double a_start = 1; double b_start = 1; double c_start = 1;
double n = 15;
double tolerance = 0.00001; void SumsMLS()
{
for (int i = 0; i < 15; i++)
{
total_x1 += X[i];
total_x2 += Math.Pow(X[i], 2); total_x3 += Math.Pow(X[i], 3); total_x4 += Math.Pow(X[i], 4); total_y1 += Y[i];
total_yx1 += Y[i] * X[i];
total_yx2 += Y[i] * Math.Pow(X[i], 2);
}
}
void LSM(double x)
{
double a = 0; double b = 0; double c = 0; do
{
a_start = a;
a = (-(b_start * total_x3) - (c_start * total_x2) + total_yx2) /
(total_x4);
b_start = b;
b= (-(a * total_x3) - (c_start * total_x1) + total_yx1) / (total_x2); c_start = c;
c= (-(a * total_x2) - (b * total_x1) + total_y1) / n;
}
while ((Math.Abs(a - a_start) >= tolerance) || (Math.Abs(b - b_start) >= tolerance) ||
(Math.Abs(c - c_start) >= tolerance));
{
double y = (a * x * x) + (b * x) + c; Console.WriteLine($"При x = {x}: y = {y}");
}
}
SumsMLS();
LSM(0.0);
LSM(0.2);
LSM(0.4);
LSM(0.6);
LSM(0.8);
LSM(1.0);
LSM(1.2); |
|
LSM(1.4); |
|
LSM(1.6); |
|
LSM(1.8); |
|
LSM(2.0); |
|
LSM(2.2); |
|
LSM(2.4); |
|
LSM(2.6); |
|
LSM(2.8); |
|
Console.WriteLine(" |
------------------------"); |
LSM(1.1); |
|
Console.WriteLine("------------------------ |
"); |
LSM(3.0); |
|
LSM(4.5); |
|