assign3/mat.cpp
// square of distance between two matrices
// this is an element by element operation and not like matrix multiply
square of distance between two matrices
this is an element by element operation and not like matrix multiply
square of distance between two matrices this is an element by element operation and not like matrix multiply
double Matrix::dist2(const Matrix &other) const
{
    double sum;
    assertDefined("lhs of dist2");
    other.assertDefined("rhs of dist2");
    assertOtherSizeMatch(other, "dist2");
    sum = 0;
    for (int r=0; r<maxr; r++) {
        for (int c=0; c<maxc; c++) {
            double tmp;
            tmp = m[r][c] - other.m[r][c];
            sum += tmp * tmp;
        }
    }
    return sum;
}
double Matrix :: dist2 ( const Matrix & other ) const { double sum ; assertDefined ( " " ) ; other . assertDefined ( " " ) ; assertOtherSizeMatch ( other , " " ) ; sum = 0 ; for ( int r = 0 ; r < maxr ; r ++ ) { for ( int c = 0 ; c < maxc ; c ++ ) { double tmp ; tmp = m [ r ] [ c ] - other . m [ r ] [ c ] ; sum += tmp * tmp ; } } return sum ; }
square of distance between two matrices
this is an element by element operation and not like matrix multiply
square of distance between two matrices this is an element by element operation and not like matrix multiply