double not assigning value 
Author Message
 double not assigning value

Hi,

I'm writing a program to perform Gaussian reduction of a matrix to get it
into reduced-echelon form, and it calls the following function to choose a pivot
point and arrange the rows as needed:

void choosepivot(double **a, int i, int j, double N) {
  double pivot = 0.0;
  int k, ipivot;
  for(ipivot=i,k=i;k<N;k++) {
    if(fabs(a[k][j]) > pivot) {
      pivot = a[k][j];
      printf("a[%d][%d]=%f\n", k, j, a[k][j]);
      printf("pivot=%d\n", pivot);
      ipivot = k;
      printf("ipivot=%d\n", ipivot);
    }
  }
  row_swap(a, i, ipivot);
  return;

Quote:
}

where a is the matrix itself, i is the row to start from, j is the
column, and N is the smaller dimension of the matrix.

I pass it an NxN+1 matrix, for example

|1 2 5|
|3 4 6|

and two values of (i, j), namely (0, 0) and (1, 1). The problem is, the
line

pivot = a[k][j]

is not working; rather, pivot always stays at 0.0. I know it is getting
to the for loop, because the printf() statements are always working.

Here is the output for the program:


Value of N: 2
Matrix A:
What is the value of (1, 1)? 1
What is the value of (1, 2)? 2
What is the value of (2, 1)? 3
What is the value of (2, 2)? 4
Matrix B:
What is the value of (1, 1)? 5
What is the value of (2, 1)? 6
a[0][0]=1.000000
pivot=0
ipivot=0
a[1][0]=3.000000
pivot=0
ipivot=1
0  0  0  
0  0  0  

Anybody have any ideas? I'm completely stumped. If you need to, I can
post the source for the entire program.

Thanks,

Grayson



Sun, 18 Apr 2004 14:45:03 GMT  
 double not assigning value

Quote:

> double pivot = 0.0;
  ....
> pivot = a[k][j]

> is not working; rather, pivot always stays at 0.0. I know it
> is getting to the for loop, because the printf() statements
> are always working.
> printf("pivot=%d\n", pivot);

                ^^

Bzzt .. you're trying to print a double with a %d format string,
which may have all kind of strange effects since printf expects
pivot to have sizeof int, which it probably hasn't.

Use %f instead, and your problem will be over ...

willem



Sun, 18 Apr 2004 15:14:31 GMT  
 double not assigning value


Quote:
> Hi,

> I'm writing a program to perform Gaussian reduction of a matrix to get
it
> into reduced-echelon form, and it calls the following function to
choose a pivot
> point and arrange the rows as needed:

> void choosepivot(double **a, int i, int j, double N) {
>   double pivot = 0.0;
>   int k, ipivot;
>   for(ipivot=i,k=i;k<N;k++) {
>     if(fabs(a[k][j]) > pivot) {
>       pivot = a[k][j];
>       printf("a[%d][%d]=%f\n", k, j, a[k][j]);
>       printf("pivot=%d\n", pivot);

This is probably the cause of your problem. The %d format specifier
doesn't match the type of pivot. Try %f as you did in the previous
printf statement - but I guess you've already worked that out :-)

    Regards
    Des Walker



Sun, 18 Apr 2004 15:18:17 GMT  
 double not assigning value

Quote:



>> Hi,

>> I'm writing a program to perform Gaussian reduction of a matrix to get
> it
>> into reduced-echelon form, and it calls the following function to
> choose a pivot
>> point and arrange the rows as needed:

>> void choosepivot(double **a, int i, int j, double N) {
>>   double pivot = 0.0;
>>   int k, ipivot;
>>   for(ipivot=i,k=i;k<N;k++) {
>>     if(fabs(a[k][j]) > pivot) {
>>       pivot = a[k][j];
>>       printf("a[%d][%d]=%f\n", k, j, a[k][j]); printf("pivot=%d\n",
>>       pivot);

> This is probably the cause of your problem. The %d format specifier
> doesn't match the type of pivot. Try %f as you did in the previous
> printf statement - but I guess you've already worked that out :-)

>     Regards
>     Des Walker

Doh! I thought I had gotten rid of all of those when I changed int **a to
double **a. Oh well, shows the value of another pair of eyes.

I feel really dumb now.. :/

Thanks to both of you who responded.

Grayson



Sun, 18 Apr 2004 15:23:19 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. CDateTimeCtrl value not being set as assigned.

2. sum of double values not the same after re-fetch from dbase

3. sum of double values not same after re-fetch from database

4. addition long values to long double value ?

5. Comparing double NAN with double INF is not IEEE compliant

6. Assigning nan to a double

7. assigning values to an array

8. Scheduled c# application and how to assign customizable value through scheduled task

9. How to assign a value to unsigned long variable

10. I cannot assign value to the variable

11. Problems assigning const fields in a class to an initial value

12. assigning the value of a char to a string (newbie)

 

 
Powered by phpBB® Forum Software