View
223
Download
2
Embed Size (px)
Citation preview
ECIV 301
Programming & Graphics
Numerical Methods for Engineers
REVIEW III
Topics• Regression Analysis
– Linear Regression– Linearized Regression– Polynomial Regression
• Numerical Integration– Newton Cotes– Trapezoidal Rule– Simpson Rules– Gaussian Quadrature
Topics• Numerical Differentiation
– Finite Difference Forms
• ODE – Initial Value Problems– Runge Kutta Methods
• ODE – Boundary Value Problems– Finite Difference Method
Regression
Often we are faced with the problem…
x y0.924 -0.003880.928 -0.00743
0.93283 0.005690.93875 0.00188
0.94 0.01278
-0.01
-0.005
0
0.005
0.01
0.015
0.92 0.925 0.93 0.935 0.94 0.945
what value of y corresponds to x=0.935?
Curve FittingQuestion 2: Is it possible to find a simple and convenient formula that represents data approximately ?
-0.01
-0.005
0
0.005
0.01
0.015
0.92 0.925 0.93 0.935 0.94 0.945
e.g. Best Fit ?
Approximation
Experimental Measurements
Strain
Str
ess
BEST FIT CRITERIA
Strain
y S
tres
s
xaaxl 10)(
ii
iii
xaay
xlye
10
)(
Error at each Point
Best Fit => Minimize Error
n
iii
n
ielimeasuredi
n
ii
xaay
yye
1
210
1
2mod,,
1
2
Best Strategy
Best Fit => Minimize Error
n
iii
n
ii xaaye
1
210
1
2
Objective:
What are the values of ao and a1
that minimize ?
n
iie
1
2
Least Square Approximation
101
210
1
2 ,aaSxaaye r
n
iii
n
ii
In our case
Since xi and yi are known from given data
02,
110
0
10
n
iii
r xaaya
aaS
02,
110
1
10
n
iiii
r xxaaya
aaS
Least Square Approximation
n
ii
n
i
n
ii
r xaaya
aaS
11
10
10
10 ,
n
ii
n
ii
n
iii
r xaxaxya
aaS
1
21
10
11
10 ,
Least Square Approximation
n
iii
n
ii
n
ii xyxaxa
11
21
10
n
ii
n
ii yxana
1110
2 Eqtns 2 Unknowns
Least Square Approximation
xaya 10
2
11
2
1111
n
ii
n
ii
n
ii
n
ii
n
iii
xxn
yxyxna
n
xx
n
ii
1
n
yy
n
ii
1
Example
y = 0.8393x + 0.0714
0
1
2
3
4
5
6
7
0 2 4 6 8
Series1
Linear (Series1)
Quantification of Error
0
1
2
3
4
5
6
7
0 1 2 3 4 5 6 7 8
Exper 1
Average
42.37
241
n
yy
n
ii
Quantification of Error
0
1
2
3
4
5
6
7
0 1 2 3 4 5 6 7 8
Exper 1
Average
n
iit yyS
1
2
Quantification of Error
0
1
2
3
4
5
6
7
0 1 2 3 4 5 6 7 8
Exper 1
Average
n
iit yyS
1
2
1
n
Ss t
y
Quantification of Error
n
iit yyS
1
2
1
n
Ss t
y
0
1
2
3
4
5
6
7
0 1 2 3 4 5 6 7 8
Exper 1
Average
Standard Deviation Shows Spread Around mean Value
y = 0.8393x + 0.0714
0
1
2
3
4
5
6
7
0 2 4 6 8
Quantification of Error
n
iii
n
iir xaayeS
1
210
1
2
Quantification of Error
n
iii
n
iir xaayeS
1
210
1
2
2/
n
Ss r
xy
“Standard Deviation” for Linear Regressiony = 0.8393x + 0.0714
0
1
2
3
4
5
6
7
0 2 4 6 8
Quantification of Error
0
1
2
3
4
5
6
7
0 1 2 3 4 5 6 7 8
Exper 1
Average
n
iit yyS
1
2
y = 0.8393x + 0.0714
0
1
2
3
4
5
6
7
0 2 4 6 8
n
iiir xaayS
1
210Better Representation
Less Spread
Quantification of Error
0
1
2
3
4
5
6
7
0 1 2 3 4 5 6 7 8
Exper 1
Average
n
iit yyS
1
2
y = 0.8393x + 0.0714
0
1
2
3
4
5
6
7
0 2 4 6 8
n
iiir xaayS
1
210
t
rt
S
SSr
2
Coefficient of Determination
t
rt
S
SSrr
2
Correlation Coefficient
Linearized Regressionxbeay 1
1
xba
eay xb
11
1
ln
lnln 1
BxA
1
1ln
bB
aA
The Exponential Equation
Linearized Regression2
2bxay
xba
xay b
2210
21010
log
loglog 2
BxA
2
210log
bB
aA
The Power Equation
Linearized Regression
xb
xay
33
33
3 111
axa
b
y
BxA
3
3
3
1
a
bB
aA
The Saturation-Growth-Rate Equation
Polynomial Regression
exaxaay 2210
A Parabola is Preferable
Polynomial Regression
210r
n
1i
222i10i
n
1i
2i
a,a,aS
xaxaay
e
Minimize
Polynomial Regression
0xaxaay2a
a,a,aS n
1i
2i2i10i
0
210r
0xxaxaay2a
a,a,aS n
1ii
2i2i10i
1
210r
0xxaxaay2a
a,a,aS n
1i
2i
2i2i10i
2
210r
Polynomial Regression
i22i1i0 yaxaxa)n(
ii23i1
2i0i yxaxaxax
i2i2
4i1
3i0
2i yxaxaxax
3 Eqtns 3 Unknowns
Polynomial Regression
i2i
ii
i
2
1
0
4i
3i
2i
3i
2ii
2ii
yx
yx
y
a
a
a
xxx
xxx
xxn
Use any of the Methods we Learned
Polynomial Regression
n
1i
222i10i210r xaxaaya,a,aS
With a0, a1, a2 known the Total Error
3n
Ss r
xy Standard Error
t
rt2
S
SSr
Coefficient of
Determination
Polynomial Regression
n
1i
2mmi10im10r xaxaaya,a,aS
For Polynomial of Order m
1mn
Ss r
xy Standard Error
t
rt2
S
SSr
Coefficient of
Determination
Numerical Integration & Differentiation
Motivation
x
xfxxf
x
y ii
Motivation
x
xfxxf
x
y ii
Motivation
x
xfxxf
dx
dy ii
x
0lim
Motivation
b
a
dxxfI
AREA BETWEEN a AND b
Motivation
)()( tydt
dtv
Motivation
b
a
dxtvty
Motivation
Motivation
Calculate Derivative
Given
MotivationGiven
Calculate
Think as Engineers!
In Summary
INTERPOLATE
In SummaryNewton-Cotes Formulas
Replace a complicated function or tabulated data with an approximating
function that is easy to integrate
b
a
n
b
a
dxxfdxxfI
nn
nnon xaxaxaaxf
111
In Summary
Also by piecewise approximation
b
ax
x
x
n
b
a
i
i
i
dxxf
dxxfI
1
Closed/Open Forms
CLOSED OPEN
Trapezoidal RuleLinear Interpolation
12
3hOError
Trapezoidal Rule Multiple Application
Trapezoidal Rule Multiple Application
Trapezoidal Rule Multiple Application
n
xfxfxfabI
n
n
ii
2
22
10
x a=xo x1 x2 … xn-1 b=xn
f(x) f(x0) f(x1) f(x2) f(xn-1) f(xn)
Simpson’s 1/3 Rule
Quadratic Interpolation
22102 )( xaxaaxf
90
5hOError
Simpson’s 3/8 Rule
Cubic Interpolation
33
22102 xaxaxaa)x(f
80
3 5hOError
Gauss Quadrature
x1 x2
2211 xfwxfwI
General Case
2211
1
1
xfwxfwdx)x(fI
Gauss Method calculates pairs of wi, xi for the Integration limits
-1,1
For Other Integration LimitsUse Transformation
Gauss Quadrature
b
a
dx)x(fIGxaax 10
10 aaa
10 aab
For xg=-1, x=a
For xg=1, x=b
20
aba
21
aba
Gauss Quadrature
b
a
dx)x(fI
2
Gxababx
Gdx
abdx
2
1
12dx)x(f
abdx)x(fI
b
a
Gauss Quadrature
1
12dx)x(f
abdx)x(fI
b
a
n
ii xfwab
I12
Gauss Quadrature
Points
Weighting Factors wi
Function Arguments
Error
2 W0=1.0 X0=-0.577350269 F(4)()
W1=1.0 X1= 0.577350269
3 W0=0.5555556 X0=-0.77459669 F(6)()
W1=0.8888888 X1=0.0
W2=0.5555556 X2=0.77459669
Gaussian Points
Points
Weighting Factors wi
Function Arguments
Error
4 W0=0.3478548 X0=-0.861136312 F(8)()
W1=0.6521452 X1=-339981044
W2=0.6521452 X2=- 339981044
W3=0.3478548 X3=0.861136312
Gaussian Quadrature
Not a good method if function is not available
Fig 23.1FORWARD FINITE DIFFERENCE
Fig 23.2BACKWARD FINITE DIFFERENCE
Fig 23.3CENTERED FINITE DIFFERENCE
Data with Errors
ODE IVP, BVP
Pendulum
W=mg
02
2
l
sinmg
dt
dm
02
2
l
sing
dt
d
OrdinaryDifferentialEquation
ODEs
02
2
l
sing
dt
dNon Linear
Linearization
Assume is small
sin 02
2
l
g
dt
d
ODEs
02
2
l
g
dt
dSecond Order
ydt
d
Systems of ODEs
0
l
g
dt
dy
ODE
15810450 234 x.xxx.y
5820122 23 .xxxdx
dy
ODE - OBJECTIVES
Cx.xxx.y 5810450 234
5820122 23 .xxxdx
dy
dx.xxxy 5820122 23
15810450 234 x.xxx.y
Undetermined
ODE- Objectives
15810450 234 x.xxx.y
Initial Conditions
10 y
ODE-Objectives
y,xfdx
dy
Given
.C.Iknowny,f 0
Calculate
xy
Runge-Kutta MethodsNew Value = Old Value + Slope X Step Size
hyy ii 1
Runge Kutta Methods
hyy ii 1
Definition of yields different Runge-Kutta Methods
Euler’s Method
hyy ii 1
y,xfdx
dy
ii y,xfLet
Sources of Error
Truncation: Caused by discretization
• Local Truncation• Propagated Truncation
Roundoff: Limited number of significant digits
Sources of Error
Propagated
Local
Euler’s Method
Heun’s Method
Predictor Corrector
2-Steps
Heun’s Method
Predict
Predictor-CorrectorSolution in 2 steps
hyy ii 10
ii y,xf
Let
Heun’s Method
Correct
Corrector
hyy ii 1
01ii y,xf
Estimate
2
01
iiii y,xfy,xfLet
Error in Heun’s Method
The Mid-Point Method
hyy ii 1
Remember:Definition of yields different Runge-Kutta Methods
Mid-Point Method
Predictor Corrector
2-Steps
Mid-Point Method
Predictor
Predict
22
1
hyy i
i
ii y,xf
Let
Mid-Point Method
Corrector
Correct
hyy ii 1
2
1
2
1 ,ii
yxf
Estimate
2
1
2
1 ,ii
yxfLet
Runge Kutta – 2nd Order
hyy ii 1
21 3
2
3
1kk
y,xfdx
dy .C.Iknowny,f 0
ii y,xfk 1
hky,hxfk ii 12 4
3
4
3
Runge Kutta – 3rd Order
hyy ii 1 321 46
1kkk
y,xfdx
dy .C.Iknowny,f 0
ii y,xfk 1
hky,hxfk ii 12 2
1
2
1
hkhky,hxfk ii 213 2
Runge Kutta – 4th Order
hyy ii 1 4321 226
1kkkk
y,xfdx
dy .C.Iknowny,f 0
ii y,xfk 1
hky,hxfk ii 12 2
1
2
1
hky,hxfk ii 34
hky,hxfk ii 23 2
1
2
1
Boundary Value Problems
Fig 23.3CENTERED FINITE DIFFERENCE
xo
Boundary Value Problems
x1 x2 x3 xn-1 xn...
Boundary Value Problems
xo x1 x2 x3 xn-1 xn...
),(2 112
012 yxfhyyy
Boundary Value Problems
xo x1 x2 x3 xn-1 xn...
),(2 222
123 yxfhyyy
Boundary Value Problems
xo x1 x2 x3 xn-1 xn...
),(2 332
234 yxfhyyy
Boundary Value Problems
xo x1 x2 x3 xn-1 xn...
),(2 112
21 nnnnn yxfhyyy
Boundary Value ProblemsCollect Equations:
),(2 112
012 yxfhyyy
),(2 222
123 yxfhyyy
),(2 112
21 nnnnn yxfhyyy
BOUNDARY CONDITIONS
T0 T5T0 T5
Example
02
2
TTcdx
Tda
x1 x2 x3 x4
Example
02
12012
TTc
h
TTTa
aTchTchTT 20
212 2
T0 T5T0 T5
x1 x2 x3 x4x1 x2 x3 x4
Example
02
22123
TTc
h
TTTa
aTchTchTT 21
223 2
T0 T5T0 T5
x1 x2 x3 x4x1 x2 x3 x4
Example
02
32234
TTc
h
TTTa
aTchTchTT 22
234 2
T0 T5T0 T5
x1 x2 x3 x4x1 x2 x3 x4
Example
02
42345
TTc
h
TTTa
aTchTchTT 22
234 2
T0 T5T0 T5
x1 x2 x3 x4x1 x2 x3 x4
Example
52
2
20
2
4
3
2
1
2
2
2
2
2100
1210
0121
0012
TTch
Tch
Tch
TTch
T
T
T
T
ch
ch
ch
ch
a
a
a
a
T0 T5T0 T5
x1 x2 x3 x4x1 x2 x3 x4