I have a function , which is to mulitply a matrix and vector:
double *matrix_vector_multiply(int rows, int cols,
double **mat, double *vec)
{
double *answer = malloc(rows * sizeof (double));
int i,j;
for (i=0; i<rows; rows++)
ans[i]=0;
for (i=0; i<rows; rows++){
for (j=0; j<cols; cols++)
{
answer[i] = answer[i] + mat[i][j] * vec[j];
}
}
return ans;
}
I keep getting all 0’s for the output.. any ideas on how to fix it?
Is this actual code that you have posted ? As well as the obvious problems with
ansandansweretc, your for loops are completely wrong, e.g.should be:
and:
should be: