Top Banner
Dr. Guy Tel-Zur Computational Physics Differential Equations Autumn Colors, by Bobby Mikul , http://www.publicdomainpictures.net Version 10-11-2010 18:30
39

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

Jan 11, 2016

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Dr. Guy Tel-Zur Computational Physics Differential Equations Autumn Colors, by Bobby Mikul,  Mikul Autumn Colors,

Dr. Guy Tel-Zur

Computational PhysicsDifferential Equations

Autumn Colors, by Bobby Mikul, http://www.publicdomainpictures.net Version 10-11-2010 18:30

Page 2: Dr. Guy Tel-Zur Computational Physics Differential Equations Autumn Colors, by Bobby Mikul,  Mikul Autumn Colors,

Agenda

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

Page 3: Dr. Guy Tel-Zur Computational Physics Differential Equations Autumn Colors, by Bobby Mikul,  Mikul Autumn Colors,

Topics

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

Page 4: Dr. Guy Tel-Zur Computational Physics Differential Equations Autumn Colors, by Bobby Mikul,  Mikul Autumn Colors,

The scope of the discussion

For a higher order ODE a set of coupled 1st order equations:

Page 5: Dr. Guy Tel-Zur Computational Physics Differential Equations Autumn Colors, by Bobby Mikul,  Mikul Autumn Colors,

Simple methodsEuler method:

Integration using higher order accuracy:

Taylor series expansion:

Page 6: Dr. Guy Tel-Zur Computational Physics Differential Equations Autumn Colors, by Bobby Mikul,  Mikul Autumn Colors,

Local error!

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

Page 7: Dr. Guy Tel-Zur Computational Physics Differential Equations Autumn Colors, by Bobby Mikul,  Mikul Autumn Colors,

An ExampleLet’s solve:

Boundary conditiion

Page 8: Dr. Guy Tel-Zur Computational Physics Differential Equations Autumn Colors, by Bobby Mikul,  Mikul Autumn Colors,
Page 9: Dr. Guy Tel-Zur Computational Physics Differential Equations Autumn Colors, by Bobby Mikul,  Mikul Autumn Colors,

FORTRAN code - I

Demo: virtual box, folder: ~/fortran, program: chap2a.fCompilation: telzur@linux1:~/fortran$ fort77 -o chap2a chap2a.f

Euler’s method

Page 10: Dr. Guy Tel-Zur Computational Physics Differential Equations Autumn Colors, by Bobby Mikul,  Mikul Autumn Colors,

FORTRAN code - II FUNC(X,Y)=-X*YC-------scientific computing course, lecture 05 - differential equationsC Guy Tel-Zur, April 2011C example chap2a from KooninC 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

Taylor’s series method

Page 11: Dr. Guy Tel-Zur Computational Physics Differential Equations Autumn Colors, by Bobby Mikul,  Mikul Autumn Colors,

The Results

IX X Y DIFF Y DIFF 0 0.5 1. -.117503099 .875 .00749690272 1 1.0 .75 -.143469334 .57421875 .0323119089 2 1.5 .375 -.0503475331 .287109375 .0375430919 3 2.0 .09375 .0415852815 .116638184 .0186970998 4 2.5 0. .0439369343 .0437393188 .000197614776 5 3.0 0. .0111089963 .0177690983 -.00666010194

Euler’s Taylor’s

Page 12: Dr. Guy Tel-Zur Computational Physics Differential Equations Autumn Colors, by Bobby Mikul,  Mikul Autumn Colors,

Multi-Step methodsAdams-Bashforth

2 steps:

4 steps:

Page 13: Dr. Guy Tel-Zur Computational Physics Differential Equations Autumn Colors, by Bobby Mikul,  Mikul Autumn Colors,

(So far) Explicit methods

Future = Function(Present && Past)

Implicit methods

Future = Function(Future && Present && Past)

Page 14: Dr. Guy Tel-Zur Computational Physics Differential Equations Autumn Colors, by Bobby Mikul,  Mikul Autumn Colors,

Let’s calculate dy/dx at a mid way between lattice points:

Rearrange:

This is a recursion relation!

Let’s replace:

Page 15: Dr. Guy Tel-Zur Computational Physics Differential Equations Autumn Colors, by Bobby Mikul,  Mikul Autumn Colors,

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)=1X1=0.5, y(0.5)=?x2=1.0, y(1.0)=?

Page 16: Dr. Guy Tel-Zur Computational Physics Differential Equations Autumn Colors, by Bobby Mikul,  Mikul Autumn Colors,

Error=-0.01569

The solution:

Page 17: Dr. Guy Tel-Zur Computational Physics Differential Equations Autumn Colors, by Bobby Mikul,  Mikul Autumn Colors,

Predictor-Corrector method

Page 18: Dr. Guy Tel-Zur Computational Physics Differential Equations Autumn Colors, by Bobby Mikul,  Mikul Autumn Colors,

Predictor-Corrector method

Page 19: Dr. Guy Tel-Zur Computational Physics Differential Equations Autumn Colors, by Bobby Mikul,  Mikul Autumn Colors,

Runge-Kutta

Page 20: Dr. Guy Tel-Zur Computational Physics Differential Equations Autumn Colors, by Bobby Mikul,  Mikul Autumn Colors,
Page 21: Dr. Guy Tel-Zur Computational Physics Differential Equations Autumn Colors, by Bobby Mikul,  Mikul Autumn Colors,
Page 22: Dr. Guy Tel-Zur Computational Physics Differential Equations Autumn Colors, by Bobby Mikul,  Mikul Autumn Colors,

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

Page 23: Dr. Guy Tel-Zur Computational Physics Differential Equations Autumn Colors, by Bobby Mikul,  Mikul Autumn Colors,

Physics Project – The pendulum, 13.7

I use a modified the C++ code from:http://www.fys.uio.no/compphys/cp/programs/FYS3150/chapter13/cpp/program2.cpp

fout.close fout.close()

Demo on folder:\Lectures\05\CPP

Page 24: Dr. Guy Tel-Zur Computational Physics Differential Equations Autumn Colors, by Bobby Mikul,  Mikul Autumn Colors,

ODEs in Matlabfunction dydt = odefun(t,y)a=0.001;b=1.0;dydt =b*t*sin(t)+a*t*t;

Usage:

[t1, y1]=ode23(@odefun,[0 100],0);[t2, y2]=ode45(@odefun,[0 100],0);plot(t1,y1,’r’);hold onplot(t2,y2,’b’);hold off

Demo folder: C:\Users\telzur\Documents\Weizmann\ScientificComputing\SC2011B\Lectures\05\Matlab

Page 25: Dr. Guy Tel-Zur Computational Physics Differential Equations Autumn Colors, by Bobby Mikul,  Mikul Autumn Colors,

Output

Page 26: Dr. Guy Tel-Zur Computational Physics Differential Equations Autumn Colors, by Bobby Mikul,  Mikul Autumn Colors,

http://www.scilab.org

Page 27: Dr. Guy Tel-Zur Computational Physics Differential Equations Autumn Colors, by Bobby Mikul,  Mikul Autumn Colors,
Page 28: Dr. Guy Tel-Zur Computational Physics Differential Equations Autumn Colors, by Bobby Mikul,  Mikul Autumn Colors,
Page 29: Dr. Guy Tel-Zur Computational Physics Differential Equations Autumn Colors, by Bobby Mikul,  Mikul Autumn Colors,
Page 30: Dr. Guy Tel-Zur Computational Physics Differential Equations Autumn Colors, by Bobby Mikul,  Mikul Autumn Colors,
Page 31: Dr. Guy Tel-Zur Computational Physics Differential Equations Autumn Colors, by Bobby Mikul,  Mikul Autumn Colors,

Parallel tools for Multi-Core and Distributed Parallel Computing

Page 32: Dr. Guy Tel-Zur Computational Physics Differential Equations Autumn Colors, by Bobby Mikul,  Mikul Autumn Colors,

In preparation

Parallel executionA new function (parallel_run) allows parallel computations and leverages multicore architectures and their capacities.

In future Scilab versions:http://help.scilab.org/docs/5.3.1/en_US/parallel_run.html

Page 33: Dr. Guy Tel-Zur Computational Physics Differential Equations Autumn Colors, by Bobby Mikul,  Mikul Autumn Colors,
Page 34: Dr. Guy Tel-Zur Computational Physics Differential Equations Autumn Colors, by Bobby Mikul,  Mikul Autumn Colors,
Page 35: Dr. Guy Tel-Zur Computational Physics Differential Equations Autumn Colors, by Bobby Mikul,  Mikul Autumn Colors,
Page 36: Dr. Guy Tel-Zur Computational Physics Differential Equations Autumn Colors, by Bobby Mikul,  Mikul Autumn Colors,
Page 37: Dr. Guy Tel-Zur Computational Physics Differential Equations Autumn Colors, by Bobby Mikul,  Mikul Autumn Colors,
Page 38: Dr. Guy Tel-Zur Computational Physics Differential Equations Autumn Colors, by Bobby Mikul,  Mikul Autumn Colors,

Xcos demo

Page 39: Dr. Guy Tel-Zur Computational Physics Differential Equations Autumn Colors, by Bobby Mikul,  Mikul Autumn Colors,