void Aitken std vector double std vector double std vector double sX s

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
void Aitken(std::vector<double> x, std::vector<double> y, std::vector<double> sX, std::vector<double> &res)
{
int n = x.size();
for (int j = 0; j < sX.size(); ++j)
{
std::vector<std::vector<double> >tempY(n, std::vector<double>(y.size(), 0));
tempY[0] = y;
for (int i = 0; i < n - 1; ++i)
{
for (int k = i +1; k < n; ++k)
{
tempY[i+1][k] = ((sX[j] - x[i])*tempY[i][k] - (sX[j]- x[k])*tempY[i][i]) / (x[k] - x[i]);
}
}
res.push_back(tempY[n - 1][n-1]);
}
}