40#include "EST_DMatrix.h"
50 for(
int i=0; i<
x.n(); ++i)
61 cerr <<
"polynomial_fit : order must be >= 1" <<
endl;
66 cerr <<
"polynomial_fit : x and y must have same dimension" <<
endl;
71 cerr <<
"polynomial_fit : weights must have same dimension as x and y" <<
endl;
76 cerr <<
"polynomial_fit : x and y must have at least order+1 elements"
89 for(
int row=0;row<
y.n();row++)
92 for(
int col=0;col<=order;col++){
93 A(row,col) =
pow(
x[row],(
double)col) *
weights[row];
110 cerr <<
"polynomial_fit : inverse failed (";
112 cerr <<
"unspecified reason)" <<
endl;
166 cerr <<
"diagonalise: non-square matrix ";
194 for (i = I = 0; i < n; ++i, ++I)
198 for (
j =
J = 0;
j < n; ++
j, ++
J)
217 s(0, i) = a.a(row, i);
228 s(i, 0) = a.a(i, col);
261 for (i = 0; i < n; ++i)
262 for (
j = 0;
j < n; ++
j)
263 t(n - i - 1, n -
j - 1) = a.a(i,
j);
283static void row_swap(
int from,
int to,
EST_DMatrix &a)
332 inv.a_no_check(i,
j) = 0.0;
335 inv.a_no_check(i,i) = 1.0;
375 inv.a_no_check(i,k) /= s;
389 inv.a_no_check(
j,k) -=
inv.a_no_check(i,k) * s;
444 cerr <<
"Tried to take determinant of non-square matrix\n";
458 for (i = 0; i < n; ++i)
462 A[i] =
pow(-1.0, p) * determinant(sub(a, i,
j));
468 for (i = 0; i < n; ++i)
493 cerr <<
"Can't make non-square identity matrix !" <<
endl;
510 cerr <<
"Can't subtract vectors of differing lengths !" <<
endl;
531 cerr <<
"Can't subtract vectors of differing lengths !" <<
endl;
550 cerr <<
"Can't extract diagonal of non-square matrix !" <<
endl;
565 for(
int i=0;i<
coeffs.length();i++)
581 cerr <<
"Can't symmetrize non-square matrix !" <<
endl;
597 v.
resize(
M.num_rows() *
M.num_columns());
599 for(i=0;i<
M.num_rows();i++)
600 for(
j=0;
j<
M.num_columns();
j++)
610 for(
int row=0;row<
M.num_rows();row++)
611 for(
int col=0;col<
M.num_columns();col++)
614 M.a_no_check(row,col) = r;
623 for(
int i=0;i<
V.length();i++)
633 if(
M.num_rows() !=
M.num_columns())
635 cerr <<
"Can't make non-square symmetric matrix !" <<
endl;
641 for(
int row=0;row<
M.num_rows();row++)
642 for(
int col=0;col<=row;col++)
645 M.a_no_check(row,col) = r;
646 M.a_no_check(col,row) = r;
653 if(
M.num_rows() !=
M.num_columns())
655 cerr <<
"Can't make non-square symmetric matrix !" <<
endl;
660 for(
int row=0;row<
M.num_rows();row++)
671 cerr <<
"Can't make polynomial basis function : dimension mismatch !" <<
endl;
673 cerr <<
" T.num_rows()=" <<
T.num_rows() <<
endl;
676 for(
int row=0;row<
T.num_rows();row++)
677 for(
int col=0;col<
T.num_columns();col++)
678 T.a_no_check(row,col) =
pow(t[row],(
double)col);
686 for(i=0;i<
M.num_rows();i++)
687 for(
j=0;
j<
M.num_columns();
j++)
703 m.resize(
v1.length(),
v2.length());
705 for(
int i=0;i<
v1.length();i++)
706 for(
int j=0;
j<
v2.length();
j++)
707 m.a_no_check(i,
j) =
v1.a_no_check(i) *
v2.a_no_check(
j);
int num_columns() const
return number of columns
void fill(const T &v)
fill matrix with value v
INLINE const T & a_no_check(int row, int col) const
const access with no bounds check, care recommend
int num_rows() const
return number of rows
void resize(int rows, int cols, int set=1)
resize matrix
void resize(int n, int set=1)
resize vector
INLINE int length() const
number of items in vector.
INLINE const T & a_no_check(int n) const
read-only const access operator: without bounds checking