Science and Computers I
Science and Computers I PHY 307
Popular in Course
Popular in Physics 2
This 25 page Class Notes was uploaded by Clement Bernier on Wednesday October 21, 2015. The Class Notes belongs to PHY 307 at Syracuse University taught by Staff in Fall. Since its upload, it has received 26 views. For similar materials see /class/225633/phy-307-syracuse-university in Physics 2 at Syracuse University.
Reviews for Science and Computers I
Report this Material
What is Karma?
Karma is the currency of StudySoup.
You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!
Date Created: 10/21/15
Lec2 mechanics and simple simulation Newton s laws Euler method 1D and 2D examples projectiles harmonic motion damping Simulation code and graphics More on functions Newton s laws One particle one dimension d1 IU gt v azFm dt First order form important Generalize to three dimensions and many par ticles later Definitions of velocity and acceleration Euler I What is meant by derivatives Nothing more than dz m 512t I dt It dt Chi gt0 dt Insert in first of Newton39s laws dtvt N 1t dt 51215 turning this around 1t dt 51215 dtvt If know 110 and use a small enough time step dt will give approx for 1t I dt Do same for vt dt Euler II Divide time into discrete steps 26 ndtn 01 Full algorithm xn1 ndtvn vn1 vn l thnm Note L n E xndt Start from some 120110 Generate 121111 then 122112 keep going Accurate to Odt Note F can be Ftxv Python no automatic scaling of window from Visual import no automatic scaling of window sceneautoscale0 size of window scenerange100 standard Python 3D object ballsphereradius05pos0800 ballvelvector000 dt001 tO loop over time for ever while 1 rate100 ttdt ballposballposballveldt ballvelballvelballposdt Comments Simple oscillator rate is a Python function whth controls the speed at which graphics is drawn to the screen A large argument means a faster simulation in real time sphere is a standard Python object It may have a number of attributes such as po sition color size etc You may also add attributes such as here velocity which is defined to be a vector Since VPython is a 3D environment we must work with vectors No automatic scaling of window to simula tion Fix size of window with range explic itly Indentation Structures like if while typically act on a group of Python commands You can tell which ones by the level of inden tation E9 in the last code the lines rate100 ttdt ballpos ballvel are all carried out in the while loop IDLE automatically idents codes that follows such a command Indentation II Such structures can be nested eg in the root program while ulgttol mul05 fmeXpmO5 if fmfugt00 um The statements m and iffmfugt00 are under control of the while command The statement um is separately under control of the if command Real oscillators Can add drag force f 2 km Python code line changes ballvelballvelballposO1ballveldt Notehere k 01 what happens larger k Damped oscillations overdamping Linear damping analytic solution possible but not in general But numerically easy to change to say f kv2 2D Motion Identical equations for all components eg 1234 and oxwy eg new equations for y motion dy v ddt y y 2 F dt ym Same Python code will automatically integrate them Just need to change initial conditions to have vytO 750 10 Drawing the path Nice with 2D3D problems to visualize the tra jectory Need the track attribute from Visual import no automatic scaling of window sceneautoscale0 scenerange100 use a standard Python 3D object to represent part ballsphereradius05pos0800 trackcurveradius01 ballvelvector550 dt001 tO while 1 rate100 ttdt ballposba11posballveldt ballvelba11velballposdt balltrackappendposballpos 11 Projectiles revisited Change force to form O 10 Gravity near Earth s surface ballsphereradius05posvector900 trackcurveradius01 ballvelvector330 dt001 t0 forcevectorO1000 true1 while true rate100 ttdt ballposba11posballveldt ballvelba11velforcedt balltrackappendposballpos if ballylt00 true0 12 General program for 1 particle damped 2d oscillator def forceposvelt result vector000 resultx10posxO1velx resulty10posyO1vely resultz0 return result ballsphere ballvelvector dt001 t0 while 1 ballposballposdtballVel ballvelballveldtforceba11posvelpost ballmass 13 Comments a mass is a user defined attribute a force function takes vector arguments and returns objects of type vector 0 return is keyword like if while etc 14 Lec2 IVIore mechanics Summary of Iec1 D gt 1 Python functions Drawing tracks Lissajou figures Better integrators than Euler leapfrog Summary 0 What is Computational Science Discipline concerned with solving math ematical models of physical systems us ing computers Small systems exact solutions Large systems simulations Model ing New types of phenomena not visi ble with few dof o Earliest origins in trying to predict motions in solar system mechanics gravity 0 Mechanics simplest method or algorithm to solve Newton s laws on computer Euler method Python code Create a code eulerpy Inside from visual import no automatic scaling of window sceneautoscale0 size of window scenerange100 standard Python 3D object ballsphereradius05pos0800 ballvelvector000 dt001 t0 loop over time for ever while1 rate100 ttdt ballposballposballveldt ballvelballvelballposdt General forces Nice to rewrite Python code to make it easier to keep the force definition separate from the Euler update from force import while1 rate100 ttdt ballposballposballveldt ballvelballvel forceballposballve1ballmassdt Need a new code in file forcepy Force function 2d oscillator def forceposvel result vector000 resultx10posx resulty10posy resultz0 return result Comments def force is followed by code defining what the function does Note indentation showing the lines of code inside the definition force function takes vector arguments and returns object result of type vector resultx gives x component of vector return iS keyword like import def while etc Drawing the path Nice with 2D3D problems to visualize the tra jectory Need the track attribute which adds an object of type curve which is standard in VPython ballsphereradius05pos0800 trackcurveradius01 ballvelvector550 dt001 t0 while 1 rate100 ttdt ballposballposballveldt ballvelballvelforcedt balltrackappendposballpos curve curve is really a list of coordinate points which can be dynamically added to Also knows how to plot itself to the screen Can be given attributes like radius color etc Like other standard prthon objects can be added as an attribute to SphereO Lissajou figures o Imagine using different harmonic springs in each direction What is resulting motion a Does motion close on finite length trajec tory When What condition is needed a Finite orbits termed Lissajou figures 10 Time step errors The Euler method we have used so far has its limitations solution accurate to 0dt only Why error per step 0dt2 Total steps Tdt Total error dtQTdt Tdt See this by computing energy E 12mv2 1213322 Compute error as function of dt Note calculate mean error over some finite period of time see code Can do better 11 Summary Functions Separate off code for particu lar force from code to integrate Newton s laws Easier to debug Less code to write when tackling new situation 2D3D Drawing tracks Playing with harmonic forces Better integrators leapfrog 14
Are you sure you want to buy this material for
You're already Subscribed!
Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'