Formula Calculator for iPhone

Index > Arrays and graphs

A graph is a good way of understanding the nature of a function or a formula. Creating a graph requires a means for calculating an array of ordered pairs of numbers (x, y), with each pair containing a value of the variable x and the corresponding function value y=f(x). To enable functions to be graphed, Formula calculator parameters can be configured with a range of values. All functions operating on the parameter detect that it contains an array. The functions operate on each array element and return another array as a result. The two arrays then form the ordered pairs that are then very simple to plot.

Creating a range (array) of values: A parameter with a range of values is created using the range(start,stop,step) function, where start is the first value, stop is the last value and step specifies how much the parameter value is incremented. For example x=range(0,1,0.2) creates a parameter x which contains an array with values 0, 0.2, 0.4, 0.6, 0.8, 1.0. Note that if stop-start is not a multiple of step then the last value in the array will be less than stop. As an example, y=range(2,7,1.5) creates an array with values 2, 3.5, 5, 6.5

Formula calculator tries to rationalise the start, stop and step values to be consistent. If start>stop and step>0 formula calculator will swap the start and stop values.

Interval notation: You can also create a range of values using square brackets in the form [start, stop, step]. An example is x=[0,1,0.2]. Formula calculator converts this into x=range(0,1,0.2).

Viewing array elements: Since arrays usually contain many numbers, Formula calculator does not show you the array contents, but lets you know the parameter is an array. For the above example we would see x=<array>. You can access array elements using the element(x,n) function that returns the n-th element of the array.

Functions of arrays: Formula calculator recognises when a parameter contains a range of values and applies the function operation to each element of the array. The result is a parameter containing another array. You can also add arrays, subtract them, and so on, to create new arrays. The operations are done between elements at the same location in each array. This requires the arrays to have the same number of values.

Plotting functions: Plotting functions is simple using arrays. If you have a function f(x) that you wish to plot, first create an array of x values using x=range(...), then type plot(x,f(x)). Formula calculator takes the values in the two arrays x and f(x) and plots the points in a graph, which is automatically displayed. The graph appears on a chart, which is the graph plus axis labels, a legend, and so on. The chart allows you to examine the values in the graph, as well as apply a large number of graph formatting options. Details on charts are found in the Charts and graphs page.

Many graphs can be plotted on the chart. Every time Formula calculator encounters a plot() function, it creates another graph on the chart. You can use multiple parameters in the plot function. For example plot(x,a,b,c) will plot arrays a, b and c against x.

Note: Formula calculator accumulates the plot commands and only creates the graphs at the end of the sequence of calculations. Any pair of array parameters can be plotted, but their arrays must be of the same length.