**Pre Reqs:** [Kinematics](http://blog.dotphys.net/2008/09/basics-kinematics/), [Momentum Principle](http://blog.dotphys.net/2008/10/basics-forces-and-the-momentum-principle/)

What are “numerical calculations”? Why are they in the “basics”? I will give you really brief answer and then a more detailed answer. Numerical calculations (also called many other things – like computational physics) takes a problem and breaks into a WHOLE bunch of smaller easier problems. This is great for computers ([or a whole bunch of 8th graders](http://blog.dotphys.net/2008/09/computational-physics-and-a-group-of-1000-8th-graders/)) because computers don’t mind doing lots of little problems. Why are they “basic”? Well, most text would say they are not basic. I disagree. I think this is a legitimate method for solving problems. In particular, this is a great way of solving problems that can not be solved analytically (meaning solving one hard problem).

**Numerical Calculations are Theoretical Calculations**

Let me just get this out of the way. Numerical calculations and analytical calculations are really in the same “class”. Often people will lump numerical in with “computational experiment” but that is a really bad thing to do. Some others will claim that there are three different “paths” to discover stuff in science: theory, experiment, and simulations. Simulations are the same thing as numerical calculations which are the same as theory. ([I wrote a letter about this in the American Journal of Physics](http://scitation.aip.org/getabs/servlet/GetabsServlet?prog=normal&id=AJPIAS000076000009000797000001&idtype=cvips&gifs=yes))

**Example Problem**

Let me start with a problem that can be solved analytically. Suppose I have a ball of mass 0.5 kg and I throw this straight up with a speed of 10 m/s. How high will it go?

**Analytical Solution:**

First, let me draw a free body diagram for the ball while it is in the air.

![Screenshot 01](http://blog.dotphys.net/wp-content/uploads/2008/10/screenshot-01.jpg)

Yes, this is correct. Even though the ball is moving up, or if it is at the highest point, or if it is on the way down, there is only one force on it (neglecting air resistance, we can add that later). Remember your training. What is touching the ball? Nothing. What long range forces are on the ball? Just the gravitational force of the Earth. If you were in class with Aristotle, he would probably come up with something like *”If it is moving up, it still has some of the force of the hand on the ball.”* Don’t listen to him. He thinks he is a Jedi.

Ok, so how do you find out how high this will go? I am not going to do this the obvious way. The obvious way is to use the kinematics equations and assume that the acceleration is 9.8 m/s^{2} in the downward direction. Not going to do that. I am going to start with the momentum principle. I will write it as:

![Screenshot 02](http://blog.dotphys.net/wp-content/uploads/2008/10/screenshot-02.jpg)

Since the only motion and only force are in the y-direction (I am calling up as the positive y direction) I can write the following scalar equation:

![Screenshot 03](http://blog.dotphys.net/wp-content/uploads/2008/10/screenshot-03.jpg)

Notice that I went ahead and put the gravitational force as -mg where g is the local gravitational field (that is what I like to call it) and has a value of 9.8 Newtons/kg. So, what do I do with this equation? Well, there is something I know. I know the initial momentum (it was shot up at 10 m/s) AND I know the final momentum at the highest point is 0 kgm/s (because at the highest point, it stops for an instant). I can use this to find the time it take to get to the highest point.

![Screenshot 04](http://blog.dotphys.net/wp-content/uploads/2008/10/screenshot-04.jpg)

First, this is clearly going to be a positive value (good for time). I am calling the initial velocity and momentum by putting a subscript (1). Yes, I should have put units on the zero final momentum, but I am lazy. Ok. So, I have the TIME it takes to get to the highest point, but that is not what the question asked. Here I can use a small “trick”. If the force is constant, the momentum (and thus velocity) change at a constant rate. Then:

![Screenshot 07](http://blog.dotphys.net/wp-content/uploads/2008/10/screenshot-071.jpg)

If I choose the ground to be the origin so that the initial y is zero, then solving for the final y (y_{2})

![Screenshot 08](http://blog.dotphys.net/wp-content/uploads/2008/10/screenshot-081.jpg)

Now putting in what I found for the change in time from above:

![Screenshot 09](http://blog.dotphys.net/wp-content/uploads/2008/10/screenshot-09.jpg)

Now, if I want to put in some numbers, I can:

![Screenshot 10](http://blog.dotphys.net/wp-content/uploads/2008/10/screenshot-10.jpg)

I know what you are going to say: “you are doing it wrong. That is way more difficult than it needs to be. Just use the kinematic equation.” Well, there is nothing wrong with this method. I like it, it starts from more fundamental ideas than the kinematic equation you are referring to (I know the one).

**Numerical Solution**

What if I wanted to do this numerically? Well, the key is to break this into a whole bunch of little steps. This is such an easy example that anything can be used. I am going to show how to do this in a spreadsheet – though typically I like to use [vpython](http://www.vpython.org). I am not going to give a real intro to spreadsheets, but if you are not familiar with them maybe this will help.

First, I am going to set up my constants and variables:

![Screenshot 11](http://blog.dotphys.net/wp-content/uploads/2008/10/screenshot-11.jpg)

A couple of notes on this first step.

- Computers are stupid. I am sorry, but it is true. They really don’t know much. They don’t know the units. I wrote them down on the side, but the computer is just going to crunch the numbers. It is my (the human) responsibility to make sure the units are correct. I wrote them to the side, just for us humans.
- The momentum is actually calculated as 10*mass (it is good to get in a practice of calculating everything that you can).
- There are only 3 variables. Time, momentum (in the y-direction), and y position. You might need more for more complicated problems.
- What is “dt”? dt is the “time step” this is how long in time each step is. You will see.

Now, I will calculate the times. To do this, I will enter “0” for the first time cell (in my example, the first time cell is A7). The next time (cell A8) will be the time before plus “dt”. Here is the expression I entered in Excel.

![Screenshot 12](http://blog.dotphys.net/wp-content/uploads/2008/10/screenshot-12.jpg)

Instead of entering “0.1” for cell A8, I entered “=A7+B$4”. If you are not familiar with spreadsheets, the $ sign in front of the 4 means “don’t change this”. Now I will copy this formula to the cells below A8. In Excel you can do this by highlighting cell A8 and dragging the small box at the lower left hand of the cell:

![Screenshot 14](http://blog.dotphys.net/wp-content/uploads/2008/10/screenshot-14.jpg)

How far down do you copy? It really doesn’t matter, you can change this later.

Now, what about y? What is the first value? I already said that I would like the origin to be on the ground. This would mean the first value is 0. What about the value after that? I can use the following formula:

![Screenshot 15](http://blog.dotphys.net/wp-content/uploads/2008/10/screenshot-15.jpg)

Great, but I don’t know what the average velocity is. That is ok. I know what the initial velocity is, and that is good enough.

**This is the secret of numerical calculations**

It is not technically correct to use the initial velocity for the average velocity. However, if my time interval is short, it won’t really matter much. So, I will enter the following for the second value of y:

![Screenshot 16](http://blog.dotphys.net/wp-content/uploads/2008/10/screenshot-161.jpg)

Notice that instead of v_{y}, I put p_{y}/m – this will matter in the future (I am being prepared). Also, notice that I called the momentum C7, but dt as B$4 and mass as B$2. I am going to want to change the momentum, but not the time step nor the mass.

Finally, for the momentum. I will use the momentum principle:

![Screenshot 17](http://blog.dotphys.net/wp-content/uploads/2008/10/screenshot-17.jpg)

Here I am referring to p_{1} and p_{2}. These refer to the momentum for the first and second calculations, You can see that generically, the following is true:

![Screenshot 18](http://blog.dotphys.net/wp-content/uploads/2008/10/screenshot-18.jpg)

Where *n* can be any integer. Here is the formula entered in Excel for the momentum:

![Screenshot 19](http://blog.dotphys.net/wp-content/uploads/2008/10/screenshot-19.jpg)

Copying down some, you should have something that looks like this:

![Screenshot 20](http://blog.dotphys.net/wp-content/uploads/2008/10/screenshot-201.jpg)

Here you can already see your answer. What is the highest the ball goes? Well, you can look at the y positions and see that 5.61 is the highest. You also know this is the highest because it occurs when the momentum (and thus velocity) is around zero. I can also plot the position as a function of time:

![Screenshot 21](http://blog.dotphys.net/wp-content/uploads/2008/10/screenshot-211.jpg)

I know what you are thinking. I am a cheater and I am wrong. When I solved this problem analytically, I found the ball went 5.1 meters. With this method, the highest point is 5.256 meters (according to Excel). This problem is easily fixed. What if I go and change dt from 0.1 to 0.01? Try it. The first thing you will find is that you don’t have enough data. You will need to copy your calculations down around 100 cells. Now looking for the highest point, I find:

![Screenshot 22](http://blog.dotphys.net/wp-content/uploads/2008/10/screenshot-222.jpg)

Now I get on the order of 5.15 meters. What do you think would happen if I made dt = 0.001? Well, I would definitely need more Excel cells to find the answer.

I know this is long, but I want to show you another way of doing this numerical calculation.

**VPython**

It is useful to realize that with a spreadsheet, each row was a different time. Spreadsheets are nice in that people typically feel more comfortable with them than with a programming language.

What is [VPython?](http://www.vpython.org) VPython is a set of modules for python (the programming language) that does a lot of the hard work in 3-D graphics for you. In this case, you wouldn’t REALLY need vpython because you don’t really need a visual representation of the ball going up. Oh – vpython (and python) are FREE and run on Mac OS X, Windows, and Linux.

Let me go ahead and show you the vpython program

![Screenshot 25](http://blog.dotphys.net/wp-content/uploads/2008/10/screenshot-252.jpg)

- Notice the vector nature of stuff. VPython likes vectors and so should you. Even though this problem does not require vectors, it is good to get in the habit.
- Do not be afraid of the “sphere” function. It is part of the visual module and it will make a nice and pretty sphere.
- There are more sophisticated ways of getting the highest point, I could even make a graph, but printing out all the values is the clearest way.

Here is part of the output that was printed:

![Screenshot 26](http://blog.dotphys.net/wp-content/uploads/2008/10/screenshot-262.jpg)

Here also the highest point is 5.15 meters. One of the cool things about a program vs. a spreadsheet is that it is very easy to decrease the time steps. What if I re-run the program, but change dt to 0.001? The first thing you will notice is that the program takes longer to run (because it is printing out a lot more stuff). If you remove the “print” statements, it goes blazingly fast still. Looking at the output, I get the max height as 5.11 meters.

Ok. That is good enough for now. I still need to show you some more things with numerical calculations, but this is a good start. The next thing I need to show is a case where it is not so easy to do an analytical calculation.

A middle approach is to graph the function in gnuplot, for instance, and repeatedly expand the abscissa to zoom in on the ordinate. Given a spinning sphere (2-D!) the resultant of inertial centripetal acceleration and its horizontal component maximizes at 45 latitude. The Earth is anisotropically and inhomogeneously filled, it is distorted from spherical, sidereal day. WGS84 fits gee with a somewhat messy second degree trig function in latitude. Slap it into gnugraph, zoom in. A few minutes later… the sweet spot is at 44.951894 latitude.

Kinetic energy = Ek = (1/2) * m * v**2

Potential energy = Ep = m * g * h

At the top of its travels Ek is zero and Ep is max

So

(1/2) * m * v

2 = m * g * h2 / (2 * g)or

h = v

h = 10**2 / (2 * 9.8)

h ~= 5.102

Ralph,

That is the best way to calculate this analytically. However, I have not posted about work-energy yet. Also, I wanted to calculate this in a way that was somewhat similar to the way it would be with the numerical calculation. But – you are correct.