39#include "EST_FMatrix.h"
40#include "EST_system.h"
52 for(
int i=0; i<
x.n(); ++i)
63 cerr <<
"polynomial_fit : order must be >= 1" <<
endl;
68 cerr <<
"polynomial_fit : x and y must have same dimension" <<
endl;
73 cerr <<
"polynomial_fit : weights must have same dimension as x and y" <<
endl;
78 cerr <<
"polynomial_fit : x and y must have at least order+1 elements"
91 for(
int row=0;row<
y.n();row++)
94 for(
int col=0;col<=order;col++){
112 cerr <<
"polynomial_fit : inverse failed (";
114 cerr <<
"unspecified reason)" <<
endl;
168 cerr <<
"diagonalise: non-square matrix ";
196 for (i = I = 0; i < n; ++i, ++I)
200 for (
j =
J = 0;
j < n; ++
j, ++
J)
219 s(0, i) = a.a(row, i);
230 s(i, 0) = a.a(i, col);
263 for (i = 0; i < n; ++i)
264 for (
j = 0;
j < n; ++
j)
265 t(n - i - 1, n -
j - 1) = a.a(i,
j);
285static void row_swap(
int from,
int to,
EST_FMatrix &a)
334 inv.a_no_check(i,
j) = 0.0;
337 inv.a_no_check(i,i) = 1.0;
377 inv.a_no_check(i,k) /= s;
391 inv.a_no_check(
j,k) -=
inv.a_no_check(i,k) * s;
446 cerr <<
"Tried to take determinant of non-square matrix\n";
460 for (i = 0; i < n; ++i)
464 A[i] =
pow((
float)-1.0, p) * determinant(sub(a, i,
j));
470 for (i = 0; i < n; ++i)
495 cerr <<
"Can't make non-square identity matrix !" <<
endl;
511 cerr <<
"Can't add vectors of differing lengths !" <<
endl;
516 for(
int i=0; i<
a_len; i++ )
529 cerr <<
"Can't subtract vectors of differing lengths !" <<
endl;
534 for(
int i=0; i<
a_len; i++ )
546 cerr <<
"Can't extract diagonal of non-square matrix !" <<
endl;
561 for(
int i=0;i<
coeffs.length();i++)
577 cerr <<
"Can't symmetrize non-square matrix !" <<
endl;
593 v.
resize(
M.num_rows() *
M.num_columns());
595 for(i=0;i<
M.num_rows();i++)
596 for(
j=0;
j<
M.num_columns();
j++)
606 for(
int row=0;row<
M.num_rows();row++)
607 for(
int col=0;col<
M.num_columns();col++)
610 M.a_no_check(row,col) = r;
619 for(
int i=0;i<
V.length();i++)
629 if(
M.num_rows() !=
M.num_columns())
631 cerr <<
"Can't make non-square symmetric matrix !" <<
endl;
637 for(
int row=0;row<
M.num_rows();row++)
638 for(
int col=0;col<=row;col++)
641 M.a_no_check(row,col) = r;
642 M.a_no_check(col,row) = r;
649 if(
M.num_rows() !=
M.num_columns())
651 cerr <<
"Can't make non-square symmetric matrix !" <<
endl;
656 for(
int row=0;row<
M.num_rows();row++)
667 cerr <<
"Can't make polynomial basis function : dimension mismatch !" <<
endl;
669 cerr <<
" T.num_rows()=" <<
T.num_rows() <<
endl;
672 for(
int row=0;row<
T.num_rows();row++)
673 for(
int col=0;col<
T.num_columns();col++)
674 T.a_no_check(row,col) =
pow(t[row],(
float)col);
682 for(i=0;i<
M.num_rows();i++)
683 for(
j=0;
j<
M.num_columns();
j++)
699 m.resize(
v1.length(),
v2.length());
701 for(
int i=0;i<
v1.length();i++)
702 for(
int j=0;
j<
v2.length();
j++)
703 m.a_no_check(i,
j) =
v1.a_no_check(i) *
v2.a_no_check(
j);
710#if !defined(SYSTEM_IS_WIN32)
715 seed = getpid() * (
tp.tv_usec&0x7fff);
730 seed = (getpid()&0x7f) * (
tp.tv_usec&0xff);
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