12 double cos_quad_alpha(
double **bk,
double **differenceTable,
int k,
int nNodes);
16 double cos_quad_alpha(
double **bk,
double **differenceTable,
int k,
int nNodes)
19 std::vector<double> bk_kthRow(n);
20 std::vector<double> dt_3rdColumn(n);
21 for (
int i = 0; i < n; i++)
23 bk_kthRow[i] = bk[k][i];
24 dt_3rdColumn[i] = differenceTable[i][3];
26 double nominator = inner_product(bk_kthRow.begin(), bk_kthRow.end(), dt_3rdColumn.begin(), 0.0);
28 return ( pow((nominator/denominator),2) );
34 int maxIteration = 100;
37 double** bkk =
new double*[n];
38 double** bk =
new double*[n];
39 double** differenceTable =
new double*[n];
41 for(
int i = 0; i < n; ++i)
43 bkk[i] =
new double[n];
44 bk[i] =
new double[n];
45 differenceTable[i] =
new double[n];
49 for (
int r = 0; r < n; r++)
51 for (
int c = 0; c < n; c++)
56 for (
int k = 0; k < n; k++)
58 for (
int i = 0; i < n; i++)
70 for (
int j=1; j <= 3; j++)
72 for (
int i = 0; i < (n-j); i++)
74 bkk[i][j]=bkk[i+1][j-1]-bkk[i][j-1];
78 for (
int i = 0; i < n; i+=1)
87 while (realizable == 1 && iteration < maxIteration)
94 if ( realizable == 1 )
100 for (
int k = 0; k < n; k++)
102 double cqa = cos_quad_alpha(bk, differenceTable, k, nNodes);
103 double cqa_star = cos_quad_alpha(bk, differenceTable, k_star, nNodes);
109 std::vector<double> bk_starRow(n);
110 std::vector<double> dt_3rdColumn(n);
111 for (
int i = 0; i < n; i++)
113 bk_starRow[i] = bk[k_star][i];
114 dt_3rdColumn[i] = differenceTable[i][3];
116 double lnck = -( inner_product(bk_starRow.begin(), bk_starRow.end(), dt_3rdColumn.begin(), 0.0) )/(
vectorNorm(bk_starRow) );
117 moments[k_star] = exp(lnck)*moments[k_star];
void buildDifferenceTable(double **differenceTable, double *mom, int nNodes)
constructs the difference table
void McGrawCorrection(double *moments, int nNodes)
McGraw correction algorithm.
double vectorNorm(vector< double > const &v)
normalized vector used in McGraw correction algorithm
int isRealizable(double **differenceTable, int nNodes)
checks if the moments are realizable