









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!










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 ??
def force(pos,vel): result = vector(0,0,0) result.x=-1.0pos.x result.y=-1.0pos.y result.z= return result