matrix mult. (source and question)

Rick Busdiecker rfb at h.cs.cmu.edu
Mon Nov 18 01:59:38 AEST 1985


Subject: Re: matrix mult. (source and question)
Message-Id: <501087498/rfb at H.CS.CMU.EDU>
In-Reply-To: Gregory R. Simpson @ The North Coast's netnews message of Thu, 14-Nov-85 00:18:16 EST

If Gregory Simpson's data representation were slightly different, things
would go much more nicely, maybe even more nicely than in fortran 8-}


Declaring a two-dimensional array is not equivalent to declaring an
array of one-dimensional arrays, i.e.

	double matrix [m][n]

is not the same as

	double (matrix [m]) [n];

however a reference to element (m,n) may still be coded as matrix[m][n] in
a routine regardless of which declaration is used.  With the second
declaration element (m,n) could also be referenced as *(*(matrix + m) + n).


/*===========================================================================
 * matrix_multiply
 *
 * Multiplies the matrix a (dimension m,n) by the matrix b (dimension n,p)
 * into the matrix c (dimension m,p).  Matrices must be declared explicitly
 * to be arrays of arrays rather than 2d arrays.
 */

void matrix_multiply (a, b, c, m, n, p)
double	**a, **b, **c;
int	m, n, p;
{
    int		i, j, k;
    
    for (i = 0; i < m; i++)
        for (j = 0; j < p; j++)
	{
            c [i][j] = 0.0;
	    for (k = 1; k < n; k++)
	        c += a [i][k] * b [k][j];
	}
}



More information about the Comp.sources.unix mailing list