This function uses the iterative conjugate gradient method [1] to find a solution to the function:
where
is a symmetric, positive definite matrix and
and
are vectors.
conjugate_gradient( table_name,
name_of_row_values_col,
name_of_row_number_col,
aray_of_b_values,
desired_precision
)
Matrix
is assumed to be stored in a table where each row consists of at least two columns: array containing values of a given row, row number:
{TABLE|VIEW} matrix_A (
row_number FLOAT,
row_values FLOAT[],
)The number of elements in each row should be the same.
is passed as a FLOAT[] to the function.
SELECT * FROM data;Result:
row_num | row_val
--------+---------
1 | {2,1}
2 | {1,4}
(2 rows)
SELECT conjugate_gradient( 'data',
'row_val',
'row_num',
'{2,1}',
1E-6,1
);
INFO: COMPUTE RESIDUAL ERROR 14.5655661859659
INFO: ERROR 0.144934004246004
INFO: ERROR 3.12963615962926e-31
INFO: TEST FINAL ERROR 2.90029642185163e-29
conjugate_gradient
--------------------------
{1,-1.31838984174237e-15}
(1 row)