Dear all,
I need to write a code for least square approximation with a straight line. The formula can be found here. - for a and b which are all that I need.
However, the problem is that I have like 10000 data for doing the best fit, both the unit of x and y axis are of 5 digits. And the least square fitting formula will require me to do something like multiplying z=35378 to y=15386 something like that, then add such multiplied yz for 10000 times. The size of the number resulted from such calculation (not necessarily integer) will be quite daunting.
Although I only need to run such code one time or so to calculate the a and b i.e. the slope and intercept for one time.
I would like to know, if it is OK for me to just declare the array (or vector) of x and y as double (or vector<double>) as usual? Will anything erroneous happened during such calculation?
Have you tried using a vector to hold each place value? Using a decimal system, this would mean vector[0] would hold the first number, vector[1] the second, etc. then do the math that way. It may simplify your work for you since you don't need to declare any large data types. Although, this may not be faster, but might make it easier on the rest of math depending on the depths of the math being used.