Physics 202 Physics on the Computer: Spreadsheet Version: Spring 2009 _________________________________ Matthew J. Moelter (edited by Jonathan Fernsler and Jodi L. Christiansen) Department of Physics California Polytechnic State University San Luis Obispo, CA 93407 Physics on the Computer: Spreadsheet (version Spring 2005) 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. 2 As an initial exercise, plot the quadratic, x(t) 4.9t 4t 2 (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 it’s 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 B Plot quadratic: C Moelter 2 3 (m/s^2) quad term coefficient (m/s) linear term coefficient (m) constant 4 -4.9 4 2 5 dt (s) 6 0.25 7 8 9 10 11 … 20 t n(s) 0 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 we’ll 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 =A9+$A$6 Physics on the Computer: Spreadsheet (version Spring 2007) 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. 2 Finally, what were we trying to calculate? (Recall our function x(t) 4.9t 4t 2 ) 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, it’s because of the computer’s rigid logic. You, being smarter than the computer, will have to figure out what’s wrong from the computer’s view point. Current Cell Chart gallery Physics on the Computer: Spreadsheet (version Spring 2007) 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 don’t see X-Y Scatter immediately, click the >> and select it there. add a title and axes labels using the formatting palette. If you don’t 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! Physics on the Computer: Spreadsheet (version Spring 2007) Page 5 of 18 While doing assignments, remember to: Analyze: What’s the physical model? What are the input data? What are the derived data? What data will you want to plot? Even though the problems on this page are probably easy enough that you’ll be able to answer all these questions in your head, take time to think the questions through completely. The tests should be written on a piece of paper, though, including the predicted answers before you open the blank spreadsheet. Trivial tests, like cos() are virtually useless. Program in Excel: Write the spreadsheet (NOTE: In Excel the argument of a trigonometric function must be in radians. Also, to use in an Excel formula, try using the PI() function which is very accurate. ) Evaluate: Does the spreadsheet pass its test? Do the plots all look reasonable? What makes them reasonable? Revise: If the tests or plots look odd, then go back and think it through again carefully. When everything is working properly, write up the report. It should include a statement of the problem, the numerical approach that you took, the test that the program passes and then the results, including the verification of the test, plots of interest, and any interesting features you discovered by adjusting the code.. Assignment: S0_P2 (Plotting) Problem A: How can we compare two functions on one plot? Try to write a code that plots y(t) Acos(t ) where A, , and are adjustable, let = 0 and = /2. Hint: To put two curves on one plot, highlight the tn, and both yn columns before starting up the chart wizard. Problem B: Plot the electric potential of a dipole in 2D. KQ KQ V ( x, y ) 2 2 ( x 5) y ( x 5) 2 y 2 Where K=8.99X9 Nm2/C and the charge, Q = 2 nC. Plot it on range: -10<x<10, and -5<y<5. Hint: You’ll need to choose the “surface” option in the chart wizard to create a plot like on the front cover. Assignment: S0_FD (Finite Difference) 2 Problem: Find the velocity from the position equation, x(t) 4.9t 4t 2 , used in your first spreadsheet. You may add columns to that spreadsheet instead of creating a fresh one if you like. x xn Recall that numerical derivatives use the finite difference method: x n n1 . t n1 t n 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 NUMERICAL SOLUTION TO ORDIANARY DIFFERENTIAL EQNS: (Euler and Euler-Croemer) By now you've had time to figure out how a spreadsheet works. Right!? So now we can start to do some fun stuff, which will ultimately let us do problems we can't do with pencil and paper alone. What we need to be able to do is solve ordinary differential equations (ODE) of the type you’ve learned about in other physics classes. This exercise will get you started with numerical solutions on a problem that you can solve analytically; the next spreadsheet assignment will be on some problems that can't be solved analytically. The approach to these problems is the same, so we’ll use the first exercise as a test case for the program to make sure everything works before applying it to the next exercise where tests are more difficult. Lets start by thinking about the familiar free-fall problem where velocity is the derivative of position, and acceleration is the derivative of velocity. We can write this as a single second2 order differential equation: a(t ) d x 2 OR as two first-order differential equations, namely, dt a(t ) dv dt and v(t ) dx dt. Once the problem is first order, we can integrate instead of differentiating. Integrating the acceleration tells us the velocity at some later time if we know it at some earlier time; we can derive the position in a similar stepwise fashion from the velocity. Starting at a time t0 at some known position r(t0) and with some known velocity v(t0), we can calculate the change in velocity in going from a time t0 to a time t1= t0 + t: v(t1) v(t0 ) a(t 0)t and for the position we get r(t1 ) r(t 0 ) v(t0 )t Using the Euler method twice, we have: Eqns. 3 Euler method v(t ) v(t ) a(t )t v v a t n 1 n n n 1 n n r(t n 1 ) r(tn ) v(t n )t rn 1 rn vn t Euler method where tn+1=tn+t or tn = nt . Note that the velocity/position depend on the previous velocity/position, the acceleration/velocity and the time interval. So the acceleration need not be constant. Let's say we want to numerically calculate the velocity and position of a mass falling freely under the force of gravity. (The solution to this problem is similar to the example illustrated in an earlier spreadsheet exercise.) Near the surface of the earth, we know that the acceleration of gravity is constant, a(t) = -g = -9.8 m/s2 and then we can calculate the new velocity from the previous velocity and the acceleration. vn 1 vn gt and the position is similar, rn1 rn vn t where tn+1=tn+t or tn = t0 + nt . Make sure you remember where these equations come from - it's a good idea to be able to generate them on your own without looking them up. This whole procedure can be repeated for the next time interval, e.g. from t1 to t2, and then again for the next time interval, t2 to t3, and so on. In this way the solution for v(t) and r(t) can be generated as a function of time, at a discrete set of points. This problem is especially simple because the acceleration, which is what we use Physics on the Computer: Spreadsheet (version Spring 2007) 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 Euler’s method. Eqns. 4 Euler method v(t ) v(t ) a(t )t v v a t n1 n n n1 n n r(tn1) r(tn ) v(tn1)t rn1 rn vn1t 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 n1 n n n1 n n r(tn 1) r(tn ) (v(tn t 2)t rn 1 rn 1 vn vn 1t 2 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. Assignment: S1_EC (Euler & Croemer) We will solve the same problem you did on the first assignment, the analytical solution 2 is x(t) 4.9t 4t 2 (with x in meters and t in seconds). But this time we'll use numerical techniques to obtain our solution. It is good practice to check your solution by comparing with a known result. 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 I’d 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. You’ll need to plan extra columns for xexact. And vexact derived from the analytical equation, x(t) 4.9t 2 4t 2 . Now you’re 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 Physics on the Computer: Spreadsheet (version Spring 2007) 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 aren’t 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. Physics on the Computer: Spreadsheet (version Spring 2007) Page 9 of 18 Numerical Solution of Problems with Position or Velocity-Dependent Acceleration Now you have a spreadsheet ready to calculate a numerical solution to a dynamical mechanics problem. All you need do is determine the force and corresponding acceleration and then let the computer determine the velocity and position, given the initial conditions. You can use this spreadsheet for any 1-D problem by modifying the acceleration column. When you are given a mechanics problem you do what you've always done: draw the free-body diagram, choose a coordinate system, and write down Newton's laws in component form. This gives you an expression for the components of the acceleration vector: a Fnet (r, v ) / m where the force could depend on the position and/or the velocity. In practice you will need to carefully write these out for each of the components. Now use the Euler or the Euler-Cromer methods. In many cases Euler-Cromer is better, especially for oscillatory systems. ____________________________________________________________________________ Assignment S2_E1D: Euler in one dimension Do one problem of type A. Your write-up should include an analysis of the problem. Include the physics and then turn the analytical equations into an appropriate numerical model. Input data and derived data should be identified. In these problems the acceleration changes, so you’ll need an additional column of data to hold the an values in the spreadsheet. A test should be included to verify that the code works properly before starting to play around with the parameters. Problem A1. A simple pendulum is not always so simple. You can see this if you calculate the motion of a pendulum that is started from rest at a large angle with respect to the vertical. For a 3.5 kg mass on a 1.0 m thin rod (massless), design a program to calculate the angular acceleration, angular velocity and angular position of the mass as a function of time over a few periods of the motion. Plot all three of these quantities for initial angles, 0=10o and 60o up to 90o (maybe every 10 degrees). Also, determine the period, T, of the motion as a function of starting angle for 0 from 10 to 90 every 10 degrees, now plot it out, T vs. 0. Can you think of ways to compare this with the result you get for small angles to see how the result differs? What do you notice about the shape of the acceleration and velocity curves? Problem A2. Imagine dropping a marble of mass 15 g from rest from a satellite that is directly above this building. Let the satellite be at a height of 3.58x107 m above the earth's surface. Although it is not reasonable we will ignore the effects of air resistance. The force on a particle bm of mass m above the earth is given by Newton's law of gravitation in the following form: F 2 , r where r is the distance of the mass from the center of the earth and we take b = 3.99x1014 m3/s2. The force is directed towards the center of the earth. You may ignore the earth's rotation. Design a spreadsheet to determine how long it would take the marble to hit the building. (Include the # in the time of your report.) Also, plot the position, velocity, and acceleration from the start until impact. Will the building be damaged? If so, how badly? Physics on the Computer: Spreadsheet (version Spring 2007) 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 v 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? Assignment S2_E2D: Euler in two-dimensions For these two-dimensional problems you will need seven (7) columns corresponding to t, ax, vx, x, ay, vy, y. The initial values for x, vx and y, vy will come from the problem. Do one problem of type B. Problem B1. A large flying object will be affected by air resistance. The force can be approximated by F b v v with v and v the velocity and its magnitude, and b is a constant that depends on the object and the medium. Set up a program to calculate the acceleration, velocity, and position of a bowling ball (m = 8 kg) launched from a height of 1.5 m above the ground with an initial speed of 40 m/s at an angle of 35o. Do this over a range of values of the drag coefficient, say from b = 0 to b = 5 Ns2/m2, and plot out the trajectories (y versus x) until the ball hits the ground for each b value. Make a plot of the maximum horizontal distance the ball travels as a function of b. Do your results make physical sense? Is 5 N-s2/m2 a reasonable value for a drag coefficient? 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 rˆ12 . 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. Physics on the Computer: Spreadsheet (version Spring 2007) Page 11 of 18 INTEGRATION: ELECTRIC FIELDS AND THE SPREADSHEET A. Electric Field Problem Electric Fields in General The basic problem is to determine the electric field at a point P in space, with coordinates (xo,yo,zo), for a specified distribution of charges. Note that for point charges it is reasonably simple. However, for a distributed charge (the ellipsoid or blob) you must find the electric field at P due to each of the pieces of charge in the blob and then add them together. The plan is as follows: break your extended object into little chunks, find the field due to each chunk, and add up the contributions. We’ll 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 (x) . 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 dE 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 dq (x)dx , 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, dE , into components: 40 r 2 dE x dE cos and dE y dE sin . 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 2 40 (x x) y 40 (x x) 2 y 2 2 0 0 0 0 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. B. Setting Up Your Spreadsheet To be specific let’s take (x) = o = 1x10-6 C/m. The rod is located between 1 and 2 meters along the axis and we want to know the field at position (xo,yo)= (3,3) m. Let’s see how we can calculate the total field using a spreadsheet. First, let’s determine which quantities are constants and which are variables. We will want to have the constants at the top of the spreadsheet and then have columns for the things that vary with position. A sample spreadsheet might be: A B C D E F Electric Field of Uniformly Charged Rod Moelter 2/2/00 1 Xo (m) Yo (m) a (m) b (m) dx (m) k (N m^2/C^2) 2 3 3 1 2 =($D$3 8.99E9 3 $C$3 ) /20 Piece # x (m) dEy (N/C) Ex (N/C) 4 dq = dx(C) dEx (N/C) =$C$3 + =1e-6*$E$3 =$F$3*C5* =$F$3*C5* =D25 5 1 ($E$3/2) ($A$3-B5) / $B$3/ (($A$3(($A$3B5)^2 + B5)^2 + $B$3^2)^ $B$3^2)^ (3/2) (3/2) =B5+$E$3 Ey (N/C) 6 2 =E25 7 ..... ... ..... COPY DOWN 24 20 =SUM =SUM 25 (D5:D24) (E5:E24) Physics on the Computer: Spreadsheet (version Spring 2007) Page 13 of 18 There are several things to note about the spreadsheet: Descriptive title and your name. (The date can be helpful to keep track of changes.) Labels for physical quantities with units indicated. Constants are in the top few rows and references to them are absolute (use the $ sign). The size of each segment is dx=(b-a)/20 (cell E3), which is the total length divided by the number of segments which we have chosen in this case to be 20. The formula for the x coordinate of the first segment has been chosen as the midpoint of the first segment, look at B5: x1=a+(dx/2). All the rest are just one step further along, B6: x2=x1+dx. The charge on a segment is given by dq (x)dx (for this problem 0dx , see cell C5). If you had a different charge density you would need to change this column. The results Ex and Ey are copied to F5 and F7. This is useful so you can see them when you make changes to a, xo, etc. without having to move around the spreadsheet. N/C. If you got the same then For the numbers given above I got Ex=349.53 N/C and Ey=714.62 your spreadsheet is probably working. The spreadsheet gives many digits, but how accurate is this result? What does it depend on? How could you check? Assignment S3_INTCON: Special Cases We have a working spreadsheet. Let’s see if we can get some physical understanding of how the field depends on position by looking at some special test cases. Along the Axis Find the field (both vector components) for points along the x-axis away from the charge, say at xo =4 m. What do you get for the x and y components of the field? Do these make sense? Explain. How does the field vary as you move further away from the rod, 8 m, 16 m,...? Does it 1 1 vary like 2 ? Like 3 ? Did you expect this? r r Along a Perpendicular Bisector Try a point directly above or below the midpoint of the rod. Try yo =1 m above the midpoint. Do your results make sense? Explain. How doesthe field vary as you move away, say 2 m, 4 m, 8 m, 16 m above the midpoint? What about directly below the midpoint? Does this make sense? Assignment S3_INTVAR: Variable Charge Density Finally, let’s look at a non-constant charge density. For this problem let the rod be on the x-axis between a=1 and b=3 m (a longer rod than before). The charge density is given by (x) 0 2 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. Physics on the Computer: Spreadsheet (version Spring 2007) Page 14 of 18 Solving Simultaneous Equations A. An electric circuit problem For the circuit shown find the current flowing in each branch. All potential differences in volts and resistances in ohms. V1 15 R1 4 r1 2 V2 6 R2 3 r2 2 V3 4 r3 1 R1 r1 R2 I3 r3 r2 I2 I1 Kirchoff's laws Look at a junction and get: I1 I3 I2 V1 V3 V2 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 B. Solving a set of simultaneous equations These are now in the standard form for simultaneous equations: 1 1 1 I1 0 M C V 6 0 1 I2 11 where M is the matrix of the current coefficients, C is 0 5 1I3 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 . 1 So now we need to enter M and V into a spreadsheet and find M . Then we can multiply 1 V by M and get C. The matrix inversion and multiplication operations are built into Excel. Solution Look at the screenshots on following pages as we go through the steps. After setting aside space for information at the top of your sheet enter the matrix of current coefficients, M, into a 3x3 block of cells. Adjacent to that put the potential matrix, V. (It can actually go anywhere, but for clarity make it look like the problem you are trying to solve.) Now select (highlight) a 3x3 region to hold M-1. In the equation input area type "=minverse(cells of your M matrix)" and then use "command (apple key) + return" instead of "return" on MAC or "command+shift+return" on PC. Physics on the Computer: Spreadsheet (version Spring 2007) 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". Physics on the Computer: Spreadsheet (version Spring 2007) Page 16 of 18 After entering the above formulas your spreadsheet should look like these. Physics on the Computer: Spreadsheet (version Spring 2007) Page 17 of 18 Assignment S6_SIM: Simultaneous Equations Now you can use your knowledge of circuits and your newly acquired simultaneous equation solving skills to do another one. For the circuit shown find R3 V2 R2 -the current flowing in R1, R2, and R3, - the power dissipated in each of the batteries. V1 R1 All potential differences are in volts and resistances are in ohms. V1 V2 12 9 R1 R2 R3 20 40 30 Physics on the Computer: Spreadsheet (version Spring 2007) Page 18 of 18