Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computational Physics Differential Equations

Similar presentations


Presentation on theme: "Computational Physics Differential Equations"— Presentation transcript:

1 Computational Physics Differential Equations
Dr. Guy Tel-Zur Autumn Colors, by Bobby Mikul, Version :30

2 Agenda MHJ Chapter 13 & Koonin Chapter 2 How to solve ODE using Matlab
Scilab

3 Topics Defining the scope of the discussion Simple methods
Multi-Step methods Runge-Kutta Case Studies - Pendulum

4 The scope of the discussion
For a higher order ODE  a set of coupled 1st order equations:

5 Simple methods Euler method: Taylor series expansion:
Integration using higher order accuracy: Taylor series expansion: Think of ‘x’ as the time ‘t’

6 Local error! Better than Euler’s method but useful only when it is easy to differentiate f(x,y)

7 An Example Boundary conditiion Let’s solve:

8

9 FORTRAN code - I Euler’s method
Demo: virtual box, folder: ~/fortran, program: chap2a.f Compilation: fort77 -o chap2a chap2a.f

10 Taylor’s series method
FORTRAN code - II Taylor’s series method FUNC(X,Y)=-X*Y C scientific computing course, lecture 05 - differential equations C Guy Tel-Zur, April 2011 C example chap2a from Koonin C compile under ubuntu using: fort77 -o chap2a_taylor chap2a_taylor.f 20 PRINT *,'ENTER STEP SIZE' READ *,h IF (H.LE.0) STOP NSTEP=3./h Y=1. DO 10 IX=0,NSTEP-1 X=IX*H Y=Y+H*FUNC(X,Y)+0.5*H*H*(-Y-FUNC(X,Y)*X) DIFF=EXP(-0.5*(X+H)**2)-Y PRINT *,IX,X+H,Y,DIFF 10 CONTINUE GOTO 20 END

11 The Results Taylor’s Euler’s IX X Y DIFF Y DIFF

12 Multi-Step methods -1 -1 Source:: Koonin page 27

13 Multi-Step methods Adams-Bashforth
2 steps: 4 steps:

14 (So far) Explicit methods
Future = Function(Present && Past) Implicit methods Future = Function(Future && Present && Past)

15 Let’s calculate dy/dx at a mid way between lattice points:
Let’s replace: Rearrange: This is a recursion relation!

16 yn+1=(1-xnh/2)/(1+xn+1h/2)yn
A simplification occurs if f(x,y)=y*g(x), then the recursion equation becomes: An example, suppose g(x)=-x yn+1=(1-xnh/2)/(1+xn+1h/2)yn This can be easily calculated, for example: Calculate y(x=1) for h=0.5 X0=0, y(0)=1 X1=0.5, y(0.5)=? x2=1.0, y(1.0)=?

17 The solution: 𝑦 1 = 1− 𝑦( 1 2 ) 𝑦 = 1−0∙0.5/2 1+1∙0.5/2 ∙1=0.8889 𝑦 1 = 𝑦 1 𝑒𝑥𝑎𝑐𝑡= 𝑒 −1/2 = Error=

18 Predictor-Corrector method

19 Predictor-Corrector method

20 Runge-Kutta

21

22

23 Proceed to: Physics examples: Ideal harmonic oscillator – section

24 Physics Project – The pendulum, 13.7
I use a modified the C++ code from: fout.close  fout.close() Demo on folder: \Lectures\05\CPP

25 ODEs in Matlab function dydt = odefun(t,y) a=0.001; b=1.0;
dydt =b*t*sin(t)+a*t*t; Usage: [t1, 100],0); [t2, 100],0); plot(t1,y1,’r’); hold on plot(t2,y2,’b’); hold off Demo folder: C:\Users\telzur\Documents\Weizmann\ScientificComputing\SC2011B\Lectures\05\Matlab

26 Output

27

28

29

30

31

32 Parallel tools for Multi-Core and Distributed Parallel Computing

33 In preparation Parallel execution
A new function (parallel_run) allows parallel computations and leverages multicore architectures and their capacities. In future Scilab versions:

34

35

36

37

38

39 Xcos demo

40


Download ppt "Computational Physics Differential Equations"

Similar presentations


Ads by Google