assign5/mat.cpp
// This computes the mean of every column and puts it into a row vector
// WARNING: allocates new matrix for answer
This computes the mean of every column and puts it into a row vector
WARNING: allocates new matrix for answer
This computes the mean of every column and puts it into a row vector WARNING : allocates new matrix for answer
Matrix Matrix::stddevVec() {
    assertDefined("stddevVec");
    Matrix stddev(1, maxc);
    for (int c=0; c<maxc; c++) {
        double sum, sum2;
        sum = sum2 = 0.0;
        for (int r=0; r<maxr; r++) {
            sum += m[r][c];
            sum2 += m[r][c]*m[r][c];
        }
        stddev.m[0][c] = sqrt(sum2/maxr - (sum*sum)/(maxr*maxr));  
    }
    stddev.defined = true;
    return stddev;
}
Matrix Matrix :: stddevVec ( ) { assertDefined ( " " ) ; Matrix stddev ( 1 , maxc ) ; for ( int c = 0 ; c < maxc ; c ++ ) { double sum , sum2 ; sum = sum2 = 0.0 ; for ( int r = 0 ; r < maxr ; r ++ ) { sum += m [ r ] [ c ] ; sum2 += m [ r ] [ c ] * m [ r ] [ c ] ; } stddev . m [ 0 ] [ c ] = sqrt ( sum2 / maxr - ( sum * sum ) / ( maxr * maxr ) ) ; } stddev . defined = true ; return stddev ; }
This computes the mean of every column and puts it into a row vector
WARNING: allocates new matrix for answer
This computes the mean of every column and puts it into a row vector WARNING : allocates new matrix for answer
// not the most stable way to compute!!