8. Numerical Technique: Linear Modeling
Given input data points (x1,y1), (x2,y2), ... (xn,yn), the linear approximationy = m*x + b
with minimum error is given by equations 3.1 and 3.2, page 130:
- Excerpts from chapter3_10.c:
-
int count=0; double x, y, sumx=0, sumy=0, sumx2=0, sumxy=0, denominator, m, b; while ((fscanf(zone,"%lf %lf",&x,&y)) == 2) { ++count; sumx += x; sumy += y; sumx2 += x*x; sumxy += x*y; } denominator = sumx*sumx - count*sumx2; m = (sumx*sumy - count*sumxy)/denominator; b = (sumx*sumxy - sumx2*sumy)/denominator;