Exemple #1
0
Scalar MatrixMxN<Scalar>::determinant() const
{
    unsigned int rows = (*this).rows();
    unsigned int cols = (*this).cols();
    if(rows!=cols)
    {
        std::cerr<<"Matrix not square matrix, determinant does not exit!\n";
        std::exit(EXIT_FAILURE);
    }
#ifdef PHYSIKA_USE_EIGEN_MATRIX
    return (*ptr_eigen_matrix_MxN_).determinant();
#elif defined(PHYSIKA_USE_BUILT_IN_MATRIX)
    Scalar det = 0.0;
    if(rows==1)
        return (*this)(0,0);
    for(unsigned int j = 0; j < cols; ++j)
    {
        MatrixMxN<Scalar> sub_mat(rows-1,cols-1);
        for(unsigned int ii = 1; ii < rows; ++ii)
            for(unsigned int jj =0; jj< cols; ++jj)
            {
                if(jj==j) continue;
                unsigned int row_idx = ii-1;
                unsigned int col_idx = jj>j?jj-1:jj;
                sub_mat(row_idx,col_idx) = (*this)(ii,jj);
            }
        if(j%2)
            det -= (*this)(0,j)*sub_mat.determinant();
        else
            det += (*this)(0,j)*sub_mat.determinant();
    }
    return det;
#endif
}
Exemple #2
0
MatrixMxN<Scalar> MatrixMxN<Scalar>::cofactorMatrix() const
{
    unsigned int rows = (*this).rows();
    unsigned int cols = (*this).cols();
    if(rows!=cols)
    {
        std::cerr<<"Matrix not square matrix, cofactor matrix does not exit!\n";
        std::exit(EXIT_FAILURE);
    }
    MatrixMxN<Scalar> mat(rows,cols);
    for(unsigned int i = 0; i < rows; ++i)
        for(unsigned int j = 0; j < cols; ++j)
        {
            MatrixMxN<Scalar> sub_mat(rows-1,cols-1);
            for(unsigned int ii = 0; ii < rows; ++ii)
                for(unsigned int jj =0; jj< cols; ++jj)
                {
                    if((ii==i)||(jj==j)) continue;
                    unsigned int row_idx = ii>i?ii-1:ii;
                    unsigned int col_idx = jj>j?jj-1:jj;
                    sub_mat(row_idx,col_idx) = (*this)(ii,jj);
                }
            mat(i,j)=sub_mat.determinant();
            if((i+j)%2)
                mat(i,j)*=-1;
        }
    return mat;
}
Exemple #3
0
pyne::Material pyne::Material::sub_mat (std::set<std::string> nucset,  std::string n)
{
  // Grabs a substream from this stream based on a set of strings.
  // Strings can be of any form.
  std::set<int> iset;
  for (std::set<std::string>::iterator i = nucset.begin(); i != nucset.end(); i++)
  {
    iset.insert(pyne::nucname::zzaaam(*i));
  };

  return sub_mat(iset, n);
};
Exemple #4
0
void from_frame(struct mat * pw, struct mat * PW_f, struct mat * PW_pf,
                struct mat * F, struct mat * pf)
{
  struct mat * t = mat(2, 1);

  double a = MGET(F, 2, 0);

  sub_mat(t, F, 0, 0);

  struct mat * R = mat(2, 2);

  MSET(R, 0, 0, cos(a));
  MSET(R, 0, 1, -sin(a));
  MSET(R, 1, 0, sin(a));
  MSET(R, 1, 1, cos(a));

  struct mat * temp = mat(2, 1);

  prodMat(temp, R, pf);

  addMat(pw, temp, t);

  free(temp);

  double px = MGET(pf, 0, 0);
  double py = MGET(pf, 1, 0);

  MSET(PW_f, 0, 0, 1);
  MSET(PW_f, 0, 2, -py*cos(a) - px * sin(a));
  MSET(PW_f, 1, 1, 1);
  MSET(PW_f, 1, 2, px * cos(a) - py * sin(a));

  memcpy(&PW_pf->values[0], &R->values[0], sizeof(double) * (R->rows * R->columns));

  free(R);
}