Can help me with the coding?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cool17
    New Member
    • Oct 2006
    • 24

    Can help me with the coding?

    /*
    IsScalarMatrix
    ---------------
    Check if a Matrix is a Scalar matrix
    where: diagonal elements all contain the same scalar aij.
    Return (!false == true,!true == false)
    */
    bool CDblMatrix::IsS calarMatrix()
    {
    int nRows = 0, nCols = 0;
    double temp;


    if (m_nCols == m_nRows)
    {
    temp = m_ppData[0][0];
    for (nRows = 0; nRows < m_nRows; nRows++)
    {
    for (nCols = 0; nCols < m_nCols; nCols++)
    {
    if ( nRows && nCols == 0)

    {
    if(((nRows != nCols) && (m_ppData[nRows][nCols])) != 0)
    {
    cout<< "The matrix is not a Scalar Matrix"<< endl;
    return false;
    }
    else if (((nRows == nCols) && (m_ppData[nRows][nCols])) != temp)
    {
    cout<< "The matrix is not a Scalar Matrix"<< endl;
    return false;
    }

    }
    else
    {
    cout<< "The matrix is a Scalar Matrix"<< endl;
    return true;
    }


    }
    }

    }
    else
    {
    cout<< "The matrix is not a square matrix."<< endl;
    return false;
    }

    }


    Hi i am writing a code for the scalar matrix. But when i did the testing i got problem...as those are not scalar matrix but it was detected as scalar...so can u help me please...thank you
  • D_C
    Contributor
    • Jun 2006
    • 293

    #2
    You only need nRows, or nCols, not both. Replace
    Code:
    for (nRows = 0; nRows < m_nRows; nRows++)
    {
      for (nCols = 0; nCols < m_nCols; nCols++)
      {
        ...
      }
    }
    by
    Code:
    for(nRows = 1; nRows < m_nRows; nRows++)
    {
      if( matrix[nRows][nRows] != matrix[0][0] )
        // not a scalar matrix
    }
    // is a scalar matrix

    Comment

    • cool17
      New Member
      • Oct 2006
      • 24

      #3
      oh ok..thank you

      Comment

      • shritha
        New Member
        • Jan 2008
        • 1

        #4
        hey ...how to convert a given matrix to a scalar matrix,we can apply row and col operation only when we know the variables but if i want to accept the variables at run time??/

        Comment

        Working...