Вы находитесь на странице: 1из 65

Outline

Simulation in the Undergraduate Physics Classroom


Ananda Dasgupta1
1 Department

of Physics St. Xaviers College Kolkata

e-mail : a dasgupta in@yahoo.com website : www.geocities.com/a dasgupta in

20th November 2005

Dasgupta

Simulation in the Undergraduate Physics Classroom

Outline

Outline
1

Simulation in the Physics Classroom Why teach simulations? The Python programming language Why use Python? Simulations - an example Simulating the oscillator Results The story so far Plotting elds Charged particle motion Some useful links
Dasgupta Simulation in the Undergraduate Physics Classroom

Outline

Outline
1

Simulation in the Physics Classroom Why teach simulations? The Python programming language Why use Python? Simulations - an example Simulating the oscillator Results The story so far Plotting elds Charged particle motion Some useful links
Dasgupta Simulation in the Undergraduate Physics Classroom

Outline

Outline
1

Simulation in the Physics Classroom Why teach simulations? The Python programming language Why use Python? Simulations - an example Simulating the oscillator Results The story so far Plotting elds Charged particle motion Some useful links
Dasgupta Simulation in the Undergraduate Physics Classroom

Outline

Outline
1

Simulation in the Physics Classroom Why teach simulations? The Python programming language Why use Python? Simulations - an example Simulating the oscillator Results The story so far Plotting elds Charged particle motion Some useful links
Dasgupta Simulation in the Undergraduate Physics Classroom

Outline

Outline
1

Simulation in the Physics Classroom Why teach simulations? The Python programming language Why use Python? Simulations - an example Simulating the oscillator Results The story so far Plotting elds Charged particle motion Some useful links
Dasgupta Simulation in the Undergraduate Physics Classroom

Simulation in the Physics Classroom The Python programming language Simulations - an example Results Some useful links

Why teach simulations?

Why teach Simulations?

Enhances student comprehension Allows deeper explorations Trains in precision

Dasgupta

Simulation in the Undergraduate Physics Classroom

Simulation in the Physics Classroom The Python programming language Simulations - an example Results Some useful links

Why teach simulations?

Why teach Simulations?

Enhances student comprehension Allows deeper explorations Trains in precision

Dasgupta

Simulation in the Undergraduate Physics Classroom

Simulation in the Physics Classroom The Python programming language Simulations - an example Results Some useful links

Why teach simulations?

Why teach Simulations?

Enhances student comprehension Allows deeper explorations Trains in precision

Dasgupta

Simulation in the Undergraduate Physics Classroom

Simulation in the Physics Classroom The Python programming language Simulations - an example Results Some useful links

Why teach simulations?

Why teach Simulations?

Enhances student comprehension Allows deeper explorations Trains in precision

Dasgupta

Simulation in the Undergraduate Physics Classroom

Simulation in the Physics Classroom The Python programming language Simulations - an example Results Some useful links

Why teach simulations?

The implementation

The philosophy No Advanced numerical methods Advanced programming Yet Advanced Physics

The OS issue MS - Windows Linux The language issue FORTRAN C Java Python

Dasgupta

Simulation in the Undergraduate Physics Classroom

Simulation in the Physics Classroom The Python programming language Simulations - an example Results Some useful links

Why teach simulations?

The implementation

The philosophy No Advanced numerical methods Advanced programming Yet Advanced Physics

The OS issue MS - Windows Linux The language issue FORTRAN C Java Python

Dasgupta

Simulation in the Undergraduate Physics Classroom

Simulation in the Physics Classroom The Python programming language Simulations - an example Results Some useful links

Why teach simulations?

The implementation

The philosophy No Advanced numerical methods Advanced programming Yet Advanced Physics

The OS issue MS - Windows Linux The language issue FORTRAN C Java Python

Dasgupta

Simulation in the Undergraduate Physics Classroom

Simulation in the Physics Classroom The Python programming language Simulations - an example Results Some useful links

Why teach simulations?

The implementation

The philosophy No Advanced numerical methods Advanced programming Yet Advanced Physics

The OS issue MS - Windows Linux The language issue FORTRAN C Java Python

Dasgupta

Simulation in the Undergraduate Physics Classroom

Simulation in the Physics Classroom The Python programming language Simulations - an example Results Some useful links

Why teach simulations?

The implementation

The philosophy No Advanced numerical methods Advanced programming Yet Advanced Physics

The OS issue MS - Windows Linux The language issue FORTRAN C Java Python

Dasgupta

Simulation in the Undergraduate Physics Classroom

Simulation in the Physics Classroom The Python programming language Simulations - an example Results Some useful links

Why teach simulations?

The implementation

The philosophy No Advanced numerical methods Advanced programming Yet Advanced Physics

The OS issue MS - Windows Linux The language issue FORTRAN C Java Python

Dasgupta

Simulation in the Undergraduate Physics Classroom

Simulation in the Physics Classroom The Python programming language Simulations - an example Results Some useful links

Why use Python?

Why use Python ?


Example : The Hello World Program C: # include<stdio.h> void main() { printf(Hello world); } Python : print Hello world

Simple Easy to learn Powerful Extensible Platform independent Open Source Free

Dasgupta

Simulation in the Undergraduate Physics Classroom

Simulation in the Physics Classroom The Python programming language Simulations - an example Results Some useful links

Why use Python?

Why use Python ?

Simple Easy to learn Powerful Extensible Platform independent Open Source Free

Python evolved as a language for teaching computer science concepts so the language overhead is deliberately kept at a minimum. An interpreted language - allows one to use the interpreter in the interactive mode to help understand concepts

Dasgupta

Simulation in the Undergraduate Physics Classroom

Simulation in the Physics Classroom The Python programming language Simulations - an example Results Some useful links

Why use Python?

Why use Python ?

Simple Easy to learn Powerful Extensible Platform independent Open Source Free

A general purpose language Supports structural, functional and object oriented programming Powerful modules available
numeric gnuplot visual (aka vPython)

Dasgupta

Simulation in the Undergraduate Physics Classroom

Simulation in the Physics Classroom The Python programming language Simulations - an example Results Some useful links

Why use Python?

Why use Python ?

Simple Easy to learn Powerful Extensible Platform independent Open Source Free Glue language C extensions for added speed

Dasgupta

Simulation in the Undergraduate Physics Classroom

Simulation in the Physics Classroom The Python programming language Simulations - an example Results Some useful links

Why use Python?

Why use Python ?

Simple Easy to learn Powerful Extensible Platform independent Open Source Free Interpreters are available (for free) for both Linux and MS-Windows

Dasgupta

Simulation in the Undergraduate Physics Classroom

Simulation in the Physics Classroom The Python programming language Simulations - an example Results Some useful links

Why use Python?

Why use Python ?

Simple Easy to learn Powerful Extensible Platform independent Open Source Free

Dasgupta

Simulation in the Undergraduate Physics Classroom

Simulation in the Physics Classroom The Python programming language Simulations - an example Results Some useful links

Why use Python?

Why use Python ?

Simple Easy to learn Powerful Extensible Platform independent Open Source Free

Dasgupta

Simulation in the Undergraduate Physics Classroom

Simulation in the Physics Classroom The Python programming language Simulations - an example Results Some useful links

Why use Python?

Using Python - the downside

Unconventional Slow

No longer! The google search engine uses python extensively - so does Linux!

Dasgupta

Simulation in the Undergraduate Physics Classroom

Simulation in the Physics Classroom The Python programming language Simulations - an example Results Some useful links

Why use Python?

Using Python - the downside

Unconventional Slow

No longer an issue at todays computer speeds!

Dasgupta

Simulation in the Undergraduate Physics Classroom

Simulation in the Physics Classroom The Python programming language Simulations - an example Results Some useful links

Simulating the oscillator

An example - Euler algorithm for the SHM


The algorithm : Initialize time, velocity, position . Calculate force from F = kx Calculate accleration from a =
F m vnew +vold 2

Calculate new velocity : vnew = vold + v = vold + a t Calculate new position : xnew = xold + Update the time tnew = told + t Keep on repeating until nal time is reached. Change the force law for other motions!! t

Dasgupta

Simulation in the Undergraduate Physics Classroom

Simulation in the Physics Classroom The Python programming language Simulations - an example Results Some useful links

Simulating the oscillator

An example - Euler algorithm for the SHM


The algorithm : Initialize time, velocity, position . Calculate force from F = kx Calculate accleration from a =
F m vnew +vold 2

Calculate new velocity : vnew = vold + v = vold + a t Calculate new position : xnew = xold + Update the time tnew = told + t Keep on repeating until nal time is reached. Change the force law for other motions!! t

Dasgupta

Simulation in the Undergraduate Physics Classroom

Simulation in the Physics Classroom The Python programming language Simulations - an example Results Some useful links

Simulating the oscillator

An example - Euler algorithm for the SHM


The algorithm : Initialize time, velocity, position . Calculate force from F = kx Calculate accleration from a =
F m vnew +vold 2

Calculate new velocity : vnew = vold + v = vold + a t Calculate new position : xnew = xold + Update the time tnew = told + t Keep on repeating until nal time is reached. Change the force law for other motions!! t

Dasgupta

Simulation in the Undergraduate Physics Classroom

Simulation in the Physics Classroom The Python programming language Simulations - an example Results Some useful links

Simulating the oscillator

An example - Euler algorithm for the SHM


The algorithm : Initialize time, velocity, position . Calculate force from F = kx Calculate accleration from a =
F m vnew +vold 2

Calculate new velocity : vnew = vold + v = vold + a t Calculate new position : xnew = xold + Update the time tnew = told + t Keep on repeating until nal time is reached. Change the force law for other motions!! t

Dasgupta

Simulation in the Undergraduate Physics Classroom

Simulation in the Physics Classroom The Python programming language Simulations - an example Results Some useful links

Simulating the oscillator

An example - Euler algorithm for the SHM


The algorithm : Initialize time, velocity, position . Calculate force from F = kx Calculate accleration from a =
F m vnew +vold 2

Calculate new velocity : vnew = vold + v = vold + a t Calculate new position : xnew = xold + Update the time tnew = told + t Keep on repeating until nal time is reached. Change the force law for other motions!! t

Dasgupta

Simulation in the Undergraduate Physics Classroom

Simulation in the Physics Classroom The Python programming language Simulations - an example Results Some useful links

Simulating the oscillator

An example - Euler algorithm for the SHM


The algorithm : Initialize time, velocity, position . Calculate force from F = kx Calculate accleration from a =
F m vnew +vold 2

Calculate new velocity : vnew = vold + v = vold + a t Calculate new position : xnew = xold + Update the time tnew = told + t Keep on repeating until nal time is reached. Change the force law for other motions!! t

Dasgupta

Simulation in the Undergraduate Physics Classroom

Simulation in the Physics Classroom The Python programming language Simulations - an example Results Some useful links

Simulating the oscillator

An example - Euler algorithm for the SHM


The algorithm : Initialize time, velocity, position . Calculate force from F = kx Calculate accleration from a =
F m vnew +vold 2

Calculate new velocity : vnew = vold + v = vold + a t Calculate new position : xnew = xold + Update the time tnew = told + t Keep on repeating until nal time is reached. Change the force law for other motions!! t

Dasgupta

Simulation in the Undergraduate Physics Classroom

Simulation in the Physics Classroom The Python programming language Simulations - an example Results Some useful links

Simulating the oscillator

An example - Euler algorithm for the SHM


The algorithm : Initialize time, velocity, position . Calculate force from F = kx Calculate accleration from a =
F m vnew +vold 2

Calculate new velocity : vnew = vold + v = vold + a t Calculate new position : xnew = xold + Update the time tnew = told + t Keep on repeating until nal time is reached. Change the force law for other motions!! t

Dasgupta

Simulation in the Undergraduate Physics Classroom

Simulation in the Physics Classroom The Python programming language Simulations - an example Results Some useful links

Simulating the oscillator

An example - Euler algorithm for the SHM


The algorithm : Initialize time, velocity, position . Calculate force from F = kx Calculate accleration from a =
F m vnew +vold 2

Calculate new velocity : vnew = vold + v = vold + a t Calculate new position : xnew = xold + Update the time tnew = told + t Keep on repeating until nal time is reached. Change the force law for other motions!! t

Dasgupta

Simulation in the Undergraduate Physics Classroom

Simulation in the Physics Classroom The Python programming language Simulations - an example Results Some useful links

Simulating the oscillator

The Python Program

... while (t <= tf) : F = -k * x a= F/m vn = v + a * deltat x = x + (v+vn)*deltat /2 v = vn t = t + deltat print t,v,x

Dasgupta

Simulation in the Undergraduate Physics Classroom

Simulation in the Physics Classroom The Python programming language Simulations - an example Results Some useful links

Simulating the oscillator

Output for the Simple harmonic oscillator


The undamped oscillator

Dasgupta

Simulation in the Undergraduate Physics Classroom

Simulation in the Physics Classroom The Python programming language Simulations - an example Results Some useful links

Simulating the oscillator

Output for the Simple harmonic oscillator


SHO - viscous drag F = -k * x -gamma*v

Dasgupta

Simulation in the Undergraduate Physics Classroom

Simulation in the Physics Classroom The Python programming language Simulations - an example Results Some useful links

Simulating the oscillator

Output for the Simple harmonic oscillator

SHO - with kinetic friction - what does the envelope look like?

Dasgupta

Simulation in the Undergraduate Physics Classroom

Simulation in the Physics Classroom The Python programming language Simulations - an example Results Some useful links

Simulating the oscillator

Output for the Simple harmonic oscillator

SHO - with kinetic friction

if v >= 0.0: F = -k*x - mu*m*g else: F = -k*x + mu*m*g

Dasgupta

Simulation in the Undergraduate Physics Classroom

Simulation in the Physics Classroom The Python programming language Simulations - an example Results Some useful links

Simulating the oscillator

Output for the Simple harmonic oscillator


SHO - with kinetic friction

Dasgupta

Simulation in the Undergraduate Physics Classroom

Simulation in the Physics Classroom The Python programming language Simulations - an example Results Some useful links

Simulating the oscillator

Phase space plots for the oscillator


The undamped oscillator

Dasgupta

Simulation in the Undergraduate Physics Classroom

Simulation in the Physics Classroom The Python programming language Simulations - an example Results Some useful links

Simulating the oscillator

Phase space plots for the oscillator


SHO - viscous drag

Dasgupta

Simulation in the Undergraduate Physics Classroom

Simulation in the Physics Classroom The Python programming language Simulations - an example Results Some useful links

Simulating the oscillator

Phase space plots for the oscillator


SHO - with kinetic friction

Dasgupta

Simulation in the Undergraduate Physics Classroom

Simulation in the Physics Classroom The Python programming language Simulations - an example Results Some useful links

The story so far Plotting elds Charged particle motion

Experience on the eld


So far, two batches of students have taken this course. 2003-04 2 theory classes / week. 3 periods lab / twice every three weeks Yearend project. 2004-05 No theory classes Lab with prepared instruction sheets Projects alloted.

Both batches did reasonably well. The major problem that we faced is the lack of a good book using python in physuics simulations. So - we wrote one!

Dasgupta

Simulation in the Undergraduate Physics Classroom

Simulation in the Physics Classroom The Python programming language Simulations - an example Results Some useful links

The story so far Plotting elds Charged particle motion

Experience on the eld


So far, two batches of students have taken this course. 2003-04 2 theory classes / week. 3 periods lab / twice every three weeks Yearend project. 2004-05 No theory classes Lab with prepared instruction sheets Projects alloted.

Both batches did reasonably well. The major problem that we faced is the lack of a good book using python in physuics simulations. So - we wrote one!

Dasgupta

Simulation in the Undergraduate Physics Classroom

Simulation in the Physics Classroom The Python programming language Simulations - an example Results Some useful links

The story so far Plotting elds Charged particle motion

Experience on the eld


So far, two batches of students have taken this course. 2003-04 2 theory classes / week. 3 periods lab / twice every three weeks Yearend project. 2004-05 No theory classes Lab with prepared instruction sheets Projects alloted.

Both batches did reasonably well. The major problem that we faced is the lack of a good book using python in physuics simulations. So - we wrote one!

Dasgupta

Simulation in the Undergraduate Physics Classroom

Simulation in the Physics Classroom The Python programming language Simulations - an example Results Some useful links

The story so far Plotting elds Charged particle motion

Experience on the eld


So far, two batches of students have taken this course. 2003-04 2 theory classes / week. 3 periods lab / twice every three weeks Yearend project. 2004-05 No theory classes Lab with prepared instruction sheets Projects alloted.

Both batches did reasonably well. The major problem that we faced is the lack of a good book using python in physuics simulations. So - we wrote one!

Dasgupta

Simulation in the Undergraduate Physics Classroom

Simulation in the Physics Classroom The Python programming language Simulations - an example Results Some useful links

The story so far Plotting elds Charged particle motion

Experience on the eld


So far, two batches of students have taken this course. 2003-04 2 theory classes / week. 3 periods lab / twice every three weeks Yearend project. 2004-05 No theory classes Lab with prepared instruction sheets Projects alloted.

Both batches did reasonably well. The major problem that we faced is the lack of a good book using python in physuics simulations. So - we wrote one!

Dasgupta

Simulation in the Undergraduate Physics Classroom

Simulation in the Physics Classroom The Python programming language Simulations - an example Results Some useful links

The story so far Plotting elds Charged particle motion

Experience on the eld


So far, two batches of students have taken this course. 2003-04 2 theory classes / week. 3 periods lab / twice every three weeks Yearend project. 2004-05 No theory classes Lab with prepared instruction sheets Projects alloted.

Both batches did reasonably well. The major problem that we faced is the lack of a good book using python in physuics simulations. So - we wrote one!

Dasgupta

Simulation in the Undergraduate Physics Classroom

Simulation in the Physics Classroom The Python programming language Simulations - an example Results Some useful links

The story so far Plotting elds Charged particle motion

Experience on the eld


So far, two batches of students have taken this course. 2003-04 2 theory classes / week. 3 periods lab / twice every three weeks Yearend project. 2004-05 No theory classes Lab with prepared instruction sheets Projects alloted.

Both batches did reasonably well. The major problem that we faced is the lack of a good book using python in physuics simulations. So - we wrote one!

Dasgupta

Simulation in the Undergraduate Physics Classroom

Simulation in the Physics Classroom The Python programming language Simulations - an example Results Some useful links

The story so far Plotting elds Charged particle motion

Solving Laplaces equation - a student project


Solving Laplaces equation in a rectangular domain by the relaxation method

To solve :

2V 2V + =0 x 2 y 2 V (i + 1, j) + V (i 1, j) + V (i, j + 1) + V (i, j 1) 4

we use the nite dierence version V (i, j) =

Start from any initial set of V (i, j) and iterate until the eld does not change appreciably.
Dasgupta Simulation in the Undergraduate Physics Classroom

Simulation in the Physics Classroom The Python programming language Simulations - an example Results Some useful links

The story so far Plotting elds Charged particle motion

Solving Laplaces equation - a student project


Solving Laplaces equation in a rectangular domain by the relaxation method

Dasgupta

Simulation in the Undergraduate Physics Classroom

Simulation in the Physics Classroom The Python programming language Simulations - an example Results Some useful links

The story so far Plotting elds Charged particle motion

Solving Laplaces equation - a student project


Solving Laplaces equation in a rectangular domain by the relaxation method

Dasgupta

Simulation in the Undergraduate Physics Classroom

Simulation in the Physics Classroom The Python programming language Simulations - an example Results Some useful links

The story so far Plotting elds Charged particle motion

Solving Laplaces equation - a student project


Solving Laplaces equation in a rectangular domain by the relaxation method

Dasgupta

Simulation in the Undergraduate Physics Classroom

Simulation in the Physics Classroom The Python programming language Simulations - an example Results Some useful links

The story so far Plotting elds Charged particle motion

Solving Laplaces equation - a student project


Solving Laplaces equation in a rectangular domain by the relaxation method

Dasgupta

Simulation in the Undergraduate Physics Classroom

Simulation in the Physics Classroom The Python programming language Simulations - an example Results Some useful links

The story so far Plotting elds Charged particle motion

Solving Laplaces equation - a student project


Solving Laplaces equation in a rectangular domain by the relaxation method

Dasgupta

Simulation in the Undergraduate Physics Classroom

Simulation in the Physics Classroom The Python programming language Simulations - an example Results Some useful links

The story so far Plotting elds Charged particle motion

Solving Laplaces equation - a student project


Solving Laplaces equation in a rectangular domain by the relaxation method

Dasgupta

Simulation in the Undergraduate Physics Classroom

Simulation in the Physics Classroom The Python programming language Simulations - an example Results Some useful links

The story so far Plotting elds Charged particle motion

Motion of a charged particle - a student project


Using the vPython module for visualizing the motion of a charged particle in crossed electric and magnetic elds.

Dasgupta

Simulation in the Undergraduate Physics Classroom

Simulation in the Physics Classroom The Python programming language Simulations - an example Results Some useful links

The story so far Plotting elds Charged particle motion

Motion of a charged particle - a student project


Using the vPython module for visualizing the motion of a charged particle in crossed electric and magnetic elds.

Dasgupta

Simulation in the Undergraduate Physics Classroom

Simulation in the Physics Classroom The Python programming language Simulations - an example Results Some useful links

Some useful websites :

The ocial Python site www.python.org www.enthought.com visual.org www.thinkpython.com diveintopython.org starship.skyport.net/crew/hinsen downloads documentation links forum jobs ...

Dasgupta

Simulation in the Undergraduate Physics Classroom

Simulation in the Physics Classroom The Python programming language Simulations - an example Results Some useful links

Some useful websites :

www.python.org www.enthought.com visual.org www.thinkpython.com diveintopython.org starship.skyport.net/crew/hinsen For MS-Windows - a nicely packaged python suite with a good collection of useful modules.

Dasgupta

Simulation in the Undergraduate Physics Classroom

Simulation in the Physics Classroom The Python programming language Simulations - an example Results Some useful links

Some useful websites :

www.python.org www.enthought.com visual.org www.thinkpython.com diveintopython.org starship.skyport.net/crew/hinsen Home of the Visual module aka vPython - a nice module for generating 3D animations.

Dasgupta

Simulation in the Undergraduate Physics Classroom

Simulation in the Physics Classroom The Python programming language Simulations - an example Results Some useful links

Some useful websites :

www.python.org www.enthought.com visual.org www.thinkpython.com diveintopython.org starship.skyport.net/crew/hinsen Home of the book How to think like a computer scientist - in Python - nice book, especially for beginning programmers.

Dasgupta

Simulation in the Undergraduate Physics Classroom

Simulation in the Physics Classroom The Python programming language Simulations - an example Results Some useful links

Some useful websites :

www.python.org www.enthought.com visual.org www.thinkpython.com diveintopython.org starship.skyport.net/crew/hinsen Home of the book Dive into Python - for more advanced programmers.

Dasgupta

Simulation in the Undergraduate Physics Classroom

Simulation in the Physics Classroom The Python programming language Simulations - an example Results Some useful links

Some useful websites :

www.python.org www.enthought.com visual.org www.thinkpython.com diveintopython.org starship.skyport.net/crew/hinsen Homepage of the scientic python module

Dasgupta

Simulation in the Undergraduate Physics Classroom

Вам также может понравиться