Escolar Documentos
Profissional Documentos
Cultura Documentos
Physics on the
Computer:
Spreadsheet
10
8
6
4
2
0
-2
-4
-6
-8
-10
19
S6
16
13
10
S11
S1
Page 1 of 18
INTRODUCTION TO SPREADSHEETS:
Calculations and Graphing
This exercise will guide you through the steps necessary to generate data and plot a
function using a spreadsheet. There are several spreadsheet programs (other types of programs
Mathematica, Maple, Matlab, Mathcad, etc.) would also suffice, and sometimes might be
preferable. However, this exercise should be done using a spreadsheet program.
To get started, I suggest that you read this worksheet and just try to get a sense of what is
going on. Start your spreadsheet and wander around in it for awhile. Go over the menu items to
see what is possible, Talk with people already familiar with the program, and as a last resort read
the Help menu. Practice getting the program to generate columns of data determined by
functions of your choice, and plotting your data. All of this will take some time as there is a fair
amount to become familiar with.
As an initial exercise, plot the quadratic,
(with x in meters and t in
seconds). This could be the position as a function of time for some particle. Later you will be
faced with more complicated tasks. This exercise is intended to be easy and will help you to
become familiar with the spreadsheet program.
Analyze: We will first create a time series, tn = t0 + nt. The input data are the starting time, t0,
the step size, t, and the constants, a = 4.9, b = 4, and c = 2 of the quadratic equation. Then we
can generate tn and xn = x(tn) from theses. Lets test our program by verifying that x(1) = 1.1.
Lets also let the computer plot xn vs tn to see with our eyes that its a quadratic.
Stop to think: Could you make a table with columns xn vs tn using this model and input data?
Program in Excel: The following discussion gives details of how to solve this problem using
Microsoft Excel (other spreadsheet programs will differ only slightly). If you are already
familiar with another spreadsheet, feel free to stick with it.
MICROSOFT EXCEL
There are a few things to know to get started:
you can move around the worksheet using the arrow keys or the mouse
to enter a number or a formula into a cell, select the cell by pointing at it with the mouse and
clicking once, then type in your entry, what you type will appear on a line just above the
worksheet below the formatting toolbar
when entering formulas you can use either lower case or upper case
to make a menu choice point and click on your selection on the menu bar and, while holding
the mouse down, drag down to the operation you want and release
To copy a formula from one cell to others, you highlight the cell you want to copy (point
at it and click), and then pull down 'Copy' from the 'Edit' menu. Then highlight the cell you want
to copy it into, and pull down 'Paste' from the 'Edit' menu - it should now appear in the new cell.
If you want to copy a formula or a number to a group of cells, you do it the same way except you
need to highlight all of the cells you want to copy into. To do this, point at the first cell, and
Physics on the Computer: Spreadsheet (version Spring 2007)
Page 2 of 18
while holding the mouse button down, drag over all the cells you want to highlight, and then let
go of the button.
There is an important distinction between a relative address and an absolute address.
What usually appears in a formula are constants, built-in functions, and numbers which are
located in some other cells of the spreadsheet. When you copy a formula from one cell to
another, sometimes you want to refer to a very specific spot, say the cell A4 ( at the intersection
of column A and row 4). To specify that you mean this exact spot, you give the absolute address
as $A$4 (note the dollar signs). Sometimes a formula refers to a number in some cell at a
particular relative location - say the adjacent cell on the left. For instance, we might have a
formula in B4 which involves the number in A4. If I copy the formula from cell B4 to the cell
B5, I want the formula there to look for the number in A5. If I write the relative address A4 in
the formula instead of the absolute address $A$4, copying to other cells will automatically give
the correct relative address. (You can also give an address like $A4, which is absolute in the
column designation, but relative in the row designation. Or A$4 which is absolute in the row
designation but relative in the column designation.) This is one of the very powerful features of
spreadsheets, as you shall see. Play around and check out how it works. You can quickly
alternate between relative and absolute addresses by pressing [command-T] on the Mac or F4 on
a PC.
Fill in your spreadsheet as follows (also see the picture on the next page):
A
1
Plot quadratic:
C
Moelter
2
3
(m) constant
-4.9
dt (s)
0.25
7
8
9
t n(s)
0
10
=A9+$A$6
11
20
xn (m)
=$A$4*A9^2+$B$4*A9+$C$4
copy cell B9
copy A10
to these
to these
cells
cells
down to here
down to here
The top few rows are used for information about you and the assignment. Also constants are
entered with labels and units when appropriate.
First well have to provide the input data. Notice that A4 is 4.9 (the coefficient of the
squared term in the formula), B4 is 4 (the coefficient of the linear term) and C4 is 2 (the
constant term), t is in A6 and t0 is in A9.
Now, lets make the tn array. Look at cell A10. The "=" sign at the start tells the program to
expect a mathematical formula. The formula means take the number in A9 and add to it the
number in A6. Again, the use of A4 (no dollar signs) is a relative address which, since we
are in A10, means take the number immediately above. $A$6 is an absolute address which
means go get the number in A6 no matter which cell you are asking from. So what have we
Page 3 of 18
got in column A? A sequence of numbers starting at zero, in intervals of 0.25: this will be
our tn data. Later on if we wanted to change it we could adjust cells A9, A6, and perhaps
how far down in column A we choose to go.
Finally, what were we trying to calculate? (Recall our function
) Take
a look at B9? It says take the number in the cell to the left (A9 since we are in B9), square it
(^2), multiply (*) by A4, add it to the product of B4 and the cell to the left, and finally add it
to C4. When you copy this to the cells below it the relative addresses will change, but the
absolute addresses will remain the same. For example cell B11 should be:
=$A$4*A11^2+$B$4*A11+$C$4. Move there and check (cell contents appear near the top
of screen in the formula bar).
Evaluate: Does the program pass the test? x(1) = 1.1? Row 13 has the time = 1, and the
corresponding x value. If B13 is not 1.1, then please go through the bullets again to fix a typo.
If this seems frustrating, its because of the computers rigid logic. You, being smarter than the
computer, will have to figure out whats wrong from the computers view point.
Current Cell
Chart gallery
Page 4 of 18
If everything looks ok then lets plot xn vs tn. Columns A and B, from rows 9 to 20, now contain
the data we would like to plot - column A for the variable t, in increments of 0.25, and column B
for the value of the quadratic function for each input t. How do we plot the data? Highlight your
data by clicking in A9 and dragging to B20 and let go, a rectangular region should be
highlighted. Now you can use the Chart Gallery tab (see picture) that lets you do it pretty
simply. On the top of your screen under the menu bar there should be a toolbar, with a bunch of
tabs in it. If there isn't, choose Elements Gallery in the 'View' menu. One of the tabs is the
Charts icon; click on it to get it going:
Choose "X-Y Scatter" for chart type, do not pick "line". If you dont see X-Y Scatter
immediately, click the >> and select it there.
add a title and axes labels using the formatting palette. If you dont see the formatting
palette, click View, then Formatting Palette.
With the design, implementation, testing, and visualization done, now its time to have fun
with the program. If you have gotten this far, you can now see how things change for different
quadratic functions. Move to cell A4 and change 4.9 to -10, or to whatever. Notice that the
values in B9 to B20 changed by themselves. This is because the formula in those cells referred
to $A$4 and you have changed A4. Notice also that the graph has changed, even rescaling the
axes if necessary. Pretty slick, eh!? Try changing the values in B4 and C4, or A6, and see how
your graph changes. Now that you can do this for a simple function, you can do it for any
function that you can write out as an equation, and even for some where you can't. Play around
with it!
Page 5 of 18
Where K=8.99X9 Nm2/C and the charge, Q = 2 nC. Plot it on range: -10<x<10, and -5<y<5.
Hint: Youll need to choose the surface option in the chart wizard to create a plot like on the
front cover.
You may add columns to that spreadsheet instead of creating a fresh one if you like.
Recall that numerical derivatives use the finite difference method:
Compare the numerical solution to the exact (analytical) solution. Comment on what you find.
Physics on the Computer: Spreadsheet (version Spring 2007)
Page 6 of 18
Euler method
Euler method
Page 7 of 18
to generate v and r, is the same for each time step. In more complicated problems, the
acceleration may change at each step because the force depends on either the position or
velocity, or both.
To do a better job, we could calculate the new position using the just calculated new
velocity (at the end of the interval), but we obviously can't do this for the first time step.
Croemer added this idea to Eulers method.
Eqns. 4
Euler method
v(t ) = v(t ) + a(t )t v = v + a t
n +1
n +1
Euler-Croemer
The midpoint method is even more accurate than the previous two because it uses the
slope at the midpoint of the time interval to estimate the forward progress of the velocity.
Eqns. 5
Euler method
v(t ) = v(t ) + a(t )t v = v + a t
n +1
n +1
)t rn +1 = rn + 1 2 (v n + v n +1 )t
Midpoint method
These approaches would give an exact solution if the time interval t we used were
infinitesimal in size, because then we would be doing the exact integrals that determine the
velocity and the position. Another way to say this is that values we use in equations (3), (4), and
(5) equal the instantaneous values in the limit of an infinitesimal time interval. But there's a
problem with trying to do this: we'd have an infinite number of data points where we'd have to
calculate v and r! So we want to use a time interval that is short enough to approximate the
answer adequately, but long enough that we don't have an unreasonable number of data points.
So how short is short enough? That depends on how fast v and r are changing. A simple test
that you can try in your program is to change t and see if your solution changes at all.
Describe a specific physical situation that has the solution given above. "A ball is thrown"
Analyze the problem: How does one express this equation using the Euler method? What
are the input data: acceleration, initial position, and initial velocity at t = 0 seconds? Are
there other input data? What are the derived data?
This time Id like you to use my tests. Precalculate x(2) = -4.9*22 +4*2+2. Plan to compare
the exact solution to the Euler method by graphing xEuler vs. t and xexact vs t on the same plot.
Youll need to plan extra columns for xexact. And vexact derived from the analytical equation,
x(t) = 4.9t 2 + 4t + 2 .
Now youre ready to start programming. Open the spreadsheet and set aside some space at
the top of the spreadsheet for information (your name, date, assignment number or name),
and a bit of space for the input data: parameters (constants that can change) such as time step
Page 8 of 18
(start with t=0.2 s), initial position, initial velocity, gravitational acceleration, etc. that you
might change later.
Your analysis above should have revealed that you will need 5 columns: time, velocity and
position from the Euler method, and for comparison the exact position and velocity from the
equation given above. To make this program work on more complicated problems where
accelerations arent constant, please add a column for acceleration.
The first entry in the acceleration, velocity and position columns, will have to be explicitly
set to the initial acceleration, velocity and position values you determined above.
Now put in your Euler formulas for position/velocity.
Copy your cells down far enough so that you can get to t =2 s.
Once you get it running, you will have a bunch of numbers that you need to think about.
Compare the exact and Euler values for both position and velocity at t=2 s.
It's much easier to interpret the graphs of velocity versus time and position versus time.
Make one graph with plots of both xEuler vs. t and xexact vs t . (See the Excel tips to learn how
to do this.) If things are still fishy, iterate the design until it is satisfactory.
Make another graph with plots of both vEuler vs. t and vexact vs t.
Do the exact and numerically determined values agree? If not, try adjusting the time step
until the position results agree to 2 significant figures at t =2 s.
Now go back to using the 0.2 s time step and change the position formula so it uses the
Euler-Croemer method. Does this do better or worse than Euler in determining the position
at t=2 s? How about the Midpoint method?
Here is a sample spreadsheet for the problem you are doing. Also, the bottom figure
shows part of the spreadsheet with formulas displayed.
Page 9 of 18
Page 10 of 18
Problem A3. An archeologist carelessly drops a very rare dinosaur bone (m=0.5 kg) into a tar
pit 55 m deep. The tar has a complicated density and temperature profile as a function of depth.
The result of this is that the coefficient of the drag force depends on depth. For this situation
(small
objects, low speeds) the drag force is roughly proportional to the velocity of the object,
F = b(y)v where is the velocity, and b(y)=2 + 0.03 y (in Ns/m for y in meters) where y is the
depth as measured from the top surface of the tar.
Set up a program to calculate the acceleration, velocity, and position of the bone as it
descends to the bottom of the tar pit. Plot out the position and velocity versus time. How long
does it take for the bone to hit the bottom and how fast is it going just before it hits? Do your
results make physical sense?
Problem B2. The planets move in elliptical orbits around the sun. It turns out that this is a
mm
direct result of the form of Newton's law of gravitation: F = G 1 2 2 r12 . The gravitational force
r
is attractive and varies as the inverse square of the distance between two massive objects,
directed along a line joining their centers. So what we learned about uniform circular motion
isn't quite true for planetary motion, although its not so bad for elliptical orbits that are almost
circular. An exact solution to the "two-body"
problem has been worked out (see any junior level
mechanics text); the "three body" problem (e.g. sun, earth, and moon) can't be solved
analytically, and you'd need to use a numerical scheme to solve for the motion.
The problem here is to determine the motion of the earth around the sun as a two-body
system. The vector nature of the force needs to be accounted for (what is Fx and Fy given a
position along the orbit?). Also, you need some initial conditions from which to start your
solution - so you'll need to look up some numbers and be a bit creative. The program isn't hard
to set-up, and once you have it, you can change the initial conditions and see how the orbits
change. Plot out a few orbits (y versus x) for different initial conditions.
Page 11 of 18
The plan is as follows: break your extended object into little chunks, find the field due to each
chunk, and add up the contributions. Well do a specific problem to see this procedure.
A Specific Problem: Rod of Charge
Let us find the field in the x-y plane due to a thin rod of charge sitting on the x-axis. Initially we
will let the charge distribution be given by the linear charge density
. This means the
charge density could vary on different parts of the rod.
The charged rod extends along the x-axis from a to b. A small chunk of charge (width dx) is
located at x and produces an electric field
at the point P (xo,yo). To the right is an
enlargement of that electric field vector with components indicated. Now we will find the charge
on the chunk, determine the electric field produced by the chunk, repeat for all chunks and add
them up.
Part of the Solution
The amount of charge on the little segment is
, where is the linear charge density,
charge per unit length (C/m in SI units). The magnitude of the electric field due to the bit of
1 dq
charge dq is dE =
. Now break the field due to the chunk, , into components:
4 0 r 2
and
. How will we get the total field in the x and y directions?
Physics
on the Computer: Spreadsheet (version Spring 2007)
Page 12 of 18
Because the charge lies along the x-axis we can pick up all the contributions by integrating along
x. (This was suggested by the dx in the expression for the charge.) What should be the limits of
integration?
In order to integrate with respect to x we need to be sure that the integrand is expressed in terms
of x and/or constants. Specifically, you need to write r and the trigonometric functions in terms
of xo, yo, and x; the first two are constant for a given point, P, in the plane and x is the variable of
integration. Compare what you get with what I got:
1
(x)(x 0 x)dx
1
(x)y 0 dx
dE x =
and dE y =
3
3
2
2
4 0 (x x) 2 + y
4 0 (x x) 2 + y 2 2
Now write an expression for Ex and Ey. The expressions for Ex and Ey are the physical model of
what we want to calculate. Rather than do these integrals, which we could do by various
techniques (substitution, looking it up in tables,...?), we will use a spreadsheet and solve the
numerically.
problem
NOTE: In general, if you can solve a problem analytically, you should! That way you can see
how the result depends on various physical quantities. A numerical result is only good for a
particular choice of values and if you change the values you need to recalculate.
There are a number of numerical techniques that can be applied to calculate an integral.
Page 13 of 18
between a=1 and b=3 m (a longer rod than before). The charge density is given by (x) = 20 x 2 ,
b
with o= 2x10-6 C/m. What do you get for the components of the field at (5,3) m? Here is where
the spreadsheet becomes helpful. As the charge density gets complicated (imagine it were the
inverse hyperbolic cosecant...) then you might not be able to solve it analytically.
Page 14 of 18
Kirchoff's laws
Look at a junction and get:
Now examine the left and right loops:
15 2I1 4I1 + 1I3 4 = 0 ,
4 1I3 3I2 + 6 2I2 = 0 .
This gives us a set of three equations that I put in standard form with a number multiplying each
1I1 1I2 + 1I3 = 0
of the currents and the constants on the other side of the equal sign. 6I1 + 0I2 + 1I3 = 11
0I1 5I2 1I3 = 10
1 1 1 I1 0
0 5 1 I3 10
the vector of the currents and V is the vector of the potentials. We can solve for C by finding the
inverse of M and then multiplying from the left,
M 1 M C = M 1V C = M 1V .
So now we need to enter M and V into a spreadsheet and find
. Then we can multiply
V by
and get C. The matrix inversion and multiplication operations are built into Excel.
Solution
Page 15 of 18
Now select (highlight) a region that is 3x1 to hold the result of the matrix multiplication. In
the equation input area type "=mmult(cells with M-1, cells with V)" and
then use "command + return" instead of "return".
Page 16 of 18
After entering the above formulas your spreadsheet should look like these.
Page 17 of 18
12
9
R1
R2
R3
20
40
30
Page 18 of 18