Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Polinomial Regression
Multiple Linear Regression
Diktat Kuliah
(Dec 8 , 2006)
0.12
Tide (mGal)
0.08
0.04
Tim e
0
6:00
8:24
10:48
13:12
15:36
-0.04
-0.08
18:00
Food Available, S
m m max
S
Ks S
T ( o C)
0
10
20
30
z (m )
10
Epilimnion
Thermocline
15
20
25
30
Hypolimnion
Interpolation of data
What is kinematic
viscosity at 7.5 C?
v, 10-2 cm 2/s
2
1.5
1
0.5
0
0
10
20
T(oC)
30
T (oC)
0
4
8
12
16
20
24
v, 10-2 (cm2/s)
1.7923
1.5615
1.3874
1.2396
1.1168
1.0105
0.9186
f(x)
x
We want to find the best fit of a curve through the data.
Here we see :
a) Least squares fit
b) Linear interpolation
Polynomial Regression
Multiple Regression
Nonlinear regression
Interpolation
Lagrange polynomial
Splines
Aproximation
the
fundamental
and
interpolation
difference
and
between
realize
why
Linear Regression
Polynomial Regression
???
Linear
y = ao + a1x + e
fit equations
i 1
i 1
Sr e2i yi a o a1xi
f(x)
yi a o a1xi
x
Data Observasi : (x1,y1), (x2, y2).....(xn, yn)
Persamaan Regresi Linear : y = ao + a1x + e
Sr
2 yi ao a1xi
a o
Sr
2 yi ao a1xi xi
a1
i 1
i 1
Sr e2i yi a o a1xi
0 yi ao a1xi
0 yi xi ao xi a1xi2
0 yi xi ao xi a1xi2
Note:
nao
i i
1 i
o i
2
1 i
nao xi a1 yi
xa x a x y
i
a1
2
i 1
i i
n xi yi xi y i
n x xi
ao y a1x
2
i
nao xi a1 yi
xi ao
xi2 a1 xi yi
xi n ao xi xi a1
xi
xi yi
n ao n xi2 a1
a1
xi
n xi yi
n xi2
xi yi n xi yi
a1
a1
a0
yi
xi yi n xi yi
2
xi
n xi2
n xi yi xi yi
n xi2
x
i
xi a1
y a1 x
n
a1
n xi yi xi y i
2
n xi
ao y a1 x
x
i
y = ao + a1x
Error
Recall:
f(x)
i 1
i 1
Sr e2i yi a o a1xi
S t yi y
St
sy
n 1
Error
Introduce a term to measure the standard error of the
estimate:
Sr
sy
n2
x
Coefficient of determination r2 :
St Sr
r
St
2
Error
St Sr
r
St
2
Error
S t yi y
St
sy
n 1
standard deviation
about the mean
i 1
i 1
Sr e2i yi a o a1xi
Sr
sy
n2
x
St Sr
r
St
Coefficient of
determination
Example
Determine the linear equation and R2 value for
the following data
y
9
7
5
4
3
1
0
8
7
f(x)
x
0
1
2
3
4
5
6
10
9
6
5
4
3
2
1
0
0
4
x
Data 1
10
8.04
8
6.95
13
7.58
9
8.81
11
8.33
14
9.96
6
7.24
4
4.26
12
10.84
7
4.82
5
5.68
Data 2
10
9.14
8
8.14
13
8.74
9
8.77
11
9.26
14
8.10
6
6.13
4
3.10
12
9.13
7
7.26
5
4.74
Data 3
10
7.46
8
6.77
13
12.74
9
7.11
11
7.81
14
8.84
6
6.08
4
5.39
12
8.15
7
6.42
5
5.73
Data 4
8
6.58
8
5.76
8
7.71
8
8.84
8
8.47
8
7.04
8
5.25
19
12.50
8
5.56
8
7.91
8
6.89
12
12
10
10
8
y
14
14
y = 0.5001x + 3.0001
R2 = 0.6665
y = 0.5x + 3.0009
R2 = 0.6662
0
0
10
15
10
15
14
14
12
12
10
10
8
y
y = 0.4997x + 3.0025
2
y = 0.4999x + 3.0017
R2 = 0.6667
R = 0.6663
0
0
10
x
15
10
x
15
20
f(x)
EXPONENTIAL
EQUATIONS
Linearize
P Po e
t
ln P
intercept = ln P0
slope = r
t
why?
rt
P P0e rt
ln P ln P0e rt
ln P0 lne rt
y = ao + a1x
ln P0 rt
lnP
intercept = ln Po
slope = r
P P0e rt
ln P ln P0e rt
ln P0 lne
ln P0 rt
ln P
regression.
rt
intercept = ln P0
slope = r
t
POWER EQUATIONS
Q cH
Here we linearize
the equation by
taking the log of
H and Q data.
What is the resulting
intercept and slope?
log H
Q cH a
So how do we get
c and a from
performing regression
on the log H vs log Q
data?
From : y = ao + a1x
log Q logcH a
log c log H
log c a log H
ao = log c
c = 10ao
log Q
a1 = a
slope = a
log H
intercept = log c
SATURATION-GROWTH
RATE EQUATION
m m max
S
1/m
slope = Ks/mmax
intercept = 1/mmax
1/ S
S
Ks S
Residual Error
Linear :
y = ao + a1x
2
2
Sr e yi ymodel yi ao a1 xi
2
Power :
y = axb
2
b 2
Sr e yi ymodel yi ax
2
Exponential :
y=aexb
Sr e yi ymodel yi ae
2
xi b 2
Example
X
Ymodel
0.7
0.8
1.7
1.6
3.3
3.1
7.3
6.2
10.9
12.1
22.7
23.9
y = 0.407e
0.679x
y-direction
f(x)
x-direction
Latihan
Polynomial Regression
One of the reasons you were presented with the
theory behind linear regression was to allow you the
insight behind similar procedures for higher order
polynomials
y = a0 + a1x
Polynomial Regression
Sr yi a o a1xi a x ...... a x
2
2 i
m 2
m i
Sr
2
2 xi yi ao a1xi a2 xi2 ..... amxim
a2
Polynomial Regression
2. These equations are set to zero to minimize Sr, i.e.
minimize the error.
m 2
xi yi
2
Polynomial Regression
n a o x i a1 x i2 a 2 yi
x a x a x a x y
x a x a x a x y
i
2
i
xi
xi2
2
i
3
i
xi
2
xi
2
xi
3
xi
3
xi
4
xi
3
i
4
i
ao
a1
a
2
2
i
yi
xi yi
2
xi yi
y = ao + a1x1 + a2x2
y = ao + a1x1 + a2x2 + e
x1i
x2i
x
x
x x
1i
2
1i
1i 2 i
x
x x
x
a0 yi
1i 2 i a1 x1i yi
2
x y
2 i a 2
2i i
2i
[A] and {c }are clearly based on data given for x1, x2 and y
to solve for the unknowns in {x}.
Interpolation
General formula for an n-th order polynomial
y = a0 + a1x + a2x2 +....amxm
Example: y = a0 + a1x
1st order
Interpolation
We will explore two mathematical methods well suited
for computer implementation
Temperature, C
Density, kg/m3
999.9
1000.0
10
999.7
15
999.1
20
998.2
998.2
999.1
15
17
20 15
17 15 T
20
Solve for
20 15
20 17
f x1 f x0
f1 x f xo
x x0
x1 x0
Alternate interpretation
f1 x a0 a1 x x0
the intercept is f(x0)
Newtons
Linear
Interpolation
true solution
f(x)
f1 x a0 a1 x x0
f 2 x b0 b1 x x0 b2 x x0 x x1
Prove that this a 2nd order polynomial of
the form:
f x a0 a1x a2 x
f 2 x b0 b1 x x0 b2 x x0 x x1
f 2 x b0 b1x b1x0 b2 x 2 b2 x0 x1 b2 xx0 b2 xx1
Collect terms and recognize that:
a0 b0 b1 x0 b2 x0 x1
a1 b1 b2 x0 b2 x1
a2 b2
f x a0 a1x a2 x 2
x2, f(x2)
x, f(x)
Procedure for
f(x)
Quadratic
x1, f(x1)
Interpolation
x0, f(x0)
b0 f x0
f x1 f x0
b1
x1 x0
f x2 f x1 f x1 f x0
x2 x1
x1 x0
b2
x2 x0
f x1 f x0
b1
x1 x0
f x2 f x1 f x1 f x0
x2 x1
x1 x0
b2
x2 x0
f 2 x b0 b1 x x0 b2 x x0 x x1
Example
Include 10 degrees in
your calculation of the
density at 17 degrees.
1000.5
Temperature, C
Density, kg/m3
999.5
999.9
999
1000.0
998.5
10
999.7
998
15
999.1
20
998.2
Density
1000
10
15
Temp
20
25
Example
Include 10 degrees in
your calculation of the
density at 17 degrees
f 2 x b0 b1 x x0 b2 x x0 x x1
b0 f x0
f x1 f x0
b1
x1 x0
f x2 f x1 f x1 f x0
x2 x1
x1 x0
b2
x2 x0
Temperature, C
Density, kg/m
999.9
1000.0
10
999.7
15
999.1
20
998.2
Solution
b0 f x0 999.7
f x1 f x0 999.1 999.7
b1
0.12
x1 x0
15 10
f x2 f x1 f x1 f x0
x2 x1
x1 x0
b2
x2 x0
998.2 999.1
0.12
20 15
0.006
20 10
Solution
f 2 17 b0 b1 x x0 b2 x x0 x x1
b0 b1 17 10 b2 17 1017 15
f 2 17 998.776
f1 17 998.74
f3 x b0 b1 x x0 b2 x x0 x x1
b3 x x0 x x1 x x2
b0 f x0
b1
f x1 f x0
x1 x0
f x2 f x1
b2
b1
x2 x1
f x1 f x0
x2 x0
x1 x0
b2
f x3 f x2 f x2 f x1
f x2 f x1 f x1 f x0
x
x
x
x
x
x
x
3
2
2
1
2
1
1
0
x3 x1
x2 x0
b3
x3 x0
f 4 x b0 b1 x x0 b2 x x0 x x1
b3 x x0 x x1 x x2
b4 x x0 x x1 x x2 x x3
b0 f x0 f x0
f x1 f x0
b1 f x1 , x0
x1 x0
b1
f x2 f x1 f x1 f x0
x
x1 x0
f x2 , x1 f x1 , x0
2
1
b2 f x2 , x1 , x0
x2 x0
x2 x0
b3 f x3 , x2 , x1 , x0
f x3 , x2 , x1 f x2 , x1 , x0
x3 x0
f x3 , x2 f x2 , x1 f x2 , x1 f x1 , x0
x3 x1
x2 x0
x3 x0
b2
f x3 f x2 f x2 f x1 f x2 f x1 f x1 f x0
x
x
x
x
x
x1 x0
3
2
2
1
2
1
x3 x1
x2 x0
x3 x0
b4 f x4 , x3 , x2 , x1 , x0
f x4 , x3 , x2 , x1 f x3 , x2 , x1 , x0
x4 x0
f x4 , x3 , x2 f x3 , x2 , x1 f x3 , x2 , x1 f x2 , x1 , x0
x4 x1
x3 x0
x4 x0
f x4 , x3 f x3 , x2 f x3 , x2 f x2 , x1 f x3 , x2 f x2 , x1 f x2 , x1 f x1 , x0
x4 x2
x3 x1
x3 x1
x2 x0
x4 x1
x3 x0
x4 x0
b3
f x4 f x3 f x3 f x2 f x x , x
f x f x2 f x2 f x1 f x2 f x1 f x1 f x0
3
3 2 f x , x 3
2 1
x
x
x
x3 x2
x2 x1
x2 x1
x1 x0
4
3
3
2
x4 x2
x3 x1
x3 x1
x2 x0
x4 x1
x3 x0
x4 x0
f n x Li x f xi
i0
Li x
j0
ji
x xj
xi x j
f n x Li x f xi
i 0
Li x
j 0
j i
x xj
xi x j
x x1
x x0
f1
f x0
f x1
x0 x1
x1 x0
Linear
Lagrange
Interpolating
Polynomial
fn x
n
Li
i 0
x f xi
Li x
n x xj
j 0 xi x j
j i
f1
x x0
x x1
f x0
f x1
x0 x1
x1 x0
x x0 x x2
x x0 x x1
x x1 x x2
f2
f x0
f x1
f x2
x0 x1 x0 x2
x1 x0 x1 x2
x2 x0 x2 x1
x x0
x x1
f1
f x0
f x1
x0 x1
x1 x0
x x0 x x2
x x0 x x1
x x1 x x2
f2
f x0
f x1
f x2
x0 x1 x0 x2
x1 x0 x1 x2
x2 x0 x2 x1
f n x Li x f xi
i 0
n
Li x
j 0
j i
x xj
xi x j
x x1 x x2 x x3
f3
f x0
x0 x1 x0 x2 x0 x3
.......
f n x Li x f xi
i 0
n
Li x
j 0
j i
x xj
xi x j
x x1 x x2 x x3
f3
f x0
x0 x1 x0 x2 x0 x3
x x0 x x2 x x3
f x1
x1 x0 x1 x2 x1 x3
.......
f n x Li x f xi
i 0
n
Li x
j 0
j i
x xj
xi x j
x x1 x x2 x x3
f3
f x0
x0 x1 x0 x2 x0 x3
x x0 x x2 x x3
f x1
x1 x0 x1 x2 x1 x3
.......
Note:
x1 is not being
subtracted from the
constant term x or
xi = x1 in the
numerator or the
denominator j= 1
f n x Li x f xi
i 0
n
Li x
j 0
j i
x xj
xi x j
x x1 x x2 x x3
f3
f x0
x0 x1 x0 x2 x0 x3
x x0 x x2 x x3
f x1
x1 x0 x1 x2 x1 x3
x x0 x x1 x x3
f x2
x2 x0 x2 x1 x2 x3
......
Note:
x2 is not being
subtracted from
the constant term
x or xi = x2 in the
numerator or the
denominator j= 2
f n x Li x f xi
i 0
n
Li x
j 0
j i
x xj
xi x j
x x1 x x2 x x3
f3
f x0
x0 x1 x0 x2 x0 x3
x x0 x x2 x x3
f x1
x1 x0 x1 x2 x1 x3
x x0 x x1 x x3
f x2
x2 x0 x2 x1 x2 x3
x x0 x x1 x x2
f x3
x3 x0 x3 x1 x3 x2
Note:
x3 is not being
subtracted from
the constant term
x or xi = x3 in the
numerator or the
denominator j= 3
Example
1000.5
Density
1000
Temperature, C
Density, kg/m3
999
999.9
998.5
1000.0
10
999.7
15
999.1
20
998.2
999.5
998
0
10
15
Temp
20
25
Coefficients of an Interpolating
Polynomial
f n x b0 b1 x x0 ....bn x x0 x x1 x xn 1
f x0 a 0 a1x0 a 2 x02
f x1 a 0 a1x1 a 2 x12
f x2 a 0 a1x2 a 2 x32
This is a 2nd order polynomial.
We need three data points.
Plug the value of xi and f(xi)
directly into equations.
This gives three simultaneous equations
Example
1000.5
Density
1000
Temperature, C
Density, kg/m3
999
999.9
998.5
1000.0
10
999.7
15
999.1
20
998.2
999.5
998
0
10
20
Temp
30
Spline Interpolation
Our previous approach was to derive an nth order
polynomial for n+1 data points.
drafting
drafting
drafting
drafting
Linear Splines
f x f x0 m0 x x0
f x f x1 m1 x x1
x0 x x1
x1 x x2
f x f xn 1 mn 1 x xn 1
where
f xi 1 f xi
mi
xi 1 xi
xn 1 x x n
Quadratic Spline
a1 x 2 b1 x c1
Quadratic Spline
a2 x 2 b2 x c2
Quadratic Spline
a3 x 2 b3 x c3
Quadratic Spline
a4 x 2 b4 x c4
Quadratic Spline
a1 x 2 b1 x c1
a2 x 2 b2 x c2
a4 x 2 b4 x c4
a3 x 2 b3 x c3
16
14
12
10
8
6
4
2
0
0
100
200
300
400
500
15
42
128
317
433
ai 1xi2 1 bi 1xi 1 ci 1 f xi 1
14.6
10.7
4.8
1.7
0.3
ai xi2 1 bi xi 1 ci f xi 1
16
14
12
10
8
6
4
2
0
0
100
200
300
400
500
ai 1xi2 1 bi 1xi 1 ci 1 f xi 1
Solution
ai xi2 1 bi xi 1 ci f xi 1
(42)2 a2 + 42 b2 + c2 = 10.7
16
14
12
10
8
6
4
2
0
0
100
200
300
400
500
15
42
128
317
433
14.6
10.7
4.8
1.7
0.3
ai 1xi2 1 bi 1xi 1 ci 1 f xi 1
Solution
ai xi2 1 bi xi 1 ci f xi 1
(42)2 a2 + 42 b2 + c2 = 10.7
16
14
12
10
8
6
4
2
0
0
100
200
300
400
500
15
42
128
317
433
14.6
10.7
4.8
1.7
0.3
ai 1xi2 1 bi 1xi 1 ci 1 f xi 1
Solution
ai xi2 1 bi xi 1 ci f xi 1
(42)2 a2 + 42 b2 + c2 = 10.7
16,384 a3 + 128 b3 + c3 = 4.8
16
14
12
10
8
6
4
2
0
0
100
200
300
400
500
15
42
128
317
433
14.6
10.7
4.8
1.7
0.3
ai 1xi2 1 bi 1xi 1 ci 1 f xi 1
Solution
ai xi2 1 bi xi 1 ci f xi 1
(42)2 a2 + 42 b2 + c2 = 10.7
16,384 a3 + 128 b3 + c3 = 4.8
16
14
12
10
8
6
4
2
0
0
100
200
300
400
500
15
42
128
317
433
14.6
10.7
4.8
1.7
0.3
15
42
128
317
433
Solution
(42)2 a2 + 42 b2 + c2 = 10.7
16
14
12
10
8
6
4
2
0
0
100
200
300
400
500
14.6
10.7
4.8
1.7
0.3
15
42
128
317
433
Solution
(42)2 a2 + 42 b2 + c2 = 10.7
16
14
14.6
10.7
4.8
1.7
0.3
12
10
8
6
4
2
0
0
100
200
300
400
500
Solution
15
42
128
317
433
(15)2a1 + 15 b1 + c1 = 14.6
14.6
10.7
4.8
1.7
0.3
16
14
12
10
8
6
4
2
0
0
100
200
300
400
500
15
42
128
317
433
Solution
2ai 1xi 1 bi 1 2ai xi 1 b
14.6
10.7
4.8
1.7
0.3
14
12
10
8
6
4
2
0
0
100
200
300
400
500
15
42
128
317
433
Solution
....end of problem
14.6
10.7
4.8
1.7
0.3
Splines
To ensure that the mth derivatives are continuous at the
knots, a spline of at least m+1 order must be used
Quadratic Spline
ai 1xi21 bi 1xi 1 ci 1 f xi 1
ai xi21 bi xi 1 ci f xi 1
Quadratic Spline
ai 1xi2 1 bi 1xi 1 ci 1 f xi 1
ai xi2 1 bi xi 1 ci f xi 1
This occurs between i = 2, n
Using the interior knots (n-1) this will provide 2n -2 equations.
Quadratic Spline
2. The first and last functions must pass
through
a1x02 b1x0 c1 f x0
an xn2 bn xn cn f xn
We now have 2n - 2 +2 = 2n equations.
Quadratic Spline
3. The first derivative at the interior knots must
be equal.
Quadratic Spline
4. Unless we have some additional information
regarding the functions or their derivatives, we
must make an arbitrary choice in order to
successfully compute the constants.
5. Assume the second derivative is zero at the
first point. The visual interpretation of this
condition is that the first two points will be
connected by a straight line.
a1 = 0
Cubic Splines
Third order polynomial
Need n+1 = 3+1 = 4 intervals
f i x ai x 3 bi x 2 ci x di
Cubic Splines
The function values must be equal at the
interior knots (2n -2)
SPECIAL NOTE
Quadratic Spline