










Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!











Type 1: throwing a ball into the air - time to reach ground? a)Newton’s laws, analytic solution (neglect air resistance, model as point particle) b)Real world: put in air resistance, spin of ball, can integrate the equations numerically with high accuracy.
Type 2: Show that water freezes when cooled. Features:
Errors: finite simulation time. Finite number of particles.
One particle, one dimension:
dx dt
= v dv dt
= a = F (x, v, t)/m
First order form important! Generalize to three dimensions and many par- ticles later Definitions of velocity and acceleration.
Divide time into discrete steps t = ndt, n = 0 , 1... Full algorithm:
xn+1 = xn + dtvn vn+1 = vn + dtFn/m
Note xn ≡ x(ndt) Start from some x 0 , v 0. Generate x 1 , v 1 , then x 2 , v 2 , keep going .... Accurate to O(dt) Simple example – unit mass harmonic oscillator F = −x
Create a code euler.py. Inside
from visual import *
scene.autoscale=
scene.range=10.
ball=sphere(radius=0.5,pos=(0,8.0,0)) ball.vel=vector(0,0,0) dt=0. t=
while(1): rate(100) t=t+dt ball.pos=ball.pos+ball.veldt ball.vel=ball.vel-ball.posdt
while(arg): command tells the computer to do something until arg is true (1 in computer speak). Structures like while typically act on a group of Python commands Notice the colon You can tell which ones by the level of inden- tation. Eg. in the last code the lines
rate(100) t=t+dt ball.pos=... ball.vel=...
are all carried out in the while loop. IDLE (Python editor) automatically idents codes that follows such a command.
Identical equations for all components eg (x, y) and (vx, vy) eg. new equations for y-motion
dy dt
= vy dvy dt
= Fy/m
Same Python code will automatically integrate them! Just need to change initial conditions to have vy(t = 0) 6 = 0 and add y-component to force What about 3D ??
Nice to rewrite Python code to make it easier to keep the force definition separate from the Euler update.
from force import * while(1): rate(100) t=t+dt ball.pos=ball.pos+ball.veldt ball.vel=ball.vel+force(ball.pos,ball.vel)dt
Need a new code force.py
Nice with 2D,3D problems to visualize the tra- jectory. Need the track attribute which adds an object of type curve which is standard in VPython.
ball=sphere(radius=0.5,pos=(0,8.0,0), track=curve(radius=0.1)) ball.vel=vector(5,5,0) dt=0. t=
while 1: rate(100) t=t+dt ball.pos=ball.pos+ball.veldt ball.vel=ball.vel+forcedt ball.track.append(pos=ball.pos)