A
alphaLaura
Hi all - I'm just new to the group and I hope nobody minds me asking
for some help.
I currently have an assignment which deals with matrices (more
specifically, Gauss-Seidel solving of matrices). One of the side tasks
we have is to generate an NxN matrix of random numbers using the rand()
function, but subject to the constraint that the absolute value of the
diagonal element (a) must be greater than the sum of the absolute
values of all the other elements in that row. That is -
fabs(a) > sum {from j to n} of (fabs(a[j])
For some reason, I have major brain block over this. My initial
thoughts were to use a do{}-while() loop, but I have since tried
everything and gotten nowhere. My random matrix-filler function
currently looks like this -
void fill_random(matrix m)
{
int i, j;
double summation = 0;
for(i = 0; i < n; ++i)
{
for(j = 0; j < n; ++j)
{
m[j] = 2.0 * rand() / RAND_MAX - 1; // Fills element with random
number
do
{
summation += m[j];
break;
}
while ((i!=j) && (fabs(summation) < fabs(m)));
}
}
}
Any suggestions on this are enormously appreciated! I reckon I've just
been thinking about this for too long...
for some help.
I currently have an assignment which deals with matrices (more
specifically, Gauss-Seidel solving of matrices). One of the side tasks
we have is to generate an NxN matrix of random numbers using the rand()
function, but subject to the constraint that the absolute value of the
diagonal element (a) must be greater than the sum of the absolute
values of all the other elements in that row. That is -
fabs(a) > sum {from j to n} of (fabs(a[j])
For some reason, I have major brain block over this. My initial
thoughts were to use a do{}-while() loop, but I have since tried
everything and gotten nowhere. My random matrix-filler function
currently looks like this -
void fill_random(matrix m)
{
int i, j;
double summation = 0;
for(i = 0; i < n; ++i)
{
for(j = 0; j < n; ++j)
{
m[j] = 2.0 * rand() / RAND_MAX - 1; // Fills element with random
number
do
{
summation += m[j];
break;
}
while ((i!=j) && (fabs(summation) < fabs(m)));
}
}
}
Any suggestions on this are enormously appreciated! I reckon I've just
been thinking about this for too long...