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, x(t) = -4.9t 2 + 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 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, =A9+$A$6 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 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 x(t) = -4.9t 2 + 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 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! 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.. Thermal Physics 301 computer assignment 1 Make sure to label axes and if you have several plots on the same graph, use a legend (otherwise eliminate the legend). Construct your plots in Excel and paste them in the document below where needed. Pick a data range that allows you to see the interesting behavior. Make sure that your plots make sense and the numbers seem reasonable. Then answer questions after your plot. Problem A: Produce a single P-V plot that shows four expansion processes for the gas H2. In your book (Schroeder) examine figure 1.13 to see the temperature ranges where the different degrees of freedom are active. Show an isothermal and adiabatic expansion for the three different regimes from the same starting conditions (Pi = 1 atm. Vi = 1 m3). What is different about these different plots? Does the isothermal plot change with temperature? Give a physical explanation for the differences. Problem B: Plot your results for P(z) (in units of atm.) from problem 1.16 with z from 0 to 9500 m, which is approximately the peak of Mt. Everest. Let’s assume that your result for P(z) from 1.16 remains true for a quantity of gas that is rising away from the earth. Assuming that the gas expands adiabatically as it rises, use equations 1.39 and 1.40 from the text to find T(z) of the gas up to the peak the peak of Mt. Everest. Assume a sea level temperature of 300K (room temperature). What happens to the temperature as the gas rises and why (use the 1st Law in your explanation)? How does this effect account for rain on one side of the mountain ranges (the western slope) and a desert on the other side (the east slope)? Note: This is different than the assumption in 1.40 where it is assumed that the pressure difference due to temperature and altitude are balanced. Problem C: The pressure of an ideal gas is a function of its volume and temperature. Construct a “3-D Surface” plot in Excel of P(V,T) with P in units of atm over a range of temperatures 200600K (steps of 20K) and volumes 0.1 - 2 m3 (steps of 0.1 m3) for 10 moles of gas. Using the same data from your plot find 𝑃(𝑇)|𝑉=0.2𝑚3 and 𝑃(𝑇)|𝑉=1𝑚3 on the same plot and 𝑃(𝑉)| 𝑇=300𝐾 and 𝑃(𝑉)| 𝑇=500𝐾 on the same plot. In a graphical sense, how do these two graphs relate to the 3-D surface plot you created? What do the partial derivatives (𝝏𝑷⁄𝝏𝑻)𝑽 and (𝝏𝑷⁄𝝏𝑽)𝑻 correspond to on your 3-D graph (you don’t have to compute them, unless you’d like to)? Problem D: You will create a 3D plot of diffusion as a function of x and t. Start by creating constants D = 1, x = 1, t = 0.1. Start your position at 0 in cell C9 and increment by x 20 more positions horizontally across your spreadsheet (e.g. i = 0, 1,… 20). In the next row, initialize your number of particles: from i = 0 to 10, N = 0, and from i = 11 to 20, N = 1. This starts us with a particle concentration entirely in one half of your space: we now want to compute how it will diffuse with time. Now make a column containing time starting at t = 0 in cell B10 and incrementing by t for 30 times going vertically down from this cell. Now we want to compute the number of particles Ni for each i increment and each t time. We will start by assuming that the number of particles N stays the same at the boundaries at i = 0 and at i = 20, so set these equal for all times in your spreadsheet. As we started in class, we compute the number of particles Ni(t+t) for each position index i at the next time (spreadsheet row) using the following equation that you will derive in problem 1.69: D é Ni ( t + Dt ) = Ni ( t ) 2Ni ( t ) - Ni-1 ( t ) - Ni+1 ( t )ùû Dt 2ë ( Dx ) Notice that you are computing the number of particles at the next time t+t, using the data on the number of particles from the previous time t. Be careful to make references to your original constants D, x and t all absolute references with the $ symbols. Propagate your equation to solve for Ni(t) for all t and i values. Now just select your entire spreadsheet region containing your Ni(t) data as well as your x and t values and make a 3D plot. You should now see the whole time evolution of your diffusing substance. Don’t forget to label your axes and you may want to rotate the 3D plot to look better (right-click the plot for PC, or Cntrl-click for Mac). Try altering your constants D, x and t. Explain what happens when you change each of these quantities. You will find if you change these too much, you will get wacky results. This is because your model is an approximation that is only valid for small changes in time and position. In general if DDt ( Dx ) < 0.4 , the plot should look good. 2 Try out some different starting conditions and generate a different plot of diffusion. You could even model diffusion to a surface by allowing flux to go to one of the boundaries. You would need to add an equation to the boundary instead of keeping it constant. Add one of your new 3D plots with different starting conditions in your report and qualitatively describe what happened.