Reglin Poly
Reglin Poly
input/output data
Outline
1 Scilab
2 Least squares
3 Scilab commands
Today’s focus
Scilab is free.
Today’s focus
Scilab is free.
Matrix/loops syntax is same as for Matlab.
Today’s focus
Scilab is free.
Matrix/loops syntax is same as for Matlab.
Scilab provides all basic and many advanced tools.
Today’s focus
Scilab is free.
Matrix/loops syntax is same as for Matlab.
Scilab provides all basic and many advanced tools.
Today: best fit: line and polynomial : reglin command
Linear fit
zi = a1 xi + a0 for i = 1, . . . , n (1)
Linear fit
zi = a1 xi + a0 for i = 1, . . . , n (1)
Best fit
Real situtation:
Equation (1) will not be satisfied ‘exactly’.
Least-square-fit problem:
Given n samples of (xi , zi ) pairs,
Best fit
Real situtation:
Equation (1) will not be satisfied ‘exactly’.
Least-square-fit problem:
Given n samples of (xi , zi ) pairs,
find constants a1 and a0 such that the ‘total square error’
n
X
(zi − a1 xi − a0 )2 (2)
i=1
is least.
Best fit
Real situtation:
Equation (1) will not be satisfied ‘exactly’.
Least-square-fit problem:
Given n samples of (xi , zi ) pairs,
find constants a1 and a0 such that the ‘total square error’
n
X
(zi − a1 xi − a0 )2 (2)
i=1
is least.
Least square error
zi = a2 xi2 + a1 xi + a0
zi = a2 xi2 + a1 xi + a0
zi = a2 xi2 + a1 xi + a0
zi = a2 xi2 + a1 xi + a0
zi = a2 xi2 + a1 xi + a0
is least.
zi = a2 xi2 + a1 xi + a0
is least.
reglin
reglin
is minimized.
reglin
is minimized.
[a1, a0, sig] = reglin(x,z)
sig : standard deviation of the residual.
reglin
is minimized.
[a1, a0, sig] = reglin(x,z)
sig : standard deviation of the residual.
(Smaller sig means better fit.)
Exercise plan
Exercise plan
Exercise plan
Random numbers
Random numbers
Random numbers
Random numbers
Exercises:
Exercises:
Exercises:
Exercises:
y = a1 x + a2 x 2 + a0
Suppose a0a = 3; a1a = 6; a2a = 2; (actual)
y = a1 x + a2 x 2 + a0
Suppose a0a = 3; a1a = 6; a2a = 2; (actual)
x = 1:10; dev = 0.5;
y = a1 x + a2 x 2 + a0
Suppose a0a = 3; a1a = 6; a2a = 2; (actual)
x = 1:10; dev = 0.5;
y = a1a∗x + a2a∗x•ˆ2 + a0a + dev∗(rand(x)-0.5)
x = 1:10; x2 = x.ˆ2;
X=[x;x2];
reglin(X,y)
Spoken tutorial?
Spoken tutorial?
Spoken tutorial?
Spoken tutorial?
Spoken tutorial?