Differential Numerical
Differential Numerical
Differential Numerical
CISE301_Topic6 1
Numerical Differentiation
CISE301_Topic6 2
ist order derivatives fi X) = ↑- 12 /
3 ( 9- 4)
3) ( 0- 4)
MAR
min Value slOP2= f' = * (X) = 34-1 3 ( - 35 - 4)
ก
·
/
&
↑
slope = ': ⑦ -= # ⑦
3 3x- 4)
max
↑
0=
MAX Vale
เ นล X = - 1, in
~
min
/
-
ก - +
( อ น งMi
< >
-2 !
(23:0- 24 =- 16
== อ
for%
+'
-
ห
·
↳-
~ ะ -
↑2- 2) = - 8 +24 = 16
example fi X) = <2 - X+ 5
4
fix) = 344- 8x+61
↑> ( x) = 14-
4
⑦- เ น 0 = -
+
&~
To
(2) = 23 - 4( + 5 = 4- 0 + 5 :
~
MiN
(2) = 1
CO, 83
อ ม ทธ์ อา
ั
<2,1) ดส
ร่
ร่
่ำ
ป็
ก่
ค่
ม่
วิ
สุ
คื
ถึ
ยุ
พั
ต่
ร่
มี
ที
ป็
ค่
ค่
Motivation
How do you evaluate the Time Displacement
function. 0 30.1
measurements.
15 40.2
CISE301_Topic6 3
Recall
df f ( x h) f ( x )
lim
dx h0 h h=xi+1-xi
Taylor Theorem :
f ( 2 ) ( x ) h 2 f ( 3) ( x ) h 3
f ( x h) f ( x ) f ' ( x ) h O(h 4 )
2! 3!
n
E O(h ) real, finite C , such that : E C h
n
CISE301_Topic6 4
Three Formula
df ( x) f ( x h) f ( x)
Forward Difference :
dx h
df ( x) f ( x) f ( x h)
Backward Difference :
dx h
df ( x) f ( x h) f ( x h)
Central Difference :
dx 2h
CISE301_Topic6 6
Forward/Backward Difference Formula
Forward Difference : f ( x h) f ( x ) f ' ( x ) h O ( h 2 )
f ' ( x ) h f ( x h) f ( x ) O ( h 2 )
f ( x h) f ( x )
f ' ( x) O ( h)
h
_______________________________________________________
Backward Difference : f ( x h) f ( x ) f ' ( x ) h O ( h 2 )
f ' ( x ) h f ( x ) f ( x h) O ( h 2 )
f ( x ) f ( x h)
f ' ( x) O ( h)
h
CISE301_Topic6 7
Central Difference Formula
Central Difference :
f ( 2 ) ( x ) h 2 f ( 3) ( x ) h 3 f ( 4 ) ( x ) h 4
f ( x h) f ( x ) f ' ( x ) h ...
2! 3! 4!
f ( 2 ) ( x ) h 2 f ( 3) ( x ) h 3 f ( 4 ) ( x ) h 4
f ( x h) f ( x ) f ' ( x ) h ...
2! 3! 4!
f ( 3) ( x ) h 3
f ( x h) f ( x h) 2 f ' ( x ) h 2 ...
3!
f ( x h) f ( x h)
f ' ( x) O(h 2 )
2h
CISE301_Topic6 8
1.5
/( X) = 22 Central difference
X= d= 3 1 = 0.3
f'( X) = FIXth) - FSX- HI
2H
2 22
0 0.
/(4) = 191.357
='(x) = 258.77
ร่
+(4) = XIUX
*1= 1 , h = 0.3
20.15
="(X) = 1.08 17
The Three Formula (Revisited)
df ( x) f ( x h) f ( x)
Forward Difference : O ( h)
dx h
df ( x) f ( x) f ( x h)
Backward Difference: O ( h)
dx h
df ( x) f ( x h) f ( x h)
Central Difference : O(h 2 )
dx 2h
CISE301_Topic6 9
Higher Order Formulas
f ( 2) ( x)h 2 f (3) ( x)h3 f ( 4) ( x)h 4
f ( x h) f ( x ) f ' ( x ) h ...
2! 3! 4!
f ( 2) ( x)h 2 f (3) ( x)h 3 f ( 4) ( x)h 4
f ( x h) f ( x ) f ' ( x ) h ...
2! 3! 4!
f ( 2) ( x)h 2 f ( 4) ( x ) h 4
f ( x h) f ( x h) 2 f ( x ) 2 2 ...
2! 4!
f ( x h) 2 f ( x ) f ( x h)
f ( 2) ( x) 2
O ( h 2
)
h
f ( 4) ( )h 2
Error
12
CISE301_Topic6 10
Other Higher Order Formulas
f ( x h) 2 f ( x) f ( x h)
f ( 2) ( x )
h2
f ( x 2h ) 2 f ( x h ) 2 f ( x h ) f ( x 2h )
f ( 3) ( x )
2h 3
f ( x 2h ) 4 f ( x h ) 6 f ( x ) 4 f ( x h ) f ( x 2h )
f ( 4) ( x )
h4
CISE301_Topic6 11
Example
Use forward, backward and centered difference
approximations to estimate the first derivate of:
f(x) = –0.1x4 – 0.15x3 – 0.5x2 – 0.25x + 1.2
at x = 0.5 using step size h = 0.5 and h = 0.25
Note that the derivate can be obtained directly:
f’(x) = –0.4x3 – 0.45x2 – 1.0x – 0.25
The true value of f’(0.5) = -0.9125
In this example, the function and its derivate
are known. However, in general, only tabulated
data might be given.
CISE301_Topic6 12
Solution with Step Size = 0.5
f(0.5) = 0.925, f(0) = 1.2, f(1.0) = 0.2
45 8.5 +0.5) = /( 13
Forward Divided Difference:
FIXTH) - FI X / A
f’(0.5) (0.2 – 0.925)/0.5 = -1.45
|t| = |(-0.9125+1.45)/-0.9125| = 58.9%
Backward Divided Difference:
f’(0.5) (0.925 – 1.2)/0.5 = -0.55
|t| = |(-0.9125+0.55)/-0.9125| = 39.7%
Centered Divided Difference:
f’(0.5) (0.2 – 1.2)/1.0 = -1.0
|t| = |(-0.9125+1.0)/-0.9125| = 9.6%
CISE301_Topic6 13
Solution with Step Size = 0.25
f(0.5)=0.925, f(0.25)=1.1035, f(0.75)=0.6363
Forward Divided Difference:
f’(0.5) (0.6363 – 0.925)/0.25 = -1.155
|t| = |(-0.9125+1.155)/-0.9125| = 26.5%
Backward Divided Difference:
f’(0.5) (0.925 – 1.1035)/0.25 = -0.714
|t| = |(-0.9125+0.714)/-0.9125| = 21.7%
Centered Divided Difference:
f’(0.5) (0.6363 – 1.1035)/0.5 = -0.934
|t| = |(-0.9125+0.934)/-0.9125| = 2.4%
CISE301_Topic6 14
Discussion
For both the Forward and Backward difference,
the error is O(h)
Halving the step size h approximately halves the
error of the Forward and Backward differences
The Centered difference approximation is more
accurate than the Forward and Backward
differences because the error is O(h2)
Halving the step size h approximately quarters
the error of the Centered difference.
CISE301_Topic6 15
Richardson Extrapolation
f ( x h) f ( x h)
Central Difference : f ' ( x) O(h 2 )
2h
CISE301_Topic6 16
Richardson Extrapolation
Hold f ( x ) and x fixed :
f ( x h) f ( x h)
(h)
2h
( h ) f ' ( x ) a2h 2 a4h 4 a6h 6 ...
2 4 6
h h h h
( ) f ' ( x ) a2 a4 a6 ...
2 2 2 2
Use two derivate
h 3 4 15
( h ) 4 ( ) 3 f ' ( x ) a4h a6h 6 ... estimates to
2 4 16 compute a third,
4 1
f ' ( x ) ( h / 2) ( h ) O ( h 4 ) more accurate
3 3 approximation
CISE301_Topic6 17
Richardson Extrapolation Example
Use the function:
CISE301_Topic6 18
Solution
The first-derivative estimates can be computed
with centered differences as:
f (0.5 h ) f (0.5 h )
(h) at x 0.5
2h
f (1) f (0) 0.2 1.2
(0.5) 1.0, | t | 9.6%
1 1
f (0.75) f (0.25)
(0.25) 0.934375, | t | 2.4%
0.5
The improved estimate can be obtained by applying :
4 1 4 1
f ' (0.5) ( h / 2) ( h ) ( 0.934375) ( 1) 0.9125
3 3 3 3
Which produces the exact result for this example
CISE301_Topic6 19
หา ากลา งโด ยใ
Introduction to interpolatio Lagrange Polynomial Interporation FUNCTION อเ
↳หาFUNCTION ระห า ง ด2 function using Polynomidh
create interpolation
·
( A - $ ใน งไ ไง ↑
T
+
f2+ =
/
~ ↓
· (O 1 1 ·
·
2 15 > fits =? ↳
flt) =?
= · (O
~
Mid- Point
:
18 ง +
7
(
ว
ห บน ta578 Te mp. U
*** &:
of data
1=# Point
t
Temp
40 (
LagranQY: By
+5
=term iteratio
· K= PRODUCT notation
Degree Of Poly = D- 1
0.15 ?C iteration counter
1 70 ( T
2 100 '
~
<42,
y?) ( 413433 Blogger es- 1 = <
ล บ =จ น.
ดข
K= ↳ ①: 3 -
%·
FIX) = < X- XL32X- /3)
T= / 1 +... . . . .
<* 1- ↓2) ( X1- 13/
:
Degree 1 ี2 อ น (K 2
ค่
ยั
้ำ
จุ
ต่
ก้
จุ
ย่
ำ
ตั้
ก็
นั
ดั
ว่
มี
ถึ
ต่
นื
24 Order Lagrange Polynomial :
=
=2 ระ
K= ↳ &: 3 K= 3
K= 1 K= & K= 2
%
*
Lagrandpa: &Little
↑( 2.2) = 6
*1 25h=c
โจทย์ภา
x2 5 18 Degree = K =j
solution: 0 หา
3 : 1, K = 2 5 = 2, K=
①
Fi XL = ( X- XL) + (X- /1)
y
+ 2
<x1- 12 X1- 11
② JCX) = X- 3
(5) +
X- 2
(10
2 3- 2
ถ้
ำ
ชุ
ป็
น่
ต่
ถ้
2 order Language Polynomial
example: Find the Output Of X = =2.5
↓ ·
↓ 7 1ป
f( X) = - 0.25X'+ 34 + 1.25
(2.5) = 7.1875
ชุ
sut order Lagrage polynomial f 2x3 = 0.25 - 1.50334 + 57 + 8.33
1
พ นา มล บ
Lagrandpai: +it
4
2 f
( Degree (
prefer
4
1
5 17
1= 4 M-1= 3 : gu Lagrang
rd
solution: 0 ทา5 Order > & แทน ดในสมการ > ③ แทน X =
① X- 133 ( X- 14 )
FIX) = < X- X7( <X- 135( X- /4) x 1 + ( X- X13( ↑
/1- /23 ( X1- X3)( X1- A4) ( 42- AIS ( X1- /3) ( X2- X4)
(x3- /1) ( X3- /2) ( X3- 14 ( X4- 113 ( X4- XL ( X4- 13/
=......"
⑧
FO = x O
~
↑data &- 1 = su Order %o x
58
#
at X1: P1 <x1) = ↑1
+
4ธ
> + CSS Divided YO, 41. . . . , YK
sp P1 (X1)=X1=Y 0 +58.7 ( X1 - NO)
* Difference
Newton's
ntt- order
Polynomidl
:Fixs : /str. ... An
=
3 tex- x :s 58,1 = 41 - y8
x 1 - X8
4 = จ น วนจ ด ↓
divided - S 40,
difference
↳ AXVe
จุ
ต้
จุ
ว่
หุ
ข้
ต่
ทั
หุ
ำ
and order ·order
fo +
(
st ra
Y 1 order ↳" order 3 order
↓
x
4) I +
* +
41 - y8
58.73 = 50.332 = 51, 23 - F S0, 1 4)
* 4) * 1- xU
12 - XO 51, 2, 3 - fi, le L
f1, 2 = ↑2- / 50,1,2,3 =
XL +( 43 - X 8
x- /
#1. 2, 3 ) = /2.3 - 5102
52,3 3 =
↑
↓ 43 - +(
* 3- /2 * - Xl
↑
&
>x Order &- 1 = 1
41 -
order- 1 = 2nd
↓ /
⑧
S ·
*ข + fIX) = !
Y-
fiLX) = 1 50 + 50,1 ( - NO) 7 5
> ~
* Y 1st order
↓ is ↓
1 ( * Y It order 24 order
4
·
<28,13: O: 1
( 258,13:6- 2 = 2
3 6 3- 1 f20,1,2 = -
35 -
X- 1) ( fiC X) =
fiCX) =
3+( ↳ 5
f1, 1 = 5- 6
7-S
="I
7
== 0.37
>2) = 3 +
13-
1 =+ 33- 5)
5
FILX) = 50 + <50,73 ( - 10) + 50,1,2 (X- 10
(X- X13
↳
FLIX) = 2 +/ X- 13 - 0.575 X- 13 ( X- 3)
รา32) =
FCX) =
Ex 0.575X +
=55 =
1 52 ( X) = - 3.5 X- 1.3 25
ist order Newto
FLL 2) = - 0.379( 2) + 3.5( 7) - 1.175 = 4.575
Interpolating Polynomial!
Introduction to spline Interpolation ( ประมาณ า วนผ ↑Order - Quadratic spline
Splin interpolation
... 5 ใ
",
function อเน
ใน การค น 1st order- linear sprin ↑order- cubicsplines
↑
isplines
↑
· n- 1 splineS ~
· n-
~
· ·
=order of polynOmial 4 1- ① · ↓ -
① ·
~
↑ ↑
M=* data- 1
4- 4-
f( X)
·
·
· &OMGin ·
·
4) 4)
->
* +
ป ค อม
&
↓o is x
->
↓ is x
↓ 40 งหม
> PACK) = AR. ↑" + ... + &น
in อ งใ
· Lagrange + divided
always result in the
wil
same PrCX)!
#data = จ นวน ด
· ญห าขอ ล Lagrange+dividedon-
x2)
~
17 +
↳↑ Polyhomial order = 4 erro
LOCal - · Ph( XL lower Poly Order
used subsection
...
PRCX) : 4 Poly order
~
⑧
of the o
-
!
<LOC9
I erro ↑
~
*ท โจท สถ
42 - PICN PICX) = / 1 + 42 - 11 ( X- X1) ; <13X = XL
PICXS · าไ ภ าพ ไ ่ อ ง ด เส
43 - ·
* 1- Xi
↓ 4
A. D- 1 = 5 spline S P5( X) = 14 + 41 - 14 ( X- 12/
I
· il 528UAtiOn 28- 12
17 6
P19X) = 2 + 8- 2 ( X- 13
↓ เ P5( X) = 17x- 16.5
19 10
PCCX) = 1.2 X + 0.0 ; 1. X -> 6
·
1
14 / PLCX) = 0 + 6- 8 ( X- 6 1)
28 4)
7 -6 1 = 1: P1 1) = 3.
PL( X) = - 2X + 10; 6.3XX7
1 = 5: P115) = 6.8
PS( X) = 6 + 10 - 6 ( X- 7)
1 = 10:P4( 10) = 11.35
9- 7
PSLX) = 2 X- 8; 7XX-> &
ม่
ถ้
ที
ที่
ส้
ม่
ต้
คิ
Quadratic spline solving for Quadratic Interpolation:
·
P( XI) =
↑
General <**
order: PICX) = diX'+ bix + ci
4) - -
~
·
·
PolyHOMidI
diabi, CI = SURKRONUS / spline generated
> +
↓
=SUnknown p Usplines
· PLC X) = 93*+b2X+( 7
1 spline
>*
# 7) =34 UnKnOWRS
Quadralic spline
P1SX) = 91X+b1X+(1 I splines
Issues with Linear
~
splines
P2( X) = 92X"+b1X+( 2
& S12) = 6 UnKHONUS
· :หา+
ใ Quadrati 3 เกิด อ ดพลาดน
· ①ส า างสมกา รจา กจ ุด
ุ
·
212)
P1( /1) = X1 PL( X2) = /2
1/
( n- 1 equation
⑤ความโ ง วงแ รกเ ป
dipicxs =
ที่
ช่
ต้
ต่
ค้
ท่
8 given In equatio
PICX1) = /1 = 2 = &1 ( 15 + b111 +(
/
31
P1LX
&15361+01
·
PI( X() = 4) = 3 = 9
~
PICX), PC(X)
↑
p3( X 3 UnKnOWUS =
8 polyhomials to finds
S
9 Unknown
need 9 equation to solve 9 UMKHONS
P1CX) = alX" + beXt ( /
8 P1LX) = OPILKS
01
=
3) Plin
X= / X= =
#
↓x
D- 1 = 3- 1 = c efaction
(91X+b11 29 LX + b21X = /
x = x2 =
5 F" CPI(XJ) =
bl
2 92 ( 3) +
(MICS)+61 =
=641+61 - 692- b2
·PCIX) /1 x = As = #PS(X) / x= x
0 = 1042 + 62- 10 43 - bs
3.3
&(CPICAIS &(PICX)) 1 x = 11 = <MAt b1/
=
X = 11
x = Al
⑤
oiflix)) ( x= x1=
201 = 0
ย้
ดู
1 1 100000 0 al 2
9 1000.00 b &
3 10 09 01 3
·0
000255 100
=
9 9
0000 25 5 ว
⑥ ห
00000064 0 1
C 18
6 1 0- 6 -100 a
·
·0 6 10 10 - 10 - 1 0 b ·
2000.00000.0 8 ·
↓ 5
A
x< 3
PICX) = 04
D: 1<
+0.5X +1.5
X = 2 ใช้PILXS PIC() = 1.
~
interpolatin
P1( X FUNCTION X B
(
PICX): XA-> X =
⑧
( Fi X) =
P2( X): XB >>X < X (
#
&A is เ น FUNCTION
- อเ อ งและ
!
#Of UNKNOWRS:
Pl
PICKS PICX) = PICX
<Unknowns , Aspline = <D WhKNOWRS
PY S X) = ↑"23 X) splin
sut
total <n equation
·Each PhCX) will be order polynomidh
⑨หา สมการ จาก ดภายใ
PICX) = diX+b1x+ CIX + &1 P"1 CX2) = P" 2 ( XL)
PLCX = &2X+b2X+ CLX + &l
& 4 ( 2) = 8UnknOWRS
n- 1 equation
star > end ④ความโ วงแรกแ และโ ง
หา UnknownS > PHUNKNOWU >แก้สมกา เ น/
4 4n equation ี " (X1) =
②หา สมการ จาก ด อเน
①หา สมการ จาก จด อม 9 PCX2) = P2( XI P" ( /5) =
P1CX1 = / : PLXL) = Y / -
In equation -
ที่
จุ
นื่
ช่
จุ
ข้
ป็
ป็
ต่
ต่
ค้
สุ
ค้
@ H- 1 eqUATION
Pi XL) = P 23
3414 + 261X+/1 = 393"+262X + ( 2
547( 3) +161 ( 3) +21 = 39255)+262 ( 3) +C
{
3
fiX) = -0.3728 / + 4.554 - 15.15 3 x +17.5526; 3 >X= 5
B. P1 ( 1.5 ) = 1.87 ↓
P2 ( 4) = 5.92
P347): 10.58