90 likes | 705 Views
6. Method of Least Squares:. (pp. 1001). Method of Least Squares (Least Squares Regression):. Examp 6.1:. : Sum of squares of errors. y=a+bx. a=1.188 b=0.484. y=1.188+0.484x. mls.txt. 3 -5,-2 2,4 7,3.5. Sub mlsquares_Click () ' Change File mls.txt for different problems ' y=a+b*x
E N D
6. Method of Least Squares: (pp. 1001) Method of Least Squares (Least Squares Regression): Examp 6.1: : Sum of squares of errors y=a+bx a=1.188 b=0.484 y=1.188+0.484x
mls.txt 3 -5,-2 2,4 7,3.5 Sub mlsquares_Click () ' Change File mls.txt for different problems ' y=a+b*x fl = fl0 + "mls.txt": Open fl For Input As 1 Input #1, n: ReDim x(n), y(n) For i = 1 To n: Input #1, x(i), y(i): Next i Close #1 Call cls1: Print n: Print For i = 1 To n: Print x(i), y(i): Next i: Print a11 = n: a12 = 0: a22 = 0: b1 = 0: b2 = 0 For j = 1 To n a12 = a12 + x(j) a22 = a22 + x(j) ^ 2 b1 = b1 + y(j) b2 = b2 + x(j) * y(j) Next j a21 = a12 det = (a11 * a22 - a12 * a21) a = (a22 * b1 - a12 * b2) / det b = (-a21 * b1 + a11 * b2) / det Print : Print " A, B : ", a, b End Sub
Examp 6.2: y=200.13 + 8.82x y=a+bx