18. Programming
Meeting #8
The slopeLeast Squares
x = [1.0, 2.0, 3.0, 4.0, 5.0]
y = [1.3, 1.8, 2.8, 2.5, 3.9]
def Summation(array)
sum = 0.0
for e in array
sum = sum + e
end
return sum
end
24. Programming
Meeting #8
The slopeLeast Squares
xyΣ while
sum = 0.0
i = 0
i < x.length
sum = sum + x[i] * y[i]
i = i + 1
end
The number
of elements in x
25. Programming
Meeting #8
The slopeLeast Squares
xyΣ while
sum = 0.0
i = 0
i < x.length
sum = sum + x[i] * y[i]
i = i + 1
end
in other languages
for (i = 0; i < x.length; i++) {
sum = sum + x[i] * y[i];
}
keep in
mind…
26. Programming
Meeting #8
The slopeLeast Squares
xyΣ while
sum = 0.0
i = 0
i < x.length
sum = sum + x[i] * y[i]
i = i + 1
end
def SumXY(x, y)
end
return sum
27. n xy x y
n x x2
2
α
( )
=
Σ −Σ Σ
Σ − Σ
∑x ∑y
∑x^2 ∑x
Programming
Meeting #8
The slopeLeast Squares
∑xy
28. Programming
Meeting #8
The slopeLeast Squares
(n*SumXY(x,y) - Summation(x) * Summation(y))
/
(n*Summation2(x) - Summation(x)**2)
n xy x y
n x x2
2
α
( )
=
Σ −Σ Σ
Σ − Σ
∑xy ∑x ∑y
∑x^2 ∑x