운동시뮬레이션
운동시뮬레이션 제 제1 1주 주
강의 소개, A First Numerical Problem 컴퓨터응용과학부 2011년 봄학기 담당교수 : 이형원 E304호, hwlee@inje.ac.kr E304호, hwlee@inje.ac.kr
강의소개 강의소개
담당교수 : 컴퓨터응용과학부 이형원
교재 : Computational Physics, N.J.
Giordano, H. Nakanishi, Prentice Hall
강의시간 : 수8교시, 목6,7교시
강의시간 : 수8교시, 목6,7교시
평가방법
◦ 네 번의 필기 시험 : 총 60%
1,3차 시험 : 각 10%
중간, 기말고사 : 각 20%
◦ 두 번의 실기 시험 : 총 30%
◦ 출석 : 총 10%
선수지식 선수지식(Prerequisites (Prerequisites))
미분방정식(Differential Equations)
수치해석(Numerical Analysis)
프로그램언어(Program Language)
◦ One of Java, C#, C, C++, Fortran,
◦ One of Java, C#, C, C++, Fortran, Basic, Ada
일반물리(General Physics)
참고자료 참고자료(References) (References)
General Physics
Java
C#
C, C++
C, C++
Numerical Analysis
Differential Equations
강의자료 강의자료
http://socas.inje.ac.kr -> 자료실 ->
일반자료실
진행
진행 계획 계획
제1주 : 강의소개, A First Numerical Problem(3 월 2일 수업, 3월 3일 실습)
제2주 : Realistic Projectile Motion(3월 9일 수업, 3월 12일 실습)
제3주 : Oscillatory Motion and Chaos(3월 16일 수업, 3월 17일 실습)
수업, 3월 17일 실습)
제4주 : 1차 필기 시험(3월 23일)
제5주 : The Solar System(3월 30일 수업, 3월 31일 실습)
제6주 : Potentials and Fields(4월2일 수업, 실습)
제7주 : Waves(4월 6일 수업, 4월 7일 실습)
제8주 : 중간 필기 및 실기 시험(4월 20일 필기, 4월 21일 실기)
진행계획 진행계획((계속 계속))
제9주 : Random Systems(4월 27일 수업, 4월 28일 실습)
제10주 : Statistical Mechanics, Phase Transition, and Ising Model(5월 4일 수업, 5월 7일 실습)
제11주 : Molecular Dynamics(5월 11일 수업, 5월 12일 실습)
12일 실습)
제12주 : 3차 필기 시험(5월 18일)
제13주 : Quantum Mechanics(5월 25일 수업, 5월 26일 실습)
제14주 : Vibrations, Waves, and the Physics of Musical Instruments(5월 28일 수업, 6월 2일 실습)
제15주 : Interdisciplinary Topics(6월 8일 수업, 6월 9일 실습)
제16주 : 기말필기 및 실기 시험(6월 15일 필기, 6월 16일 실기)
Chapter
Chapter 1 A first numerical 1 A first numerical problem
problem
Radioactive decay
A Numerical approach
Design and construction of a working program: codes and working program: codes and pseudocodes
Testing your program
Numerical considerations
Programming guidelines and philosophy
Radioactive Decay Radioactive Decay
n Ba
Kr U
U
n →235 →236 →92 +141 +3
Differential equation for Differential equation for nuclear decay
nuclear decay
Number of particles will change as decay process
τ
U
U N
dt
dN = −
Solution for the equation
τ
dt = −
/τ
) 0 ( )
( U t
U t N e
N = −
How to solve diff. equation How to solve diff. equation
Change the equation as
τ
dt N
dN
U
U = −
Integrate both side as
τ τ
t N
t N
dt N
dN
U t U
t N N
U
U U
U
−
=
→
−
=
∫
∫
(0)) ln (
0 )
( ) 0 (
Graph of the solution Graph of the solution
) 0
U( N
t
Numerical approach Numerical approach
Use Taylor’s expansion
+L
∆ +
∆ +
=
∆
= =
2 0
2 2
0 2
) 1 0 ( )
( t
dt N t d
dt N dN
t N
t U t
U U
U
Ignore the second order
=0 t=0
t
t dt
N dN t
N
t U U
U ∆ ≈ + ∆
=0
) 0 ( )
(
Numerical approach Numerical approach
Graphical interpretation
) ( t N ∆
) ( t NU ∆
)
( exact
U t
N ∆
∆t
Numerical approach Numerical approach
Definition of derivative
t
t N
t t
N t
t N
t t
N dt
dN U U U U
t U
∆
−
∆
≈ +
∆
−
∆
≡ +
→
∆
) ( )
( )
( )
lim (
0
Gives(Euler method)
t t
dt ∆ ∆
t dt
t dN N
t t
N
t t U U
U +∆ ≈ + ∆
=
) ( )
(
Numerical approach Numerical approach
Inserting the decay equation
t t t N
N t
t
N U
U
U +∆ ≈ − ∆
τ
) ) (
( )
(
We can obtain values(initial value problem)
τ
)L 3
( )
2 ( )
( )
0
( N t N t N t
NU → U ∆ → U ∆ → U ∆
Design Program Design Program
Declare necessary variables
Initialize variables
Do the actual calculation
Store the result/Show result as
Store the result/Show result as graph
Pseudo code for Pseudo code for initialization
initialization
Get data from console
Set initial time, final time, time step
Set initial nucleus number, decay time
time
Pseudo code for calculation Pseudo code for calculation
For each time step I, calculate and t at step i+1
◦
◦
NU
t t
N t
N t
NU ( i+1) = U ( i)−( U( i)/τ)∆ t
t
ti+1 = i +∆
◦
◦ Repeats for n-1 time steps
t t
ti+1 = i +∆
Testing your program Testing your program
Does the output look reasonable?
Does your program agree with any exact results that are available?
Always check that your program
Always check that your program
gives the same answer for different
“step sizes”
Numerical considerations Numerical considerations
Round-off error exist: use double precision
Total error(global error) exist
For unknown exact solution, check
For unknown exact solution, check if converge the result with step size
Programming guidelines Programming guidelines
Program structure
◦ Organize the program readable and understandable
Use descriptive names
Use descriptive names
◦ Choose variable and function names meaniful words
Use comment statements
Programming guidelines Programming guidelines
Sacrifice(almost) everything for clarity
◦ Use more variables if it is descriptive
◦ Change algorithm for execution speed
◦ Change algorithm for execution speed
Take time to make graphical output as clear as possible