--[[ --Formula : --Trend Line Equation(y) = a + bx --Where, -- Slope(b) = (NSXY - (SX)(SY)) / (NSX2 - (SX)2) -- Intercept(a) = (SY - b(SX)) / N --This tool will help you to dynamically calculate the trendline chart online. Trend line --is also referred as Dutch Line or Line of Best Fit. --]]-- -- http://easycalculation.com/statistics/trend-line.php -- http://www.easycalculation.com/statistics/learn-regression.php -- http://easycalculation.com/statistics/trend-line.php function regression() print ("Enter number of points:") n=io.read() sum_x=0 sum_y=0 sum_xx=0 sum_xy=0 for i=1,n do -- print ("For point",i) -- print ("Enter x:") x=i print ("Enter y:") y=io.read() sum_x=sum_x+x sum_y=sum_y+y xx=math.pow(x,2) sum_xx=sum_xx+xx xy=x*y sum_xy=sum_xy+xy end --Calculating the coefficients a=(-sum_x*sum_xy+sum_xx*sum_y)/(n*sum_xx-sum_x*sum_x) b=(-sum_x*sum_y+n*sum_xy)/(n*sum_xx-sum_x*sum_x) print ("The required straight line is Y=",b,"X+(",a,")") end regression()