Purpose:
There are lovely books on numerical modeling in Physics that are intended for a complete course. It is fascinating to me that there are very few basic introductory documents for this material. I guess that means I'm on my own here:) Now that you have created a simple analytic calculation in a Jupyter notebook I need to introduce the basic tool of the trade for most modeling. That tool is called iteration and works roughly like this. If I know the condition of my object at a point in time (position, velocity, and forces) I can predict where it will be a short time later ASSUMING everything remains constant. This allows me to use my basic physics tools for a short period of time. I then stop and recalculate the forces (and accelerations) in the problem and then 'step' forward another increment of time. This is exactly like using Riemann sums to find areas under a curve.
This may make perfect sense conceptually but there are lots of things to trip over when you set up the code to make this happen. In essense you start a some moment in time that is usually labelled '0' and work you way forward to '1', '2', '3',.... etc etc. Keeping track of all of these individual points requires the use of 'vectors' which are a subset of a python creature called an array. Because you will be doing the same calculation over and over again as you move from point to point learning about loops will be critical. Having created this array of information describing the position and velocity of the object we will want to plot it out which means we need to learn a little about plotting as well..
This weeks lab will feel like a big step up and we will need to communicate effectively to keep things on track.
Thanks in advance.....
Process:
We will start this exploration by going through much of the Toast2.1 notebook that you can download from the Jupyter files webpage. Ideally you will have already done so and are following along. In this lab you will iteratively calculate the trajectory of an ideal physics ball. This means no friction etc etc.
You will make a copy of your First Steps lab as a starting point for this weeks lab:
I: Dependencies: As I have learned from the style guide I sent you to the section where I import useful libraries and functions is called the dependencies section. This will remain the same for this lab.
II: Markdown Cell: Before any code cells describe your understanding of what is happening in that cell. Document any important learnings that are illustrated in the cell including links to python/numpy/matplotlib documentation or tutorials. If you 'borrow' code from some source be sure to acknowledge the original authors and add your own understanding.
III: Code Cell: Your initial conditions will remain the same but some of the variables you defined will now need to be arrays instead of single points. You will need to distinguish between your initial position and the vector which defines the evolving position of the ball. There will be similar issues with the velocity. Will gravity need to be adjusted?
IV: Code Cell: In the next cell you will define the arrays that describe the evolving position and velocity of the ball. We will talk in class about issues of array 'length' relative to the number of iterations you are planning to do.
V: Code Cell: "Code your algorithm" for determining where the ball is one time step later. Start by using two explicit moments, 0 and 1, so you can see if the calculation makes sense (see next expectation). Check your result manually for consistency and units.
VI: Debug: As you develop the iterative algorithm you will write into your code some debugging print statements that allow you to watch what is happening as your code executes. When the cell is working as you desire then you will comment out (but leave it there so I can see it!) the debugging code.
VII: Wrap the code(step V) in 'while' loop: Now you just need to repeat the calculation in step V over and over again while changing the value of the index each time. This is where you are most likely to find that your debugging code will help sort out what is happening. One challenge in this process is deciding when to stop the calculation. How do you notice when the ball 'hits' the ground? Do you just keep calculating? How can you break out of the loop? When this code is working the result of this cell is a position and velocity array that describes where the ball is at each moment and how it is moving.
VIII: Create Plots: Your last step is to create and save a number of plots of your numerically generated data. These will be 'simple' two variable plots unless you choose to go further. The minimum requirement is an y vrs x plot of the trajectory of the ball and a y vrs t plot. Once you've gotten this far it is not a big step to do v vrs t or v vrs x or even kinetic energy vrs t if you so choose.
IX: How to get within 3% of previous result?: You will no doubt notice that your iteratively calculated trajectory does not land at the same point that you calculated last week. Why? By taking more smaller steps in time your iterative model should converge to the same value. How many steps and how small a time increment are required to get within 3% of the 'exact' solution? Does it depend on your initial velocity and/or angle?
- Project Deliverables:
1) Submit a pdf of your notebook that shows all aspects of your iterative model for a physics rock flying through the air. Answers to the questions asked above should be embedded in the notebook in markdown cells..
2) The last cell of your notebook will be a markdown cell with a short paragraph reflecting on your experiences with this first iterative model. What still confuses you? What part of the coding seems most obscure? What do you feel good about?