## Mac OS X Grapher – Using Parameters

Welcome to part two of my unofficial MacOS X Grapher User’s Guide – Using Parameters. As before, click on any graph to enlarge.

### I. Discrete Parameters

Discrete parameters allow you to systematically vary elements of your equation and see the effects on your graph. For example, suppose you’re studying cosine waves and want to see the effects of changing amplitude: In this equation the discrete parameter A is defined by the statement “A = {comma-delimited list of values}”. In essence, you are defining a FOR loop, telling Grapher to plot y=A*cosine(x) for each of the specified values of A. Parameter declarations are separated from the main equation (and from each other) by commas.

Note the little triangle appearing next to the equation in the equation list. Clicking on the triangle will give you a list of all the different parameter values, and allow you to access/modify each of the separate curves: You can also define parameters by themselves, without attaching them to the end of an equation.  Here we’re varying the phase shift of a cosine wave: The parameter declaration for the phase shift, B, was entered into the equation editor as a separate statement, “B:={parameter list}”. Grapher understands that such statements are variable declarations, and does not plot them. You can then define an equation using B on a separate line.

Grapher treats this kind of parameter declaration slightly differently than an in-line declaration.  A parameter defined in-line is considered a local variable, whereas a parameter defined on its own line is considered a global variable.  Local variables are recognized only within the equation in which they are defined. If I enter a second equation into the worksheet using A, Grapher will not recognize A, and complain that it is an undefined variable.  Global variables such as B, OTOH, can be referenced by any equation in the worksheet.

If your parameter varies by regular intervals, you can avoid the hassle of typing in each and every parameter value. Instead type in the first two values of the parameter, followed by an ellipsis (“…”), followed by the final value. Grapher will automatically increment the parameter by the desired step size: You can get fancy and use more than one parameter per equation. Grapher will faithfully plot your equation using all possible combinations of the specified parameters: Be aware that you can quickly reach large numbers of plots this way. For example, specifying three different parameters with 10 possible values each will result in 1000 plots.  If you specify >20 or so parameter combos, Grapher will give you a warning asking if you want to proceed.  If you insist, Grapher will endeavor to draw all the plots but can become slow and unpredictable.  Be prepared to watch the spinning beach ball, and save early/save often.

### II. Changing Color and Line Style

One of Grapher’s quirks is that it does not do auto coloring. If you define multiple curves on one worksheet, each curve is drawn in the same basic black. To change this, select the equation of interest in the Equation List, and open up the Inspector.  Here I’ve picked out one of the cosine waves (the one with a phase shift of π/4): The Inspector allows you to change both color and line style of the selected curve. Clicking on the Color box will bring up the standard Macintosh color chooser; clicking on the Line Style box will bring up a submenu that allows you to alter both line thickness and style (dashed, solid, dot dash, etc.).

If you define a family of curves using parameters, you can specify color and line style for the entire family by selecting the main equation.  Alternatively, you can select a group of curves via shift-click.

Grapher has another unfortunate quirk regarding coloring: if you modify the underlying equation, Grapher will reset all color/style information. So if, for example, I changed the cosine waves to sine waves, my painstakingly colored curves would revert to basic black. Therefore it’s best to do coloring last, after you’ve gotten your equation to look the way you want it.  You can get quite jiggety with it, if you’re so inclined:  One brief note about making “pretty” plots for public consumption.  Grapher has the annoying tendency to zoom in/out too much, making it difficult to get a plot scaled nicely within the frame.  This can be fixed using the View -> Frame Limits menu option: Look at the scale boxes, where it says “1 unit = xxxxx cm”.  Here unit refers to a unit distance on the plot, e.g., x from 0 to 1.  By altering how many centimeters are associated with each unit, you can fine tune the graph size to fit your window. Note that if you use different scales for the x and y axes, you will introduce distortions into your plot.

### III. Continuous Parameters, i.e. Parametric Equations

Grapher allows continuous parameters only in the context of parametric equations.  In parametric equations x and y are functions of a third variable (usually time): x(t), y(t). I always think of parametric equations as trajectories.  For example: Let’s analyze this equation. At time t=0, our putative particle (the red dot) sits at (x,y)=(2, 0). By time t=π/6, the particle has moved to (0, 2). It then loops around counterclockwise, reaching the same point again at time t=5π/6. As time continues to increase, the particle continues to trace out the curve, finally going back to where it started @(2, 0) when t=2π. To enter a parametric equation you need to use the Equation Palette. Go to Window -> Show Equation Palette. This brings up a a window showing a variety of symbols that you can use in your equations. Parametric equations are entered using vector notation as shown: The parameter t is specified with the statement “t = lower bound… upper bound”. As with discrete parameters, t can be declared globally by defining it on a separate line.

Tune in next week for a discussion of point sets and contour plots, plus how to add extras like arrows and text boxes.

This entry was posted in Grapher and tagged , , , , . Bookmark the permalink.

### 11 Responses to Mac OS X Grapher – Using Parameters

1. Andre says:

This is amazing, why did you stop??? Please, continue!! I’ve struggled with Grapher and wish I had seen your posts earlier, even in grad school it’s often more practical to use it in lieu of Mathematica or other powerful programs.

2. Martin says:

This was very useful, the only description of how to properly use Grapher I could find. I would be very grateful to see you go into the rest of the features.
Thanks!

3. theputterer says:

Thank you for your kind comments, and apologies for the delay in reply. I spent this summer locked in a cage match with my disability insurance company (Unum Provident, in case you’re looking for a company to avoid), and the stress has pretty much killed my writing mojo. I appreciate the positive feedback, though, and am looking for a way to move this project off the back burner. There were a lot more topics I wanted to discuss, and I definitely want to finish the Grapher series before moving on to something else.

4. Ira says:

I am wondering if grapher can perform data fitting of given points with equations and give back values of parameters.
Thanks.

• theputterer says:

That’s actually the topic of my next post, hopefully up this weekend. Short answer = yes. You need to go under Equation -> New Point Set, which will allow you to enter your own data points. The point set window has a tab called “Interpolation”, which offers options for fitting lines, polynomials, exponential curves, or custom curves to your data.

5. bobobobo says:

Very nice. How did you get it to apply the chromatic gradient to your equations?

• theputterer says:

LOL, it didn’t. I had to color them by hand.

6. Jo says:

How would you setup Grapher to plot a Riemann Sum?

7. Ari Tjahjawandita says:

I remember Graphing Calculator in pre OS X days has a capability to change a parameter using a slider. Unfortunately Graphing Calculator is no longer being develop. It only available for PPC. I hope Apple will add this feature plus auto coloring in the next version, being refine just like Preview app.

8. David says:

Although it seems to be possible to create many independent y= equations, I can’t find a way to use one equation within another. For example, do you know if it’s possible to do something like this?

g(x) = sin(x)
h(x) = cos(x)
y=g(x) + h(x)

Or even this: y=g(h(x))

9. Randy McMillan says:

z=Acos({x+a})+Bsin({y+b}),A=|_list_{1,2,3,4,5},B=1,a=A|_cdot_2,b=B|_cdot_2

z=Acos({x+a})+Bsin({y+b}),A=|_list_{1,2,3,4,5},B=1,a=A|_cdot_2,b=B|_cdot_2