Professional Documents
Culture Documents
MS3200 Anum Part 2
MS3200 Anum Part 2
MS
3200 Numerical Analysis
Part 2
8. Curve Fitting
8.1
Introduction
Application:
Trend Analysis
Hypothesis testing
Source of Data:
Experimental data
Discrete numerical solution
57
Rac 2015
Interpolation (polynomial)
Regression (linear)
58
Interpolation
Regression
59
Rac 2015
8.2
Interpolation
8.2.1 Newtons Divided-Difference
Making
g use of a Polynomial
y
form to fit a curve Polynomial
y
interpolation:
f1 x f x0 f x1 f x0
x x0
x1 x0
f1 x f x0
f x1 f x0
x x0
x1 x0
61
Rac 2015
b0 f x 0
b1 f x1 , x 0
b2 f x 2 , x1 , x 0
bn f x n , x n 1 , , x1 , x 0
where
f xi , x j
f xi f x j
xi x j
f x n , x n 1 , , x1 , x 0
f x n , x n 1 , , x1 f x n 1 , , x1 , x 0
x n x0
62
f n x f x 0 f x1 , x 0 x x 0 f x 2 , x1 , x 0 x x1 x x 0
f x n , x n 1 , , x1 , x 0 x x 0 x x1 x x n 1
63
Rac 2015
Algorithm
f( i) = yi
f(x
f x i , x j
f xi f x j
xi x j
First stage
-Second
S
d stage
t
-yint2 f2(x)
-Error
64
order
Data points
required
f(x)
t (%)
1st (linear)
0.4621
33.3
2nd
(quadratic)
0.5658
18.4
3rd
(cubic)
0.6288
9.3
65
Rac 2015
8.2.3 Lagrange
Form
i 0
j 0
j i
f n x Li x f xi ; Li x
x xj
xi x j
Rationale:
Each term of Li(xi) is 1 at x = xi and zero at all other
datapoints takes the value of f(xi) at data point xi.
Therefore, the curve passes through each data points A
characteristic
h
t i ti off IInterpolation
t
l ti
66
f 3 x Li x f xi L0 f x0 L1 f x1 L2 f x2 L3 f x3
i 0
x x1 x x2 x x3
x x0 x x2 x x3
f x0
f x1
f 3 x
x
x
x
x
x
x
2
0
3
0 1 0
x1 x0 x1 x2 x1 x3
x x0 x x1 x x3
x x0 x x1 x x2
f x2
f x3
x2 x0 x2 x1 x2 x3
x3 x0 x3 x1 x3 x2
67
Rac 2015
f n x a0 a1 x a2 x 2 ... an x n
Steps:
Build system of linear equations in form of matrix problem
Solve using ordinary Gauss/Gauss-Jordan/etc..
a0 a1 x0 a2 x0 ... an x0 f x0
1 x0
1 x1
1
1
1 x
n
a0 a1 x1 a2 x1 ... an x1 f x1
n
a0 a1 xn a2 xn ... an xn f xn
n
x0
2
x1
xn
n
x0 a0 f x0
n
x1 a1 f x1
a2 f x2
n
xn an f xn
68
x = ??
Mostly unevenly-spaced
Sample Problem!!: Find x, to give f(x) = 0.3
69
Rac 2015
Alternative method:
Interpolating polynomial, then root of polynomial
Steps:
b a0 a1 x a2 x 2 ... an x n
a0 ' a1 x a2 x 2 ... an x n 0 where : a0 ' a0 b
Root finding problem
70
Segmen I
Segmen II
Segmen III
...
1
Principles:
1. At first and end points, the
value of functions =
datapoints
f 1 x0 y0
f m xn y n
xi
2 At interior nots
2.
nots, the value
of adjacent functions must
be equal
f
jth Segment
ith data
xi
j 1
xi 1
71
Rac 2015
Segmen I
Segmen II
Segmen III
Principles:
3. At interior nots, slope of
adjacent functions must be
equal
...
d
f
dx
xi
xi
d
f
dx
j 1
xi 1
d2 I
f x0 0
dx 2
jth Segment
ith data
72
xi a j xi 2 b j xi c j
9a1 b1 9a2 b2 0
14a2 b2 14a3 b3 0
a1 0
73
Rac 2015
a1
...
b1
c1
a
2
...
c3
In Matrix form:
f I x x 5.5
3.0 x 4.5
II
III
4.5 x 7.0
7.0 x 9.0
74
Self evaluation
Newtons DD:
f xn , xn 1 , , x1 , x0
f x2 , x1 , x0 ...
Lagrange:
f xn , xn 1 , , x1 f xn 1 , , x1 , x0
xn x0
i 0
j 0
j i
f n x Li x f xi ; Li x
f 2 x ...
x xj
xi x j
75
Rac 2015
10
8.3 Regression
8.3.1 Review on Statistics
Consider a p
population
p
of xi containing
g n members.
Mean/average:
n
Standard deviation:
n
sy
y
i 1
1
yi
n i 1
In a normalised form
Coefficient of variance
C OV
n 1
sy
y
atau
sy
2
i
yi
n n 1
76
Normal distribution
77
Rac 2015
11
78
ei yi a 0 a1 xi
min ei
min ei
minmax ei
min ei
79
Rac 2015
12
min ei
min ei
minmax ei
80
yi a0 a1 xi
81
Rac 2015
13
r2
S t yi y
p
the relative discrepancy
p
y between squares
q
This represents
of errors and the spread of the original data, yi .
By taking square root Correlation coefficient (r).
For a perfect fit r = 1, for total non-correlated r = 0.
82
Sr yi a0 a1 xi
S r
2 yi a0 a1 xi 0
a 0
Sr
2 yi a0 a1 xi xi 0
a1
yi xi a0 xi a1 xi 0
y a a x 0
y na a x
i
1 i
a0 xi a1 xi yi xi
Solving
g for the two equations:
q
a1
n xi yi xi yi
n xi2 xi
a 0 y a1 x
Example 17.1
83
Rac 2015
14
84
Linearization:
Know the basic relationship !
Modify
y the equation
q
into linear relationship
p
y a1e b1 x ln y ln a b1 x
y ' a0 a1 x
85
Rac 2015
15
86
S
S
Sr
0; r 0,, r 0
a0
a1
am
x
x
x
x
x
x
x
x
xim
xim1
xim2
n
i
2
i
i
2
i
3
i
2
i
3
i
4
i
a0 y i
a1 xi yi
a2 xi2 yi
xi2m am xim yi
x
x
x
m
i
m 1
i
m2
i
87
Rac 2015
16
y a 0 a1 x1 a 2 x 2
So, the line in the two-dimensional space becomes flatplane in the three-dimensional space.
88
Rac 2015
17
x1i
x2 i
x
x
x x
1i
2
1i
1i
x
x x
x
a0
1i 2 i a1
2
2i a2
2i
2i
yi
x1i yi
x y
2i i
90
Non-linear regression
Fourier Approximation
Response Surface modelling
Metamodelling/Neural Network
91
Rac 2015
18
9. Numerical Integration
9.1 Introduction
Integration is summation with infinitesimally small division
g
is approximation
pp
of the integration
g
Numerical integration
with finite difference
b
I f x dx f n x dx
f n x a0 a1 x a n x n
92
9. Numerical Integration
9.1 Introduction
Basic Approach
Trapezoidal Concept
93
Rac 2015
19
9. Numerical Integration
9.1 Introduction
Multiple-section approach
Higher-order-term approach
94
9. Numerical Integration
9.2 Trapezoidal Rule (Linear)
9.2.1 Basic Rule
b
I f x dx f1 x dx
f b f a
x a
ba
considering the area under the curve
f1 x f a
b a f b f a
2
Error (second degree) :
1
3
Et
f " b a
12
95
Rac 2015
20
9. Numerical Integration
9.2.2 Multiple Section
b a f x 2 f x f x
I
i
n
0
n 1
2n
1
1
1
1
i 1
1
1
1
1
1
1
1
1
1
Et
1 ba
12 n
f "
i
96
9. Numerical Integration
start
Programming realisation
FUNCTION Trapm (h,n,f)
sum = f0
DO I = 1, n-1
sum = sum + 2* fi
ENDDO
sum = sum + fn
Trapm = h*sum/2
END Trapm
end
97
Rac 2015
21
9. Numerical Integration
9.3 Simpsons Rule 1/3 (Quadratic)
9.3.1 Basic Rule
I
f x dx f x dx
2
x0 a ; x 2 b
Et
1 ( 4) b a
f
90
2
b a 5
2880
f ( 4)
98
ba
3n
n 1
n 2
f
x
4
f
x
2
f x j f xn
0
i
i 1, 3, 5 ,...
j 2 , 4 , 6 ,...
1
1
1
1
4
1 (4) b a
Et
f
90
2
1
1
4
1
1
99
Rac 2015
22
f x dx f x dx
3
x0 a ; x2 b
I
ba
f x0 3 f x1 3 f x2 f x3
8
101
Rac 2015
23
102
103
Rac 2015
24
104
105
Rac 2015
25
I I hm
1
I I
hl hm 2 1 m l
for h2 h1 / 2 Oh 4
4
1
I h2 I h1
3
3
16
1
I I m Il
15
15
64
1
I
Im Il
63
63
I
for hm hl / 4 Oh 6
for h2 h1 / 8 Oh8
106
1
4
1
4
I m I l 1.0688 0.1728 1.367467
3
3
3
3
t 16.6%
I
In general form:
I j ,k
4 k 1 I j 1,k 1 I j ,k 1
4
k 1
107
Rac 2015
26
b
?
108
109
Rac 2015
27
I c0 f x0 c1 f x1
y3 x 3
c0 f a c1 f b
1dx 2
c0 c1 1
c0 f a c1 f b
x dx 0
x0
2
x dx 3
x1
c0 f a c1 f b
c0 f a c1 f b
1
0.5773505...
3
1
0.5773505...
3
x dx 0
1
110
b a b a xd
2
b a dx
dx
2
I f x dx I d
a
f x dx
d
1 d
111
Rac 2015
28
I c0 f x0 c1 f x1 cn f xn
With 2*(n+1) coefficients, it could solve system of
polynomial equations for the order up to {2*(n+1)-1}, to
give c0, c1, cn (weights), and x0, x1, xn (function
arguments)
Hence, accurate for polynomial with order up to
{2*(n+1)-1}.
112
113
Rac 2015
29
114
1/ a
f x dx t
a
1/ b
1
2
1
f dt
t
a, b
f x dx h 2 f x f x 2 f x
xn
n2
x0
n 1
115
Rac 2015
30
117
Rac 2015
31
Example:
Falling parachutist
Free vibration
118
f xi 1 f xi f ' xi h
119
Rac 2015
32
120
121
Rac 2015
33
yi01 yi f xi , yi h
The slope at the predictor is calculated and then used to
estimate a better general slope, as a Corrector to the
previous slope (average)
y 'i 1 f xi 1 , yi01
yi 1 yi01 y ' h
y ' y 'i 1
y' i
2
The next predicted result is, then:
0
Or: Predictor : yi 1 yi f xi , yi h
Corrector : yi 1 yi
f xi , yi f xi 1 , yi01
h
2
122
123
Rac 2015
34
yi 1 yi xi , yi , h h
a1k1 a2k2 an kn
n represents the order of approximation: second-order,
thi d d
third-order,
etc
t
k1 f xi , yi
k2 f xi p1h, yi q11k1h
124
125
Rac 2015
35
1
1
yi 1 yi k1 k 2 h
2
2
k1 f xi , yi
(Heun)
k 2 f xi h, yi k1h
yi 1 yi k 2 h
k1 f xi , yi
1
1
k 2 f xi h , yi k1h
2
2
2
1
yi 1 yi k1 k 2 h
3
3
k1 f xi , yi
(Mid-point)
(Ralston)
3
3
k 2 f xi h , yi k1h
4
4
126
1
yi k1 4 k 2 k 3 h
6
1
k1 4 k 2 k3 h
6
k1 f xi , yi
yi 1 yi
1
1
k 2 f xi h , yi k1h
2
2
k 3 f xi h , yi k1h 2 k 2 h
1
k1 2 k 2 2k 3 k 4 h
6
k1 f xi , yi
1
1
k 2 f xi h , yi k1h
2
2
1
1
k 3 f xi h , y i k 2 h
2
2
k 4 f xi h , y i k 3 h
127
Rac 2015
36
Heun (R-K 2)
R-K 4
128
129
Rac 2015
37
dy n
f n x , y1 , y 2 ,..., y n
dx
Initial condition:
x 0 , y10 , y 20 ,..., y n0
130
Boundary--value Problem
Boundary
Heat transfer: from hotter surface, T1, to cooler surface T2,
in one-dimensional medium (rod)
Thot
Tcool
d 2T
h ' Ta T x 0
dx 2
Known: Th, and Tc.
Find: temperature distribution at the medium
131
Rac 2015
38
Boundary--value Problem
Boundary
Solution Strategy#1: Shooting method
d 2T
h ' Ta T x 0
dx 2
d dT
h ' T Ta
dx dx
dz
dT
z;
h ' T Ta
dx
dx
Steps:
Assume z(0) calculate to find Tn
if Tn known Tc, Assume z(0),
Interpolate to find appropriate z(0) use for overall
solution, T (x).
Example 27.1
132
Boundary--value Problem
Boundary
Strategy #2: Finite difference
d 2T
h ' Ta T x 0
dx 2
T 2Ti Ti 1
i 1
h ' Ta Ti 0
x 2
Grid model:
x
T0=Th
T1
T2
Tn = Tc
133
Rac 2015
39
Boundary--value Problem
Boundary
For each step, build system of equation:
T2 2T1 T0
T 2T1 Th
h ' Ta T1 0 2
h ' Ta T1 0
2
x
x 2
T3 2T2 T1
h ' Ta T2 0
x 2
Th = Hot temp
(known)
Th = Cold temp
(known)
Tn 2Tn 1 Tn 2
T 2Tn 1 Tn 2
h ' Ta Tn 1 0 c
h ' Ta Tn 1
2
x
x 2
a11
a
12
a12 a1n T0 b1
T b
a22
1 2
ann Tn 1 bn
Matrix of Linear
Algebraic Equation
Solve for Ts (temperature
Distribution)
134
Boundary--value Problems
Boundary
Buckling
Analytical Approach
d2y M
d 2 y Py
d2y
p2 y 0
dx 2 EI
dx 2
EI
dx 2
135
Rac 2015
40
Boundary--value Problems
Boundary
Analytical approach: Eigenvalue
Numerical approach: Finite difference:
d2y
p2 y 0
2
dx
y 2 y i y i 1
i 1
p 2 yi 0
2
x
y i are deflection of the column at position xi
(see Boundary Value Problems Procedure above)
136
Eigenvalue Problems
General Form
A I X 0
Possible solutions:
{X} = 0, i.e. all x-s zero trival (useless)
[[A]-[I]] = {0}, i.e. det [[A]-[I]] = 0 non-trivial, with
usefull {X}
137
Rac 2015
41
Eigenvalue Problems
Alternate method: Power Method
A I X 0
AX X
X i 1 A X i
Procedure:
1.
2.
3.
4.
Eigenvalue Problems
Application #1: Mohrs Circle
State of stress
x xy
ij yx y
zx zy
Find Principal
x 1
yx
zx
xz
yz
z
Stresses:
xy
xz
y 2 yz 0
z 2
zy
3 I1 2 I 2 I 3 0
1 , 2 , 3 (principal stresses)
139
Rac 2015
42
Eigenvalue Problems
Application #2: MDOF Vibration
F 0
m1 x1 k 2 x1 x2 0
m2 x2 k x1 2 x2 0
First Approach: Mixed numerical-analytical
Trial solution:
xi Ai sin t
140
Eigenvalue Problems
xi Ai sin t
xi Ai 2 sin t
m1 x1 k 2 x1 x2 0
m1 A1 2 k 2 A1 A2 0
m2 x2 k x1 2 x2 0
2
2 m
1
m2
A1 0
k
2
2 A2 0
m2
k
m1
Eigenvalue Problem
141
Rac 2015
43
Eigenvalue Problems
Solution:
Natural frequencies: 1 and 2
Mode Shape:
p A1 and A2 for each mode
142
2u
2u
2u
A 2 B
C 2 D 0
x
xy
y
Classification
143
Rac 2015
44
Math Function:
2T 2T
0
x 2 y 2
144
2T 2T
0
x 2 y 2
Numerical Approach
Ti 1, j 2Ti , j Ti 1, j
Ti , j 1 2Ti , j Ti , j 1
x
y 2
if we set square grid, x y, hence :
Ti 1, j Ti 1, j Ti , j 1 Ti , j 1 4Ti , j 0
2
aT b
T ...
Temp. Distribution
over area
Rac 2015
45
Math Function:
T
2T
k' 2
t
x
146
T
2T
k' 2
t
x
T l 2Ti l Ti l 1
Ti l 1 Ti l
k ' i 1
t
x 2
Ti l 1 Ti l Ti l 1 2Ti l Ti l1
t
x 2
T0=Th
T1
T2
Tn = Tc
147
Rac 2015
46
Math Function:
2 y 1 2 y
x 2 c 2 t 2
Wave equation
148
Rac 2015
47