Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Matrix colunms-Urgent

  1. Mar 3, 2006 #1
    Please I need help to do the following:

    add the elements of each colunm of a matrix and
    Count the number of colunm whose the sum is less than 1.

    I did this: i is the indice of line , j =indice of colunm.. size = dimension of the square matrix.

    { for(i=0;i<size;i++)
    if (sum<1)

    The compiler says I am wrong . I have to turn this in few hours...
    please help me!

  2. jcsd
  3. Mar 3, 2006 #2


    User Avatar

    Staff: Mentor

    What do you mean the compiler "says you are wrong"? Is it throwing a syntax error?

    Is sum a global or local variable? How is it initialized? How about count?

    Is the assignment to come up with one sum total for all columns, or one total per column?
  4. Mar 3, 2006 #3
    The compiler(Unix) say that a semicolon is missing after the second for loop. sum and count are a local variables.

    In fact the assignemt says , "if the sum of each colunm ( for the whole matrix ) is less than 1 print "OK".

    Example, if it is a 2 x 2 matrix,

    0.2 0.25
    0.3 .4

    it should print "OK" since the sum of each colunm is less than 1.

    This is why I use the count. if count = size ( size of the matrix) ,then each the colunm has a sum less than 1 , so I can print "OK".

    sum and count are initialzed to zero at the beginning of the program.(sum=count=0;)

  5. Mar 3, 2006 #4


    User Avatar
    Science Advisor

    You should probably post the whole code because if it is a syntax error it might have propagated from previous code. Sounds like it.
  6. Mar 3, 2006 #5
    the problem is that I am working directly in unix lab . there is no copy/paste in the editor I am using..
  7. Mar 3, 2006 #6


    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    That's a problem with debugging then -- many errors are simple typos. When you retype it, you're likely to get it right that time, and thus we cannot catch your typo. :frown:
  8. Mar 3, 2006 #7


    User Avatar

    Staff: Mentor

    Then just pipe a listing to a file that you can post.
  9. Mar 7, 2006 #8
    I am not sure if i have reached u in time
    i think the syntax should be as follows

    if (sum<1)
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?

Similar Discussions: Matrix colunms-Urgent
  1. Determinate Matrix (Replies: 4)