Generating Mathematics—Change Playground |
Tutorials > Generating Mathematics—Change Playground This tutorial also focuses on using formulas to define new attributes, but this time we’ll work in a purely mathematical context, experimenting with change and how to calculate change using Fathom’s prev function.
Creating the CollectionHere, we don’t have data in the sense of observations; rather, we are working simply with some numbers.
5. Click OK to accept the formula and close the formula editor.
11. Change B’s pointSize to 8. 12. Close the inspector by clicking its close box.
Playing with Change 13. In the graph of A, drag point 3. You will see the value changing in the case table. The graph of B will also change. What points in B move? How do they move? Why? 14. Try to drag a point in B. You can’t change these values by dragging, because they are defined by formula. 15. Change the data in A to 10, 8, 6, 4, 2. 16. If necessary, rescale each graph so all the points show again, by selecting the graph and choosing Graph | Rescale Graph Axes. What does graph B show? Why does it show this? The screen shots below each show a set of data of B. Create each graph or table on your computer by changing the data for A.
Cumulative Sum Let’s make a new attribute, C, that is the cumulative total of A for each case. 17. Add the attribute C, giving it the formula A + prev(C). Note that it’s not A + prev(A), because that would add only two values of A rather than adding to the previous cumulative sum of A. 18. Make a line plot of C. What shape is this? Why? (There’s a calculus connection here: B is the derivative of A; C is the integral.)
Fibonacci Numbers Now that we’re used to how the prev function works in Fathom (there’s also a next function that takes the value of the next case), we can look at other uses, such as the Fibonacci numbers (1, 1, 2, 3, 5, 8, …). For this, we’ll start over, making another collection. 19. Scroll down in the Fathom window to give yourself a blank area. 20. Make a new, empty case table with an attribute called Fib. We need to use a formula that will result in the first two cases getting the value 1 and the rest of the cases getting the sum of the previous two numbers. For this, we need an if-statement. 21. Select Fib and choose Edit | Edit Formula. 22. Type if( When you type the open parenthesis, Fathom gives you a template for filling out the if statement. You want the first two cases to have the value 1. 23. Inside the parentheses, type caseIndex≤2. (To get the ≤ press Ctrl (Win) Option (Mac) and click the < button that appears on the keypad.) 24. Press Tab to get to the top result clause. (This specifies what value the cases that meet the condition get.) 25. Type 1 and tab to the next clause. For all cases that don’t meet the specified condition, we want the result to be the sum of the two previous values. 26. Type prev(Fib) + prev(prev(Fib)) So, the whole formula says, for the first two cases, give a value of 1; otherwise take the previous value and add it to the value before that. This construction is typical for a recursive definition: Use caseIndex in an if statement to define the initial condition. One fork of the if statement defines the initial values; the other defines the recursive step.
|