Текст программы

#include "stdafx.h"

#include <cstdio>

#include <cstring>

#include <cstdlib>

#include <cmath>

#include <iostream>

#include <iomanip>

using namespace std;

const short N = 6;

double Lagrang(double X[N], double Fx[N], double _x)

{

double Wx = 1.0;

for (short i = 0; i < N; ++i)

Wx *= (_x - X[i]);

double result = 0.0;

for (short i = 0; i < N; ++i)

{

double dWx = 1.0;

for(short j = 0; j < N; ++j)

if (i!= j) dWx *= X[i] - X[j];

result += (Wx * Fx[i])/((_x - X[i]) * dWx);

}

return result;

}

int main(int argc, char** argv)

{

double X[6] = {0.43, 0.48, 0.55, 0.62, 0.70, 0.75};

double Fx[6] = {1.63597, 1.73234, 1.87686, 2.03345, 2.22846, 2.35973};

cout << "Lagrang\t" << fixed << setw(20) << setprecision(15) << Lagrang(X, Fx, 0.702) << endl;

system("pause");

return 0;

}


Вывод программы

Lagrang 2.233567572885693


Понравилась статья? Добавь ее в закладку (CTRL+D) и не забудь поделиться с друзьями:  



double arrow
Сейчас читают про: