Добавил:
SSU_CSIT
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:методы вычислений Поплавский / main
.cpp#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main() {
setlocale(LC_ALL, "RUS");
int N, n;
cout << "Введите ваш номер варианта: ";
cin >> n;
system("cls");
cout << "Введите N: ";
cin >> N;
system("cls");
cout << "=== Введите значения X ===\n" << endl;
vector <float> x, y;
for (int i = 0; i < N; i++) {
cout << "Введите X [" << i << "]: ";
int m;
cin >> m;
x.push_back(m);
cout << endl;
}
for (int i = 0; i < N; i++) {
float m = (x[i] * x[i] * x[i]) / (n + 1);
y.push_back(m);
}
cout << "X: ";
for (int i = 0; i < N; i++)
cout << x[i] << " ";
cout << endl;
cout << "Y: ";
for (int i = 0; i < N; i++)
cout << y[i] << " ";
cout << "\n" << endl;
vector <vector <float>> XX;
for (int i = 0; i < N; i++) {
XX.push_back(vector<float>());
for (int j = 0; j < N - 1; j++) {
float m = (x[j] + x[j + 1]) / 2;
float M = m;
for (int k = 0; k < N ; k++) {
XX[i].push_back(M);
//cout << " " << M; //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
M *= m;
}
}
}
for (int t = 0; t < N - 1; t++) {
float res = 0;
int l = 0;
do {
float m = 1, k = 1;
for (int i = 0; i < N; i++) {
if (l != i) {
//cout << XX[0][t] << " И " << XX[1][t] << endl;
m *= XX[l][t] - x[i];
k *= x[l] - x[i];
//cout << "[" << l << "]\n" << m << "\n" << k << "\n" << endl;
}
}
res += (m / k) * y[l];
// cout << "RES =" << res << endl;
l++;
} while (l < N);
cout << "Результат [" << t << "]: " << res << endl;
}
//float l = ((XX[0][1] - x[1]) * (XX[0][1] - x[2]) * (XX[0][1] - x[3])) / ((x[0] - x[1]) * (x[0] - x[2]) * (x[0] - x[3]));
//float ll = ((XX[0][1] - x[0]) * (XX[0][1] - x[2]) * (XX[0][1] - x[3])) / ((x[1] - x[0]) * (x[1] - x[2]) * (x[1] - x[3]));
//float lll = ((XX[0][1] - x[0]) * (XX[0][1] - x[1]) * (XX[0][1] - x[3])) / ((x[2] - x[0]) * (x[2] - x[1]) * (x[2] - x[3]));
//cout << "L(1): " << l << "\n L(2): " << ll << "\n L (3): " << lll << endl;
system("pause");
return 0;
}
Соседние файлы в папке методы вычислений Поплавский