1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

C++ project to row reduce matrices

Discussion in 'C++' started by xyzabc, Apr 27, 2009.

  1. xyzabc

    xyzabc New Member

    Joined:
    Apr 13, 2009
    Messages:
    21
    Likes Received:
    0
    Trophy Points:
    0
    I am writing a c++ project to row reduce matrices. I was wondering if the following line would work to find the absolute value of the largest number in a row?

    e=fabs(a);

    Thanks
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    The function calculates the absolute value of a specific value, i.e. it strips off the sign, so fabs(-3) is 3. To find the highest value in a row you need to loop over that row storing the current highest and replace it when you come across a higher value.

    As I've already answered this in another thread here's some code (not compiled):
    Code:
    int arr[10];
    init_arr(arr); // you have to write this; it sets up the 10 values.
    int highest=arr[0]; // set highest to the first value
    for (int i=1; i<10; i++)
    {
      if (arr[i]>highest)
        highest = arr[i];
    }
    // now highest contains the highest individual value
    
     

Share This Page