Hi, everyone. I am trying to calculate slope and intercept (y=mx+b) of 37 data files in .txt files I have. Can anyone tell me if I'm going about this right?
I can't test your program, as I don't have the data files, but I do see one error. Line 22. You've declared your variables but neglected to assign a value. Lines 27 thru 30 are taking the unknown start values of Sx, Sy, Sxy and Sx2, and adding them to your array values. You should start each of your declared values in line 22 as 0.0
To assign values to my variables in line 22, would I set it as:
double Sx = 0.0, Sy = 0.0, ... ?
Yes, that is right.
Also, on line 23, you could declare N as in int. It doesn't change the way the program runs or change the output, but using a double, isn't really necessary.
I ran the program with your data files, and ended up with m = 0.55606 and b equaling -17.8702.