Programming meeting #8
-
Upload
hideyuki-tabata -
Category
Engineering
-
view
53 -
download
2
Transcript of Programming meeting #8
Programming Meeting #8
EEC: T.Hideyuki
Programming Meeting #8
Least Squares
Practice
What's next?
+
Programming Meeting #8
Least Squares
x
y
O
1
234
1 2 3 4 65 7
Error
Programming Meeting #8
Least Squares
x
y
1
234
1 2 3 4 65 7y- intercept
Slope
Programming Meeting #8
Least Squares
DataSlope
y-intercept
Least Squares
Programming Meeting #8
Data
Least Squares
Programming Meeting #8
DataLeast Squares
Coordinates(X,Y)
Programming Meeting #8
DataLeast Squares
Variable Array
Coordinates(X,Y)
Programming Meeting #8
DataLeast Squares
Arrayx = [1.0, 2.0, 3.0, 4.0, 5.0]
y = [1.3, 1.8, 2.8, 2.5, 3.9]
Programming Meeting #8
x
y
O
1
234
1 2 3 4 65 7
x = [1.0, 2.0, 3.0, 4.0, 5.0]y = [1.3, 1.8, 2.8, 2.5, 3.9]
Least Squares
0
2 3
4
Data
1
Programming Meeting #8
n xy x y
n x x2 2α
( )=
Σ −Σ Σ
Σ − Σ
The slope
The number of points
Arrays
Least Squares
Programming Meeting #8
n xy x y
n x x2 2α
( )=
Σ −Σ Σ
Σ − Σ
The slopeLeast Squares
∑xy ∑x ∑y
∑x^2 ∑x
Function
Programming Meeting #8
The slopeLeast Squares
xΣSummationArray Float
Programming Meeting #8
The slopeLeast Squares
xΣ for ine x
end
sum = 0.0
sum = sum + e
Programming Meeting #8
The slopeLeast Squares
xΣ for ine array
end
sum = 0.0
sum = sum + e
def
endreturn sum
Summation ( )array
Programming Meeting #8
The slopeLeast Squares
Summation( )
x = [1.0, 2.0, 3.0, 4.0, 5.0]y = [1.3, 1.8, 2.8, 2.5, 3.9]
x 15.0xΣ
Summation(
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]
y 12.3)Σy
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
Programming Meeting #8
n xy x y
n x x2 2α
( )=
Σ −Σ Σ
Σ − Σ
The slopeLeast Squares
Σx 2∑x ∑y
∑x
Programming Meeting #8
The slopeLeast Squares
Σx 2 for ine array
end
sum = 0.0
sum = sum + e
def
endreturn sum
Summation2 ( )array
**2
Programming Meeting #8
The slopeLeast Squares
xyΣn xy x y
n x x2 2α
( )=
Σ −Σ Σ
Σ − Σ
∑x ∑y
∑x∑x^2
Programming Meeting #8
The slopeLeast Squares
xyΣx = [1.0, 2.0, 3.0, 4.0, 5.0]
y = [1.3, 1.8, 2.8, 2.5, 3.9]
* * * * *
1.3 3.6 8.4 10.0 19.5
42.8
Programming Meeting #8
The slopeLeast Squares
xyΣ for in
Programming Meeting #8
The slopeLeast Squares
xyΣ while
sum = 0.0i = 0
i < x.lengthsum = sum + x[i] * y[i]i = i + 1
end
The number of elements in x
Programming Meeting #8
The slopeLeast Squares
xyΣ while
sum = 0.0i = 0
i < x.lengthsum = 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…
Programming Meeting #8
The slopeLeast Squares
xyΣ while
sum = 0.0i = 0
i < x.lengthsum = sum + x[i] * y[i]i = i + 1
end
def SumXY(x, y)
endreturn sum
n xy x y
n x x2 2α
( )=
Σ −Σ Σ
Σ − Σ
∑x ∑y
∑x^2 ∑x
Programming Meeting #8
The slopeLeast Squares
∑xy
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
Programming Meeting #8
Least Squares
nx.length
y.lengthor
The slope
Array.lengthThe number of elements
in Array
Programming Meeting #8
y xn
βα
=Σ − Σ
The slope
Least Squares The y-intercept
(Summation(y) - a*Summation(x)) / n
Programming Meeting #8
What's next?
Programming Meeting #8
What's next?
Practice
Programming Meeting #8
Questions
Programming Meeting #8
Thank you for Meeting!