Sie sind auf Seite 1von 26

Computation and Programming in Physics

Numerical Integration Methods

Syeilendra Pramuditya

Physics Program
Institut Teknologi Bandung
1
2
Numerical Integration
 Definite integral dari f(t)
pada selang [a,b]
 Metode analitik: anti-
derivatif
 F dimana F’(t) = f(t)
 Iab = F(b) – F(a)

b
F (t )  I ab   f (t ) dt
a
3
Hand Calculation?
 Calculate until 2 decimal numbers?
 a = 88/17
 b = square-root of 23
 c = ln(7)
4
Numerical Integration
1
f (t ) 
t  ln7 = ???
7
1  ln5 = ???
I ab   dt  ln 7  ln 5
5
t

 Need to somehow calculate the numerical


value of natural logarithm!
 Real-world functions don’t have anti
derivatives!
 Direct calculation of definite integrals is
needed!
5
Numerical Integration
 Contoh: mencari nilai numerik ln1.2
x
1
ln( x )   dt
1
t

1.2
1
ln(1.2)   dt
1
t

 ln1.2 = luas area dibawah kurva


6
Numerical Integration
 Rumus umum quadrature
b n
I ab   f (t )dt   f (ti )wi
a i 0

 Rumus umum quadrature


 f(ti) : fungsi f dievaluasi di ti
 wi : weighting factor
7
Rectangular Rule

b
I ab   f (t )dt  f (ti ) wi  f ( a )  (b  a )
a
8
Do The Code
 Buatlah sebuah program yang menghitung
ln(x) menggunakan rectangular rule
 Input: batas kiri, batas kanan, jumlah partisi
 Output: hasil integrasi
 Seberapa akurat hasilnya?
9
Midpoint Rule

b
 ab
I ab   f (t )dt  f (ti ) wi  f    (b  a )
a  2 
10
Trapezoid Rule

b
f  a   f b 
I ab   f (t )dt  f (ti ) wi   (b  a )
a
2
11
Simpson Rule

b
ba   ab 
I ab   f (t )dt  f (ti ) wi    f (a )  4 f    f (b ) 
a
6   2  
12
Practice
 Hitung nilai numerik ln7.23 (untuk jumlah
partisi 5, 10, 25, 50)
 rectangle rule
 midpoint rule
 trapezoid rule
 Bandingkan hasil antara ketiga metode tsb
 Bandingkan dengan hasil hitungan
kalkulator/komputer
13
More Complex Integral

7.6
I ab   f (t )dt
3.2

ln( x)
f (t ) 
2
x 5
14
Monte Carlo Integration

b
 f ( x)dx
a 1
b
b 1 N
f ( x) a
 b
 
ba a
f ( x )dx f ( x) a

N
 f (x )
i 1
i

 dx
a

b
b ba N
 f ( x)dx  (b  a)  f ( x) a
 
N i 1
f ( xi )
a
15
Do The Code: Monte Carlo Integration

5.7
1
ln(5.7)   dt  1.74
1
t
16
Do The Code: Monte Carlo Integration

1.950
5.7
1
ln(5.7)  1 t dt  1.74 1.900

1.850

Numerical Value
N ln(5.7) 1.800
10 1.669
20 1.914 1.750
40 1.622
80 1.872
1.700
160 1.819
320 1.690
1.650
640 1.693
1280 1.723
1.600
2560 1.739
1 10 100 1000 10000
N points
17
Do The Code: Monte Carlo Integration
5.7
1
ln(5.7)   dt  1.74
1
t 2.200

2.100
N ln(5.7) ln(5.7) ln(5.7)
10 1.669 2.087 1.651
20 1.914 1.936 1.670 2.000

Numerical value
40 1.622 2.043 1.901
80 1.872 1.787 1.759 1.900
160 1.819 1.675 1.789
320 1.690 1.777 1.653
1.800
640 1.693 1.726 1.705
1280 1.723 1.751 1.712
2560 1.739 1.738 1.740 1.700

1.600

1.500
1 10 100 1000 10000
N points
18
Do The Code: Monte Carlo Integration
5.7
1
ln(5.7)   dt  1.74
1
t
2.8

2.6 N=10
N=160
2.4 N=2560

2.2

1.8

1.6

1.4

1.2

1
0 20 40 60 80 100
19
Do The Code: Monte Carlo Integration

7.6
I ab   f (t )dt
3.2

ln( x)
f (t ) 
2
x 5
20
Physics Problem
 Pendulum

d 2 (t )
  2 (t )  SHM
dt
g
  2 f
l
1 l
How Easy! T
f
 2
g
21
Physics Problem
 Large Amplitude Pendulum..?

Solution by series expansion


22
Physics Problem
 Large Amplitude Pendulum..?

d   g  sin  d

 l 
23
Large Amplitude Pendulum
24
Large Amplitude Pendulum
25
Large Amplitude Pendulum
 Input
 g, l, 0
 Process
 Evaluate the integral
 Output
 Period of the pendulum

Small Amplitude
1 l
T  2
f g
26
Do The Code
 Benchmark your integrator code first

Das könnte Ihnen auch gefallen