13 QVector< double* > vecA;
14 QVector< double > datA;
15 QVector< double > datb( order );
17 double** A =
construct( vecA, datA, order, order );
18 double* b = datb.data();
41 A[ 0 ][ 0 ] = (double) N;
43 for (
int i = 1; i < order; i++ )
45 for (
int j = 0; j <= i; j++ )
49 for (
int k = 0; k < N; k++ )
50 A[ i ][ j ] += pow( x[ k ], i ) * pow( x[ k ], j );
59 for (
int i = 0; i < order; i++ )
63 for (
int k = 0; k < N; k++ )
64 b[ i ] += y[ k ] * pow( x[ k ], i );
76 for (
int i = 0; i < order; i++ ) c[ i ] = b[ i ];
100 for (
int i = 0; i < n; i++ )
104 for (
int j = 0; j < i; j++ )
106 sum +=
sq( a[ i ][ j ] );
109 diff = a[ i ][ i ] - sum;
113 qDebug() <<
"Cholesky_Decomposition not positive definite.";
117 a[ i ][ i ] = sqrt( diff );
119 for (
int k = i + 1; k < n; k++ )
123 for (
int j = 0; j < i; j++ )
124 sum += a[ k ][ j ] * a[ i ][ j ];
126 a[ k ][ i ] = ( a[ k ][ i ] - sum ) / a[ i ][ i ];
131 for (
int i = 0; i < n - 1; i++ )
133 for (
int j = i + 1; j < n; j++ )
149 for (
int i = 0; i < n; i++ )
152 for ( j = 0; j < i; j++ )
154 b[ i ] -= L[ i ][ j ] * b[ j ];
157 b[ i ] /= L[ i ][ i ];
161 for (
int i = n - 1; i >= 0; i-- )
163 for (
int j = n - 1; j > i; j-- )
165 b[ i ] -= L[ j ][ i ] * b[ j ];
180 QVector< double > workvec( nn );
181 double* work = workvec.data();
188 for (
int jj = 0; jj < nn; jj++ )
191 workvec.fill( 0.0, nn );
193 work = workvec.data();
199 for (
int ii = 0; ii < nn; ii++ )
200 AI[ ii ][ jj ] = work[ ii ];
211 QVector< double >& QVd,
int rows,
int columns )
214 QVd.fill( 0., rows * columns );
215 double* vd = QVd.data();
217 for (
int ii = 0; ii < rows; ii++ )
232 QVector< double > ATvec( rows );
233 double* ATrow = ATvec.data();
235 for (
int ii = 0; ii < columns; ii++ )
241 for (
int kk = 0; kk < rows; kk++ )
243 double aval = AA[ kk ][ ii ];
248 CC[ ii ][ ii ] = dotp;
250 for (
int jj = 0; jj < ii; jj++ )
255 for (
int kk = 0; kk < rows; kk++ )
256 dotp += ( ATrow[ kk ] * AA[ kk ][ jj ] );
258 CC[ ii ][ jj ] = dotp;
268 tmm( AA, CC, rows, columns );
272 for (
int ii = 0; ii < columns - 1; ii++ )
273 for (
int jj = ii + 1; jj < columns; jj++ )
274 CC[ ii ][ jj ] = CC[ jj ][ ii ];
280 int rows,
int columns )
282 for (
int ii = 0; ii < rows; ii++ )
286 for (
int jj = 0; jj < columns; jj++ )
287 dotp += ( AA[ ii ][ jj ] * bb[ jj ] );
295 int rows,
int columns )
297 for (
int jj = 0; jj < columns; jj++ )
301 for (
int ii = 0; ii < rows; ii++ )
302 dotp += ( AA[ ii ][ jj ] * bb[ ii ] );
310 int rows,
int size,
int columns )
312 for (
int ii = 0; ii < rows; ii++ )
314 for (
int jj = 0; jj < columns; jj++ )
318 for (
int kk = 0; kk < size; kk++ )
319 dotp += ( AA[ ii ][ kk ] * BB[ kk ][ jj ] );
321 CC[ ii ][ jj ] = dotp;
328 int rows,
int columns )
330 for (
int ii = 0; ii < rows; ii++ )
331 for (
int jj = 0; jj < columns; jj++ )
332 CC[ ii ][ jj ] = AA[ ii ][ jj ] + BB[ ii ][ jj ];
338 for (
int ii = 0; ii < size; ii++ )
339 cc[ ii ] = aa[ ii ] + bb[ ii ];
345 for (
int ii = 0; ii < size; ii++ )
346 for (
int jj = 0; jj < size; jj++ )
347 CC[ ii ][ jj ] = ( ii != jj ? 0.0 : 1.0 );
353 for (
int ii = 0; ii < rows; ii++ )
354 for (
int jj = 0; jj < columns; jj++ )
355 CC[ ii ][ jj ] = AA[ ii ][ jj ];
361 for (
int ii = 0; ii < size; ii++ )
368 for (
int ii = 0; ii < size; ii++ )
369 CC[ ii ][ ii ] += ss;
375 for (
int ii = 0; ii < rows; ii++ )
376 for (
int jj = 0; jj < columns; jj++ )
377 CC[ ii ][ jj ] += ss;
383 for (
int ii = 0; ii < rows; ii++ )
384 for (
int jj = 0; jj < columns; jj++ )
385 CC[ ii ][ jj ] *= ss;
393 for (
int ii = 0; ii < size; ii++ )
394 dotp += ( aa[ ii ] * bb[ ii ] );
404 for (
int ii = 0; ii < size; ii++ )
405 dotp +=
sq( aa[ ii ] );
415 for (
int i = 0; i < n; i++ ) s += t.sprintf(
"%.15f ", v[ i ] );
423 for (
int i = 0; i < rows; i++ )
print_vector( A[ i ], columns );
445 QVector< double > vscaling( n );
446 double* scaling = vscaling.data();
449 double tiny = 1.0E-20;
456 for (
int i = 0; i < n; i++ )
460 for (
int j = 0; j < n; j++ )
462 if ( fabs( matrix[ i ][ j ]) > amax ) amax = matrix[ i ][ j ];
467 qDebug() <<
"Singular Matrix";
471 scaling[ i ] = 1.0 / amax;
475 for (
int j = 0; j < n; j++ )
478 for (
int i = 0; i < j; i++ )
480 dum = matrix[ i ][ j ];
482 for (
int k = 0; k < i; k++ )
483 dum -= matrix[ i ][ k ] * matrix[ k ][ j ];
485 matrix[ i ][ j ] = dum;
492 for (
int i = j; i < n; i++ )
494 dum = matrix[ i ][ j ];
496 for (
int k = 0; k < j; k++ )
497 dum -= matrix[ i ][ k ] * matrix[ k ][ j ];
499 matrix[ i ][ j ] = dum;
501 if ( scaling[ i ] * fabs( dum ) > amax )
503 amax = scaling[ i ]* fabs( dum );
511 for (
int k = 0; k < n; k++ )
513 dum = matrix[ imax ][ k ];
514 matrix[ imax ][ k ] = matrix[ j ][ k ];
515 matrix[ j ][ k ] = dum;
520 scaling[ imax ] = scaling[ j ];
527 if ( matrix[ j ][ j ] == 0.0 ) matrix[ j ][ j ] = tiny;
532 dum = 1.0 / matrix[ j ][ j ];
533 for (
int i = j + 1; i < n; i++ ) matrix[ i ][ j ] *= dum;
552 for (
int i = 0; i < n; i++ )
560 for (
int j = ii; j < i; j++ ) sum -= A[ i ][ j ] * b[ j ];
563 if ( sum != 0 ) ii = i;
568 for (
int i = n - 1; i >= 0; i-- )
572 for (
int j = i + 1; j < n; j++ ) sum -= A[ i ][ j ] * b[ j ];
574 b[ i ] = sum / A[ i ][ i ];
586 QVector< int > vindex( n );
587 int* index = vindex.data();