Results 1 to 2 of 2

Math Help - wrong value of r^2

  1. #1
    Member
    Joined
    Jun 2008
    Posts
    170

    wrong value of r^2

    I am computing r^2 for a set of data. Here is a snippet of code:
    Code:
     for (i=1;i<=ndata;i++) {
                *chi2 += SQR(y[i]-(*a)-(*b)*x[i]);
                syy += 1/(ndata-1)*(*chi2);
                sdy += 1/(ndata-1)*SQR((y[i]-yavg));
                *r2 = 1-(syy/sdy); 
            sigdat=sqrt((*chi2)/(ndata-2)); 
            *siga *= sigdat; 
            *sigb *= sigdat; 
        } 
        
        }
    }
    I keep getting  r^2 = 1.00000 . However when I change it to  *r2 = 1- (1.0)/(2.0) I get  *r2 = 0.5 . So for some reason  (syy/sdy) = 0 . Why? How do I change this? I declared all the important variables as float. I also did  1.0/(\text{ndata}-1) and it did not work.
    Last edited by particlejohn; August 5th 2008 at 08:05 PM.
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Member
    Joined
    Jun 2008
    Posts
    170
    figured it out.
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. [SOLVED] am I wrong here or is my textbook wrong??
    Posted in the Algebra Forum
    Replies: 5
    Last Post: September 25th 2011, 06:13 PM
  2. IVP, what am I doing wrong?
    Posted in the Differential Equations Forum
    Replies: 4
    Last Post: February 10th 2010, 12:17 AM
  3. Replies: 6
    Last Post: August 12th 2009, 03:15 AM
  4. Why am I wrong?!
    Posted in the Calculus Forum
    Replies: 1
    Last Post: April 18th 2009, 08:34 PM
  5. Wrong answer key or wrong me ?
    Posted in the Algebra Forum
    Replies: 2
    Last Post: July 2nd 2008, 05:42 AM

Search Tags


/mathhelpforum @mathhelpforum