Upload
rolando-masterman
View
224
Download
2
Tags:
Embed Size (px)
Citation preview
Numeriska beräkningar i Naturvetenskap och Teknik
Today’s topic:
Approximations
Least square method
Interpolations
Fit of polynomials
Splines
Numeriska beräkningar i Naturvetenskap och Teknik
An exemple
80
70
60
50
40
30
20
T
83.54
48.53
76.51
71.50
60.50
19.50
56.48
)(TfL
T
L
Modell
TccTfL 10)(
20 40 60 80
48
50
52
54
Why do the measured values deviate from the mode if the measurement is correct?
Numeriska beräkningar i Naturvetenskap och Teknik
How determine the ‘best’ straight line?
T
L
Model bTaTfL )(
20 40 60 80
48
50
52
54
Numeriska beräkningar i Naturvetenskap och Teknik
Distance between line and measurements points...
T
L
20 40 60 80
48
50
52
54
1d
2d3d
4d5d
6d
7d
Numeriska beräkningar i Naturvetenskap och Teknik
How to define the distance between the line and the measurement points?
idLargest deviation at minimum Approximation in maximum norm
2id
Sum of deviations squared as small as possible Approximation in Euclidian norm
Easier to calculate!
Norm
Numeriska beräkningar i Naturvetenskap och Teknik
Matrix formulation: An example
3
2
0
1
3
x
9.0
6.0
6.0
9.0
1.2
)(
xf
x
f
xccxf 10)(
9.03
6.02
6.0
9.0
1.23
10
10
0
10
10
cc
cc
c
cc
cc
9.0
6.0
6.0
9.0
1.2
1
1
1
1
1
3
2
0
1
3
1
0
c
c
fAc with
More equations than unknowns!
Numeriska beräkningar i Naturvetenskap och Teknik
Matrix formulation: An exampe
9.0
6.0
6.0
9.0
1.2
1
1
1
1
1
3
2
0
1
3
1
0
c
c
fAAcA TT
3
1
1
1
0
1
2
1
3
1
1
1
1
1
1
3
2
0
1
3
1
0
c
c
3
1
1
1
0
1
2
1
3
1
9.0
6.0
6.0
9.0
1.2
Numeriska beräkningar i Naturvetenskap och Teknik
Matrix formulation: An example
fAAcA TT
23 1
1 5
1
0
c
c
11.1
1.2
1
0
c
c
0.505
521.0
xxf 505.0521.0)(
Numeriska beräkningar i Naturvetenskap och Teknik
Matrix formulation: An example
xxf 505.0521.0)(
Numeriska beräkningar i Naturvetenskap och Teknik
General Statement of the Problem:
Depending on the model, the measurement data can of course be described by other expressions than the straight line.
In general terms one seeks a function f* that approximates f’s
given values as good as possible in euclidian norm. Specifically, above we looked for a solution expressed as
xccxf 10)(
but we could as well have looked for a solution given by another function (possibly then for different data)
)cos()sin()( 10 xcxcxf
etc...
Numeriska beräkningar i Naturvetenskap och Teknik
Generally one can thus write:
nncccxf ...)( 1100
f(x) is in other words a linear combination of given functions
n ,...,, 10 Where the coefficients
nccc ,...,, 10 are sought
One can in accordande with a vector space look at it so that
n ,...,, 10
Spans a function space (a space of this kind whichfulfills certain conditions is called a Hilbert space, cmp. quant.
mech)
Numeriska beräkningar i Naturvetenskap och Teknik
In the case of the straight line we have
x
1
0 1
In a geometrical comparision these two functions, which can
be seen as two vectors in the function space, span a plane U:
10
x1
*f
”vector” 0
”vector” 1
Approximating function
f sought function
The smallest distance from the plane is given by a normal. The smallest
deviation between f* och f is for f*-f orthogonal to the plane U!
Numeriska beräkningar i Naturvetenskap och Teknik
Normal equations
Since we are interested in fitting m measured values weleave the picture of the continuous function space and view f(x) as an m-dimensional vector with values:
)(
...
)(
)(
2
1
mxf
xf
xf
)(0
)2(0
)1(0
...m
)(1
)2(1
)1(1
...m
That should be expressed by
and0 1f
For the straight line:
1
...
1
1
0
mx
x
x
...1
1
1
Numeriska beräkningar i Naturvetenskap och Teknik
The orthogonality condition now gives the equations:
0),*(
0),*(
1
0
ff
ff1100* ccf where
0),(
0),(
11100
01100
fcc
fcc
0),(),(),
0),(),(),(
111110(0
00111000
fcc
fcc
€
c0(ϕ 0,ϕ 0) + c1(1ϕ1,ϕ 0) = ( f ,ϕ 0)
c0(ϕ 0,ϕ1) + c1(ϕ1,ϕ1) = ( f ,ϕ1)
the equations for the normal:
Which gives
Numeriska beräkningar i Naturvetenskap och Teknik
),(),(),(
),(),(),(
1111100
0011000
fcc
fcc
The equations for the normal :
),( ),(
),( ),(
1110
0100
1
0
c
c
),(
),(
1
0
f
f
1
0
. .
. .
. .
. .
. .
. .
10 1
0
c
c
1
0
.
.
.
.
.
.
f
Numeriska beräkningar i Naturvetenskap och Teknik
Back to the exemple:
3
2
0
1
3
x
9.0
6.0
6.0
9.0
1.2
)(
xf
xccxf 10)(
1
1
1
1
10
3
2
0
1
3
)(1
x
Model:
3
2
0
1
3
3 2 0 1- 3 1 1 1 1 1
1
1
1
1
1
1
0
c
c
9.0
6.0
6.0
9.0
1.2
1 1 1 1 1 3 2 0 1- 3
TA A TAc f
Data:
Numeriska beräkningar i Naturvetenskap och Teknik
Conclusion:
2||*|| ff
the minimum of
ff * is orthogonal to the basis vectors
n ...,, 3,210
Assuming the model
nncccccf ...* 33221100
Given data f
is obtained when
The coefficienterna c1, c2, c3, cn are determined from
Numeriska beräkningar i Naturvetenskap och Teknik
The equations
),(),(...),(),(
...
),( ),(...),(),(
),(),(...),(),(
1100
11111100
00011000
nnnnnn
nn
nn
fccc
fccc
fccc
or
fAAcA TT
Where the colomuns in A are:
n ...,, 3,210
Numeriska beräkningar i Naturvetenskap och Teknik
Note 1:
The func’s Have to be linearly independent
n ...,, 3,210
(cmp vectors in a vector space)
Note 2:
993
994
996
997
999
x
9.0
6.0
6.0
9.0
1.2
)(
xf
Assume our problem would have been (x koord -996)
4958111 4979
4979- 5
1
0
c
c
2102.7
1.2
23 1
1 5
1
0
c
c
11.1
1.2
cmp to
Numeriska beräkningar i Naturvetenskap och Teknik
Gauss’ elimination method:
1902568116
4464278
101694
2432
4321
4321
4321
4321
xxxx
xxxx
xxxx
xxxx
190256 81 16 1
44 64 27 8 1
10 16 9 4 1
2 4 3 2 1
Numeriska beräkningar i Naturvetenskap och Teknik
Gauss’ elimination method:
190256 81 16 1
44 64 27 8 1
10 16 9 4 1
2 4 3 2 1
188 | 252 78 14 0
42 | 60 24 6 0
8 | 12 6 2 0
2 | 4 3 2 1
132 | 168 36 0 0
18 | 24 6 0 0
8 | 12 6 2 0
2 | 4 3 2 1
24 | 24 0 0 0
18 | 24 6 0 0
8 | 12 6 2 0
2 | 4 3 2 1
1
1
1
7 1
3 1
1
6 7 1
3 1
1
Numeriska beräkningar i Naturvetenskap och Teknik
Error sources
1. Mätdata, Ef
0x 1x
fE
f
x
Numeriska beräkningar i Naturvetenskap och Teknik
Error sources
2. Truncation error
0f
1f
ph
0x 1xx5.99 1.5
1.80
0.44 4.19 1.0
0.11 1.36
0.33 2.83 0.5
1.03
1.80 0
f f f f 32 x
These would be zero for a first degree polynomial
h
Numeriska beräkningar i Naturvetenskap och Teknik
The approximation to data assumes to pass through the data points,
i.e. one assumes the errors are small.
)()( 001
010 xx
xx
fffxf
000 )()( fpfphxfxf 0f
1f
Linear interpolation
Alt for equidistant data
ph
0x 1xh
5.99 1.5
1.80
0.44 4.19 1.0
0.11 1.36
0.33 2.83 0.5
1.03
1.80 0
f f f f 32 x
Interpolation
Numeriska beräkningar i Naturvetenskap och Teknik
Quadratic interpolation
Ansatz
))(()()( 1020102 xxxxcxxccxQ
00 ffxx 00 cf
11 ffxx )( 01101 xxccf h
f
xx
ffc
)( 01
011
22 ffxx ))(()( 1202202102 xxxxcxxccf
))((
)(
)())(( 1202
02
01
01
1202
022 xxxx
xx
xx
ff
xxxx
ffc
1
2
3
Numeriska beräkningar i Naturvetenskap och Teknik
Quadratic interpolation
2
2
2012
20102
30102
1202
02
01
01
1202
022
22
2
2
22
2
2)()(
))((
)(
)())((
h
f
h
fff
h
ffff
h
hffhff
xxxx
xx
xx
ff
xxxx
ffc
3
h
fppfpfhxxp
h
ffpf
xxxxh
fxx
h
ffxQ
2)1()(
2
))((2
)()(
2
00
2
0
102
2
002
Numeriska beräkningar i Naturvetenskap och Teknik
Quadratic interpolation
Newton’s ansatz
)(...))((
...
))((
)(
)(
110
102
01
0
mm
m
xxxxxxc
xxxxc
xxc
cxQ
mf
f
f
f
...2
1
0
Uniqueness: There is only one polynomial of order m that passes
through m+1 points.
Numeriska beräkningar i Naturvetenskap och Teknik
Error interpolation
)()()( xfelxQxf
))...()(()!1(
)(
)()()(
10
)1(
m
m
m
xxxxxxm
f
xQxfxfel
)1(2
|)(|)1(
2
|)(||))((|
2
|)(|
|)()(|)(''2''
10
''
1
ppfh
hpphf
xxxxf
xQxfxfel
Linear interpolation
81/4)1/2p01-(2p )1(
2
22 fpp
f
Numeriska beräkningar i Naturvetenskap och Teknik
Exemple
Interpolation of polynomial of order 4,8,16 in equidistant points
)91/()( xexf x
Fit of polynomial of order 6 to 9 equidistant points
Numeriska beräkningar i Naturvetenskap och Teknik
4th order 8th order
16th order 6th order in 9
points
Numeriska beräkningar i Naturvetenskap och Teknik
Runge’s phenomenon
Interpolation in equidistant points by a polynomal of high order tends to reproduce a curve better in the central parts of the interval but gives considerable oscillations close to the end-points of the interval!
Chebychev polynomials and Chebychev abscissa
If one can select the points in which data is known (this can be
hard if the measurement values are already given… ) then the data
points should be closer close to the end-points of the interval.
An optimal choice is given by the zeros of the Chebychevpolynomial of order m which minimizes the residue above.
)21
12cos(
m
ixi
Numeriska beräkningar i Naturvetenskap och Teknik
Splines
An alternative is to use a polynomial piece wise between the points. One
can e.g. set the condition that the function’s values, its derivative and
second derivative is equal in the end points of each short interval for
polynomials that meet in these points. This approach gives so-called
cubic splines. In the extreme end-points one can e.g. demand the curve to be straight.
x
f
Numeriska beräkningar i Naturvetenskap och Teknik
Cubic splines
iiiiii
iii
iiiii
dcbayY
ayY
tdtctbatY
1
32
)1(
)0(
)(
iiiii
iii
iiii
dcbDY
bDY
tdtcbtY
32)1('
)0('
32)('
1
2
11
11
)(2
2)(3
iiiii
iiiii
ii
ii
DDyyd
DDyyc
Db
ya
Function Derivative
Second derivative
tdctY iii 62)(''
]1,0[:t
Numeriska beräkningar i Naturvetenskap och Teknik
Insertion:
311
211
])(2[
]2)(3[)(
tDDyy
tDDyytDytY
iiii
iiiiiii
211
11
])(2[3
]2)(3[2)('
tDDyy
tDDyyDtY
iiii
iiiiii
tDDyyDDyytY iiiiiiiii ])(2[6]2)(3[2)('' 1111
Function
Derivative
Second derivative
Numeriska beräkningar i Naturvetenskap och Teknik
The condtions
€
Yi(0) = y iYi−1(1) = y iY 'i−1 (1) =Y 'i (0)
Y ' 'i−1 (1) =Y ' 'i (0)
€
Y ' '0 (0) = 0
Y ' 'n−1 (1) = 0and
give
Numeriska beräkningar i Naturvetenskap och Teknik
1 2
1 4 1
1 4 1
1 4 1
1 2
....
n
1-n
2
1
0
D
D
D
D
D
)(3
)(3
....
)3(y
)3(y
)3(y
1
2
03
02
01
nn
nn
yy
yy
y
y
y
the following system in matrix form:
Easy to solve! Try out MATLABs spline function on your own!