Thread: my gaussian elimination problem

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    8

    my gaussian elimination problem

    Code:
    Fraction arr[10][11];
    
     if (arr[i][i] == 0)
    that part of my code doesn't work...after i is initialized. I'm just wondering why.

    these are two of my methods in my class Fraction
    Code:
    void div( Fraction divisor )
      {
        numerator   *= divisor.denominator;
        denominator *= divisor.numerator;
      }
    
    void mult( Fraction multiplier)
      {
        numerator /= multiplier.denominator;
        denominator /= multiplier.numerator;
       }
    in the int main of that program,
    fraction arr[10][11] and int i, j, and k are initialized.

    i've been trying to send arrays to the class to return it as a fraction. but im not sure if im doing this right.

    Code:
      if (arr[i][i] != 0) // this line returns an error
      {
       Fraction divisor = arr[i][i];
    
       for (int k=0; k < (N+1); k++)
         {
          arr[i][k].div(divisor);
         }
       }
    
      for (int j=0; j<N; j++) // for each row
        {
         if (j !=i)
          {
           Fraction multiplier = arr[j][i];
           for (int k=0; k<(N+1); k++)
             arr[j][k].mult(multiplier) -= arr[i][k].mult(multiplier);
    ok i didn't put that much code in this time..i hope someone can help. im not really sure if im getting somewhere with this right now. i've looked everywhere in my book..and i can't find it..but if its in there and i just can't see it..i just sure as hell don't understand it.

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    arr[i][i] is of type Fraction, why are you comparing it with the integer 0?
    May not be apples and oranges to you, but it is to the compiler.

    gg

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    8

    i understand that

    i knew that from the beginning..but how do i with the lack of a better term convert Fraction arr[i][i] to int?

  4. #4
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    One way:
    Code:
    bool Fraction::is_zero()
    {
       return (numerator == 0);
    }
    Or you could overload the "!=" operator.

    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  2. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  3. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  4. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM
  5. Gaussian Elimination Problem
    By Inexorable in forum C Programming
    Replies: 1
    Last Post: 11-08-2002, 02:25 AM