Plotting Derivatives with Google Sheets Authors: Date: Anthony Billet, Scout Heck, Kamil Jiwa, and Eric Kammers August 21, 2016 Table of Contents ● Overview ............................................................................................................................................................................................................................................ 1 ● What You Will Need ........................................................................................................................................................................................................................ 2 ● Background ....................................................................................................................................................................................................................................... 2 ○ Derivatives .......................................................................................................................................................................................................................... 2 ○ Spreadsheets ....................................................................................................................................................................................................................... 3 ● Step 1: Creating a New Google Sheets Document ........................................................................................................................................................................ 4 ● Step 2: Setting Up the Data ............................................................................................................................................................................................................. 5 ○ Selecting dx ......................................................................................................................................................................................................................... 6 ○ Selecting the Domain ......................................................................................................................................................................................................... 6 ○ Filling in the Domain ......................................................................................................................................................................................................... 7 ○ Computing the Range ........................................................................................................................................................................................................ 9 ○ Computing dy/dx .............................................................................................................................................................................................................. 10 ● Step 3: Creating a Graph ................................................................................................................................................................................................................. 11 ● Conclusion ....................................................................................................................................................................................................................................... 15 ○ Applications ....................................................................................................................................................................................................................... 15 ○ Trendlines .......................................................................................................................................................................................................................... 16 ● References ....................................................................................................................................................................................................................................... 16 Overview Expected time to complete: 15 minutes. Plotting Derivatives with Google Sheets 1 of 16 Derivatives can be tricky business, but they are crucial to our understanding of the physical world. Rates of change show up everywhere in nature and, perhaps more importantly, in our homework. Derivatives can seem very complicated, even abstract, at rst. When learning calculus, it is helpful to visualize the derivatives. This way you can see what the derivative looks like, and, when plotted with the original function, what the relationship is between the two. Understanding how functions and their corresponding derivatives relate is key to wrapping your head around calculus. Google Sheets is an excellent tool for visualizing derivatives. It is an online spreadsheet very similar to Microsoft Excel, in which you can input data, perform calculations, create graphs, and perform many other great actions. Because the sheet is online, you can also collaborate with others working on the same project. If you are a STEM major or use calculus for your work, research, or classes, then this document is for you. The technique described below can help you visualize derivatives and produce graphs for use in your documents without the need for a fancy computer algebra system. What You Will Need Ὃ f (x) A computer. Either a laptop or desktop computer will suᨀЀce. These instructions are not suitable for the mobile version of Google Sheets. A Google account to access Google Sheets (e.g.
[email protected]). Create your own Google Account by visiting https://accounts.google.com/. A function for which you would like to nd the derivative. These instructions cover functions of one variable (e.g. f (x) or f (t) , but not f (x, y ) or f (x, y , z ) ). We will be using the function y = 2x2 + 9x + 4 in these instructions, but you may choose any function you wish. Background -Derivatives. The derivative of a function is a representation of how it changes. You might be familiar with the following notation: dy dx = 4x + 9 . But what does this mean? Plotting Derivatives with Google Sheets 2 of 16 dy This symbol represents how much the y value changes. dx This symbol represents how much the x value changes. 4x + 9 This is a mathematical expression of the derivative. Together, the notation represents a rate of change. If you are familiar with a slope, then you can think of a derivative as the slope when the x interval is extremely small, i.e. the slope at a particular point. The derivative tells us how much y changes when x changes by some innitesimally small amount and gives us a mathematical expression that we can use to determine the value for this rate of change for a given value of x. The “d” before the y or x is representative of the “delta y” or “delta x,” meaning the change in y or change in x. In these instructions, we start with a mathematical function and use Google Sheets to help us plot its derivative. There are many established algebraic methods that can be used to determine a derivative. It is not necessary to know those methods for these instructions, but interested readers may wish to reference the following resources: ● Paul’s Online Math Notes on Derivatives: http://tutorial.math.lamar.edu/Classes/CalcI/DerivativeIntro.aspx ● Khan Academy on Taking Derivatives: https://www.khanacademy.org/math/di䀌erential-calculus/taking-derivatives ● James Stewart’s textbook, Calculus: Early Transcendentals: https://www.amzn.com/0538497904 -Spreadsheets. Some basic familiarity with spreadsheet software such as Microsoft Excel or Google Sheets is helpful, though not strictly required. Spreadsheets are computer programs used to store, organize, and analyze data sets in a tabular form (Wikipedia, 2016). There are many classroom, book, and online resources available discussing spreadsheet software. Readers interested in learning more about spreadsheets may wish to reference the following resources: ● Excel Easy: http://www.excel-easy.com/ ● Goodwill Community Foundation on Google Sheets: http://www.gcḠᨠearnfree.org/googlespreadsheets/ Plotting Derivatives with Google Sheets 3 of 16 Step 1: Creating a New Google Sheets Document First, you’ll need to login to Google Drive and create a new Google Sheets document. With your web browser, visit https://drive.google.com/. You may be asked to sign in to your Google account. Figure 1: An URL eld with the URL for Google Drive within it. This eld is at the top of your web browser. Once you are within Google Drive, on the left-hand side of the web page you will see a big red button with the text “NEW” written across it. Click the “NEW” button. A drop-down menu will appear beneath the button with several options for di䀌erent document types you can create. Select “Google Sheets.” Figure 2: The new document selection menu. We will be creating a new Google Sheets document. After selecting “Google Sheets” from this menu, you will be automatically directed to your new document. Plotting Derivatives with Google Sheets 4 of 16 Step 2: Setting Up the Data At this point you should be staring at a shiny new Google Sheets spreadsheet. Across the top you should see column headers such as “A,” “B,” “C,” etc. and along the left you should see row headers such as “1,” “2,” “3,” etc. We can use these headers to reference individual cells. For example, the cell in the top-left corner has the name A1 while the 2nd cell from the left in the 4th row has the name B4. Figure 3: A new Google Sheets document. Columns will have headers A to Z and rows will have headers 1 to 1001. You’ll notice your spreadsheet defaults to having the title “Untitled Spreadsheet.” It’s okay to keep it that way, but if you wish to change it, click on the title with your mouse and change it by typing in a new title over the old one. We will begin by adding column headers to our spreadsheet. Plotting Derivatives with Google Sheets 5 of 16 ● ● ● ● In cell A1, enter “x.” Column A will contain our x values, or the domain. In cell B1, enter “y.” Column B will contain our y values, or the range. These will be computed based on the function we have chosen. In cell C1, enter “dx.” Column C will contain the size of our x intervals. There will only be one value in this column. In cell D1, enter “dy/dx.” Column D will contain approximate values of our derivative. Figure 4: Row headers for our spreadsheet. The headers are optional, but help us to organize our data. -Selecting dx. Now that our column headers are set up, we need to choose a value for our x interval, or “dx.” It helps to use a small value for this, because the smaller the value, the more accurate Google Sheets will be at plotting the curve. We will use 0.01 and input this value into cell C2. Figure 5: The value for dx will be in cell C2. Smaller values will yield more accurate results. -Selecting the Domain. Next we need to select our domain (our x values). For our function, we are going to use a relatively small domain from -2 to 2, because this is the portion of the graph we are interested in. In practice feel free to use whatever size domain you like, just know that a larger domain will mean using up more rows of data in your spreadsheet. Start by entering the start value for the domain in cell A2. For the domain -2 to 2, the start value is -2. Figure 6: The start value for the domain will be in cell A2. The end value will be automatically lled in after the next step. Plotting Derivatives with Google Sheets 6 of 16 -Filling in the Domain. With our initial x value and interval (dx) dened, we can ll in the rest of our domain (x values). To do this, use your mouse or keyboard to select cell A3 and type in the following equation (without quotes): “=A2+$C$2.” It is IMPORTANT to put the dollar signs around the second part ($C$2) but not around the rst part (A2). This is to make sure Google Sheets will read your function correctly, using multiple x values and one dx value. You will notice that a numerical value appears above the cell as you type. In the image below, this value is -1.99. This is Google Sheets’ way of giving you a hint about the value that will appear in that cell. Figure 7: Entering an equation to ll in the domain. The numerical value that appears above it provides us with a hint of the value that will populate that cell. After entering the equation, press Enter. You will notice that a numerical value appears in place of the equation. However, if you highlight the cell, the equation bar will show you that the equation you entered is still present. The equation enables the cell to dynamically update its value based on the initial x value and the x interval we have chosen. Figure 8: The value in cell A3 automatically takes on a numerical value. The equation bar above shows us the equation is used to compute this value. Notice that the value that appears in cell A3 is our initial x value plus the x interval (dx) value. In our example, -2 + 0.01 = -1.99. If we repeat this process, our next values will be -1.98, -1.97, -1.96, etc. To reach our end value, 2, we’ll need to repeat this process 400 times (-2 + 400 * 0.01 = -2 + 4 = 2). You’ll need to determine the number of times to repeat this process for your own domain by using the following formula: f inal x value − initial x value repetitions = dx Plotting Derivatives with Google Sheets 7 of 16 For the domain -2 to 2 with an x interval of 0.01, this value is: repetitions = 2 − (−2) 0.01 = 400 With this number in mind, highlight the cell A3 with your mouse. Take particular note of the solid blue square in the bottom-right corner. When you hover your mouse cursor over this blue square, you will notice it turns into a + (plus) symbol. To ll the remaining domain values, click the solid square with your mouse and drag down by the number of repetitions. For 400 repetitions, we drag from cell A3 to cell A402. It’s okay to go beyond that cell--you can always delete the extra values. Let go of the mouse cursor once you’ve dragged to or beyond the number of cells determined by your repetition count. Figure 9: Filling the domain by clicking the solid blue square in the bottom-right corner of cell A3 and dragging down. We drag down by a predetermined number of rows. You will notice the additional values are automatically lled in once you complete this action. Plotting Derivatives with Google Sheets 8 of 16 Figure 10: After completing the click-and-drag process, our domain will be lled with values incremented by the x interval (dx) up to our nal x value. -Computing the Range. We will follow a similar process to ll in the range (y values) as we used to ll in the domain (x values). Instead of entering a xed value, we will enter the equation for our function into cell B2 and then follow the same click-and-drag procedure as we used to ll in the domain. The table below shows a few common mappings between mathematical expressions and their representations in Google Sheets. Here, we assume the x values exist in column A and reference a specic value in cell A2. Expression Google Sheets Representation f (x) = 2x =2*A2 f (x) = x2 =pow(A2,2) f (x) = ex =exp(A2) f (x) = sin(x) =sin(A2) f (x) = log 2 (x) =log(A2,2) f (x) = ln(x) =ln(A2) f (x) = x2 + 2x + 1 =pow(A2,2)+2*A2+1 Table 1: Common mathematical expressions and their representations in Google Sheets. Plotting Derivatives with Google Sheets 9 of 16 Google Sheets supports over 300 functions. A comprehensive list can be found here: https://support.google.com/docs/table/25273. To enter our function, f (x) = 2x2 + 9x + 4 , rst highlight cell B2 and enter the value, “=2*pow(A2,2)+9*A2+4,” and press Enter. Just as when we lled in our domain, the equation will be replaced by a numerical value--in this case, the value in cell B2 will be -6. Figure 11: Entering our equation into the rst value of our domain. With cell B2 highlighted, position your mouse cursor over the solid blue square in the bottom-right corner of the cell, click, and drag your cursor down to match the x column. Once you have reached your end row, release the mouse and your range will be lled in. Figure 11: After completing the click-and-drag process, our range will be lled with values computed from our function equation. -Computing dy/dx. Hopefully by now you’re getting the hang of this click-and-drag process. We have just one more column to ll in before we can move to the next step, and that is the column containing our derivative estimate values. The values we compute are simple approximations of the derivative based on the equation for the slope of a line segment: y − y 1 slope = 2 dx Plotting Derivatives with Google Sheets 10 of 16 Since we need two values from our range, we will skip a row and begin entering values in row 3. Begin by highlighting cell D3 and enter the value, “=(B3-B2)/$C$2” and press Enter. It is important to make sure you enter the parentheses correctly as shown. Figure 12: Computing the derivative in cell D3. The value is an approximation of the derivative at this point and is based on the equation for the slope of a line segment. To ll in the remaining values, highlight cell D3 and repeat the click-and-drag process that we used to ll in our domain and range--place your mouse cursor over the solid blue square in the bottom-right corner of the cell and drag down to row 402. Upon releasing the mouse button, cells D3 to D402 will be lled with our estimated derivative values. Figure 13: After completing the click and drag process, our derivative values will be lled with values computed from our slope equation. Step 3: Creating a Graph Whew! That was a lot of work! Don’t worry, the hardest part is over and the fun is about to begin. The next step is to insert a chart to graph both our original function and our derivative. To create a graph, we must rst select the data we want to be in our graph. To do this, click on cell A1 and drag all the way down and over to cell D402 (or whichever cell contains your last value). Plotting Derivatives with Google Sheets 11 of 16 Figure 14: Selecting all of the data for the chart Now, to insert a chart, look in the menu bar for a button that looks like a bar graph ( highlighted, click the “Insert chart…” button to bring up the “Chart Editor” dialog. ). This is the “Insert chart…” button. With your data still Figure 15: The “Insert chart…” button is located in the menu bar as shown above The Chart Editor o䀌ers many options for types of charts to use. A “scatter plot” is the correct type of chart to use for our purposes. Plotting Derivatives with Google Sheets 12 of 16 Figure 16: The Chart Editor. In addition to a selection of chart recommendations and a preview of your chart, you will also notice a text eld beneath the “Recommendations” tab. Ensure that it contains the text “Sheet1!A1:D402.” You may need to adjust the value if you have a di䀌erent number of repetitions (e.g. the value may be something like “Sheet1!A2:D652”). To change the chart type to a scatter plot, click the “Chart types” tab at the top of the Chart Editor. There will be an area showing the various chart types that can be used. Scroll down in this area and select the “Scatter” chart. Plotting Derivatives with Google Sheets 13 of 16 Figure 17: The “Chart types” tab. This section contains a comprehensive list of supported charts. We select the “Scatter” chart type. Now click the blue insert button and scroll to the top of your spreadsheet. You should see the beautiful graph you just created! Ἰ Congratulations! Ἰ To move the graph away so that it doesn’t cover your data, click on the blank space of the graph and drag it somewhere where there is space. Plotting Derivatives with Google Sheets 14 of 16 Figure 18: A graph showing the original function in blue and the derivative in orange. That’s it! The orange line, dy/dx, is your derivative and the blue line is your original function, f(x). Pat yourself on the back, you did it! Conclusion Visualizing derivatives is very helpful for learning calculus. Being comfortable with the graphical relationship between the two will aid in your understanding of their physical and numerical relationships. Applications. Derivatives are fundamental to calculus and physics. Now that you know how to plot rst derivatives, you can use the same technique to plot second derivatives. This is useful in physics because velocity ( v (t) ) is the rst derivative of position ( x(t) ) and acceleration ( a(t) ) is the derivative of velocity (or the second derivative of position). Plotting Derivatives with Google Sheets 15 of 16 v (t) = dx dt and a(t) = dv dt = d 2 x dt 2 Trendlines. Google Sheets is equipped with the ability to develop trendlines for the graphs you make. If you would like to take these instructions a step further, consider adding a trendline to estimate the equation of the derivative you just graphed. References Spreadsheet. (2016, July 19). In Wikipedia. Retrieved August 10, 2016, from https://en.wikipedia.org/wiki/Spreadsheet Plotting Derivatives with Google Sheets 16 of 16