You are on page 1of 12

Grapher

Grapher is a program that graphs a set of equations. It can graph an equation in any dimension
above (but not including) the first. Once an equation is graphed, the user can rotate it, view
the point coordinates making up the object, and highlight individual points on it.

This is an educational program. The intent is to provide a way to help people visualize and
explore how algebra relates to geometry in multiple dimensions.

Syntax Overview

Grapher reads the main edit window line, by line. Each equation, declaration, and directive
must be separated by a carriage return (When you press ENTER or RETURN). Directives and
variable declarations affect only the equations and expressions that are given after them.

Grapher ignores the case (capitalized & lowercase) of a character. White spaces are generally
ignored. Grapher will not, however, accept a constant, function, or variable name with a space
in its name.

Grapher automatically sets the angle measurement to radians, defines three variables, and sets
the axes as shown below.

Equations

Equations are the backbone of Grapher. They are used to create the graphs and assign values
to variables.

While equations can be written in the form ‘expression=expression,’ in Grapher you must
write them in the form ‘variable=expression.’
Where:

variable A predefined variable.


expression Representing a value, expression can be made up of constants, operators,
functions, and variables.

If variable is assigned to an axis, then a graph will be plotted from the equation. To assign a
value to this axis variable, you must redefine it like this:

var variable = expression

If variable is not assigned to an axis, then variable will be set to equal the expression.

Ejemplo:

y = z^2 + x^2 - cos(z + x)

var y = 0 to 2*pi step 80

var z = -5 to 5 step 80
x = (50-y^2-z^2)^5

The Operators

Operators are used to manipulate numbers. Here are the supported operators:

* Multiplication 1*2, a*b, z*3, …


/ Division 2/3, a/b, d/5, 20/s, …
+ Addition 5+6, b+a, c+3, h+3, …
- Subtraction 2-9, c-x, g-7, …
^ Raise to a power 2^3, 9^(1/2), 1.2^1.5, …

Constants

Constants are just like variables, but their value cannot be changed and they cannot be
redefined as a variable. There is currently no way to define your own constants.

There are only two constants:


pi = 3.14159265358979323846264338327956
e = 2.71828182845904523536028747135266

Grapher performs the calculations with higher precision than what it uses for graphing, so
when you look at the point set window, displaying the coordinates of each point, the precision
will be lower.

Variables

Variables are names that refer to a value. They can be used in a couple of ways, like for
representing the value of an axis, making equations more readable, and easier to create.

You may redefine any variable at any location within you project. Any declaration, however,
only affects the equations and expressions that follow.

The declaration of a variable follows this form:


var varname [= start [to stop]] [step segments]

Where:

Varname The name of the variable. This name must start with an alphabetical character.
Afterward, the name may contain other symbols and numbers. The name MAY NOT contain
an operator (*,/,+,-,^) or a white space. Names used for constants and functions are
unacceptable.
Start The initial (minimum) value of the variable. When plotting a graph, the variable first
equals start.
Stop The ending (maximum) value of the variable. If stop is equal to start, then the
variable’s value will not change in the course of generating a graph. If it is specified, by the
end of the graph generation, the variable will equal stop. If stop is less than start, then the two
values will be swapped, so that start has the lowest value. If stop is not specified, then stop
will equal start.
Segments Specifies how many times the variable should be incremented in the course of
plotting a graph. Or how many steps should be taken to reach stop. The variable will increase
by (stop - start) / segments. The variable will be incremented for each point generated, and
then reset when its stop value has been reached. Segments must be a positive integer, greater
than 0. The default value is 1.

Example:

var x = -5 to 5 step 20

var pear = -5

var wave = 0 to 10

var wave step 9 //Redefines wave with a step of 9


var cir = abs(1-foo) to 2*pi step abs(round(cos(z)*5))

You can also access the member values of a variable. To do this, append a period (.) to the
variable, and then add the member name. This can come in handy when specifying colors.

Supported member values:


min The starting value of the variable.

max The ending value of a variable.


steps The steps taken between min and max.

Example:

x = var.min*y

rgb(y/|y.max-y.min|,0.25,0.15)

Directives

Directives only affect the equations that follow.

Coordinate Systems

There are four different coordinate systems supported: Cartesian, cylindrical, spherical, and
polar. All but cylindrical coordinate systems may be extended to and dimension equal to or
above two. Cylindrical coordinates, however, are limited to only three dimensions. Polar and
Spherical coordinates are NOT treated the same.

crt(axis1, axis2 [, …, axisn])


sph(ang1 [, …, angn], radius)
plr(radius, ang1 [, …, angn])
cyl(radius, angle, z)
Each parameter should be a variable to represent that axis, angle, or radius.

Grapher automatically sets variables ‘x,’ ‘y,’ and ‘z,’ to axis1, axis2, and axis3 like this:

crt(x,y,z)

If a variable that is being associated with an axis or angle has not already been defined, it will
be defined and given default parameters when the coordinate system directive is parsed. The
variable can then be used following the directive, but not prior to it, since it has only been
defined at the point of the directive.

Example:
crt(MyXAxis,MyYAxis,MyZAxis)
sph(alpha,beta,omega,radius)
plr(A,B)
cyl(rad,ang,Z)

Color

The variables given within the parameters must have already been defined before the color
declaration.

rgb(red,green,blue)

Specifies how the graphs should be colored. Red, green, and blue can be between 0 and 1. If
they are specified as being negative, then Grapher will use the absolute value. If the value is
above 1, then it is treated as 1.

cmy(cyan,magenta,yellow)
Specifies how the graphs should be colored. Cyan, magenta, and yellow can be
between 0 and 1. If they are specified as being negative, then Grapher will use the absolute
value. If the value is above 1, then it is treated as 1. CMY is the inverse of RGB.

yiq(luminance,I,Q)
Specifies how the graphs should be colored. Luminance, I, and Q can be between 0
and 1. If they are specified as being negative, then Grapher will use the absolute value. If the
value is above 1, then it is treated as 1. I specifies the color between red and orange, where
red is 0. Q is the chrominance.

Example:
rgb(x/|x.max-x.min|,y,z)
cmy(sin(y)*2,z,x)
yiq(.5,sin(z),y/|y.min-y.max|)

Mode

mode modename
‘mode’ tells Grapher which mode to be in.

Supported modes (modename)


rad Use radians.
radians Use radians.
deg Use degrees.
degrees Use degrees.
grad Use gradients.
gradients Use gradients.

Example:
mode rad
mode degrees

Functions Overview

There are 35 different functions available in Grapher. To use these functions, simply put them
into the mathematical expression like you would a variable. After typing the function’s name,
type an opening bracket to give Grapher the parameters. If a function has more than one
parameter, a comma must separate each parameter. Valid parameters would include a
function, a constant, a variable, or an expression.

By default, Grapher uses radians whenever angles are concerned. See the declaration, ‘mode,’
for information on how to change this behavior.

Examples of using functions:


x = cos(y) + sin(z)*2
y = mod(z,x+1)
abs(cos(1*2+pi)*y)

You can use these functions wherever you can use an expression. For example, you can use a
function in a variable declaration, in the rotation window, or as another function’s parameter.

Graphing Window

The graphing window displays all of the graphs from your equations. You will find it on the
bottom of the main window. To rotate your view, open the rotation window. When this
window is open, you can rotate your view by clicking the arrows, dragging left to right, or by
double clicking the arrows. To save a snapshot of your graphs, go to the Export Graph menu,
under the File menu, and select “to Bitmap.” To work with the graphs outside of Grapher (in a
3D editor, modeler, or viewer) export the graphs as an AutoDesk 3D (*.dxf) file. If you need
to work with the vertex coordinates directly, then export to a text file (*.txt).

Math GV
Overview of Capabilities
MathGV is a software program designed to generate graphs of mathematical functions. It can
not plot raw data points. It can plot functions only.
1. Plots 5 function types; 2D Cartesian (X, Y), parametric, polar, 3D Cartesian (X,Y,Z), 2D
function rotated into 3 dimensions.
2. Graphs can contain multiple functions.
3. All graphs are drawn on resizable bitmaps, and displayed in scrolling windows.
4. Graph bitmaps can be copied and pasted into other programs, or saved to disk.

5. Multiple document interface (MDI) allows for simultaneous viewing of multiple graphs.
6. Can calculate negative numbers to fractional powers.
7. Function calculator that can give decimal or fractional results.
8. All changes take effect immediately after they are made.
9. Use tool bar buttons to zoom, rotate, and page up, down, left, right.
10. Graphs can be saved in bitmap (bmp), jpg or MathGV format.
11. Label tool bar for drawing, lines, free hand lines, rectangles, circles, round rectangles,
flood fills, and text.

12. Labels can be selected, dragged, dropped, resized, added and deleted on any graph at any
time.

Dimensional Cartesian Graphs


The Cartesian coordinate system is named after its chief inventor Rene Descartes (1596-
1650). This system is also referred to as the "Rectangular Coordinate System". To create a
new 3D Cartesian graph select the "File / New 3D Cartesian" menu item. Two different types
of functions can be added to a 3D graph.

2D function rotated into 3D


This function type is created by rotating a 2 dimensional function around an axis. In this
example the 2D parabola "Y = X^2" is rotated about the "Y" axis.

3D Function
This function type is created by plotting function points with three variables (X, Y, Z). These
functions have one dependent (range) variable and two independent (domain) variables. The
dependent variable may be "X", "Y", or "Z". In this example "Y = X^3"; "Y" is the dependent
variable, and "X", "Z" are the independent variables.
Mathematical Expression Rules

Constant Expressions
Constant expressions are subject to the same syntax rules as function expressions, but may
contain no variables (X, Y, Z, Theta). All constant expressions are simplified/calculated, and
appropriate error messages are displayed before a dialog closes.

Examples
-13.5601
6.50*10^3
(3*Pi)/2
E - 8.3
Ln(2(4 + 3))
Sin(Pi/2)^2 + Cos(Pi/2)^2

Function Expressions
Function expressions must follow the standard mathematical definition of a function. For a 2
dimensional function, each domain value (X), is given a single range value (Y). Graphing an
equation that is not a function such as "1 = X^2 + Y^2" (Equation for a circle with radius 1)
must be done in two separate pieces. Solving this equation for "Y" gives two results "Y =
+Sqrt(1 - X^2)", and "Y = -Sqrt(1 - X^2)". Plotting both of these halves creates a whole
circle. When entering a function such as "f(x) = x^2",or "Y = x^2" enter only the right side
"x^2".

Examples
When entering a function do not enter the bold left hand side.
Y=f(x)= x^2 - 1
R= 4Cos(2*theta)
Y=f(x,z)= x^2 + z^2
Fractional Results
The Function Calculator can often give fractional results like "7/5" or "2/3". These fractional
results are also used to calculate negative numbers to fractional powers. There are some things
that will cause rounding. If rounding occurs, a floating point value like "0.333333" will be
given instead of "1/3". Most functions will cause rounding. Functions that might not cause
rounding are: Exp(), Grint(), Int(), Sqrt(), Square(), Trunc( ), Round(), Frac(), Abs(), Fact().
Fractions where the numerator or denominator is greater than 1.5 trillion or less than –1.5
trillion can cause rounding.

Syntax Rules
MathGV supports all of the most common expression syntax rules used in mathematics. Many
of these such as implied multiplication are not commonly supported by computer
applications.

Order of Operations - Mathematical operations are evaluated using the standard order of
operations. All operations on same level are done from left to right.

1. Operations in parentheses "(", ")" are done first.


2. "^" Exponents. Done from left to right, not right to left.

3. "*", "/" Multiplication and division.


4. "+", "-" Addition and subtraction are done last.

Exponentiation "^" is also done from left to right. This means that the expression "2 ^ 3 ^ 4"
will be evaluated as "(2 ^ 3) ^ 4". If three to the fourth power needs to be done first, then the
expression must be written as "2 ^ (3 ^ 4)".

Grouping - the grouping characters "( )", "{ }", and "[ ]" may all be used interchangeably.

Functions - A large number of standard predefined mathematical functions and their inverses
are supported.

Function Arguments Must Be In Parentheses - Predefined function arguments must be


enclosed in parentheses. The expression "Log X" is illegal, it must be written as "Log(X)".
Examples
ln(x)
sin(2pi + 1)
exp(ln(x + 2))

Scientific Notation - Standard scientific notation (where 6500 = 6.50E+03) is not directly
supported. The character "E" is defined as the constant value 2.718. The expression
(6.50E+03) will not cause an error. It will be evaluated as (6.50*2.718+3) giving a result of
20.667, not the 6500 that scientific notation would give. Scientific notation can be written
using the form (6500 = 6.50*10^3) or for small number (0.0065 = 6.50*10^-3).

Constant Values PI and E - The predefined constant values PI and E are supported.
PI = 3.14159265358979
E = 2.71828182845905 = EXP(1.0)
Implied Multiplication - Implied multiplication notation is supported. When two variables,
constants, numbers, etc. are written with no operation between them a multiplication "*" is
implied. The following is a list of equivalent legal examples.

Implied Not Implied


2x 2*x
2Pi 2*Pi
3.5x^2 - 1 3.5*(x^2) – 1
X(3 – y) x*(3 - y)
(x – 1)(x + 1) (x - 1)*(x + 1)
Ln(x - 1)x Ln(x - 1)*x
XLn(x - 1) x*Ln(x - 1)
Double Negatives, and Positives - The following expressions are legal. They are simplified
when the expression is evaluated.

Legal Expression Simplified Equivalent


X--2x+2
3 + + x3 + x
4+-x4–x
X-+-+-5 x–5
Negative Numbers to Fractional Powers - Negative numbers to fractional powers are
supported. The exponent can not be a rounded number. Functions like Sin() and Sqrt() can
cause rounding. Fractions where the numerator or denominator is greater than 1.5 trillion or
less than –1.5 trillion can cause rounding. See the Fractional Results section above for more
information.

Factorials - Factorials using the "3!" notation are not allowed. The "Fact(x)" function allows
only integer values in (0 <= X <= 20).

Blank Spaces - All blank spaces in mathematical expressions are ignored.

SURFER

Grid Function

The Function command allows you to create a grid [.GRD] file from a user-defined two
variable equation of the form Z = f(X,Y). The density of the generated grid is a function of
the Minimum, Maximum and Increment values for both X and Y.

For example, consider the values listed below that would generate a 10 by 10 grid.

Minimum X = 1
Maximum X = 10
X Iterations = 1

Minimum Y = 1
Maximum Y = 10
Y Iterations = 1

These conditions result in 10 rows and 10 columns in the output grid file. There are a total of
100 grid nodes created when these limits are specified. The nature of the surface generated is
a result of the input function.

The Grid Function Dialog Box

When you choose the Function command from the Grid menu the Grid Function dialog box is
displayed.

* The function edit box allows you to Enter a function of the form Z = f (X,Y). The
function calculation is repeated one time for each Z value to be written to the output grid file.
The number of grid nodes in the output grid, and therefore the number of calculations to be
performed is based on the Minimum, Maximum and Increment values specified.
You can use any of the mathematical functions included with Surfer for Windows.
* The Minimum X and Y edit boxes specify the beginning values used in the specified
function. These values are plugged into the defined function and the first grid node is
calculated based on these values. These values also specify the lower limits for X and Y in
the output grid file.
* The Maximum X and Y edit boxes specify upper values to be applied to the function
and the upper X and Y limits for the grid.

* The Increment edit boxes specify the step between X and Y values for each grid line in
the output grid. The grid node Z values are calculated by successively changing the X or Y
values by the increment value and performing the function for all possible values of both X
and Y.
* The Output Grid File group specifies the path and file name for the grid [.GRD] file to
be created. If you want to change the path or file name, click the Browse button and specify
the new information.

Mathematical Functions

The following built-in functions are supported.

Trigonometric Functions

sin(x) sine
cos(x) cosine
tan(x) tangent
The value of x must not be an odd multiple of pi/2.
asin(x) arc sine
Values are in the range -pi/2 to pi/2.
The value of x must be between -1 and 1.
acos(x)arc cosine
Values are in the range 0 to pi.
The value of x must be between -1 and 1.
atan(x) arc tangent
Values are in the range -pi/2 to pi/2.
atan2(y,x) arc tangent
The values of x and y must not both be zero.

Values are in the range -pi to pi.

Bessel Functions

j0(x) Bessel functions of the first kind at x


j1(x) of orders 0, 1, and n, respectively.
jn(n,x)

y0(x) Return the Bessel functions of the second kind


y1(x) at x, of orders 0, 1, and n, respectively.
yn(n,x)For y0, y1, and yn, the value of x must not be negative.

Exponential Functions

exp(x) exponential function of x (e to the x)


sinh(x) hyperbolic sine of x.
cosh(x) hyperbolic cosine of x.
tanh(x)hyperbolic tangent of x.
log(x) natural logarithm of x.
The value of x must be positive.
log10(x) base 10 logarithm of x.
The value of x must be positive.
pow(x,y) x raised to the y-th power.
Error conditions result if:
x is zero and y is negative or zero,
x is negative and y is not an integer, or,

an overflow results.

Miscellaneous Functions

min(x,y) smaller of x and y.


max(x,y) larger of x and y.
randn(x,y) an approximately normally (Gaussian) distributed real random number with
mean x and standard deviation y.
randu(x) a uniformly distributed real random number from the interval [0,x].
row() row number.
ceil(x) smallest integer that is greater than or equal to x.
floor(x) largest integer less than or equal to x.
sqrt(x) square root of x.
The value of x must not be negative.
fabs(x) absolute value of x.
fmod(x,y) floating point remainder of x/y.
If y is zero, fmod returns zero.
d2r(x) convert argument in degrees to radians.
r2d(x) convert argument in radians to degrees.
Example: sin(d2r(30)) computes the sine of 30 degrees. sin(30) computes the sine of
30 radians.

Statistical Functions of an interval of columns

sum(a..z) sum
avg(a..z) average
std(a..z) standard deviation
min(a..z) minimum value
max(a..z) maximum value

* These functions operate row-wise on an interval of columns.


* For example, SUM(A..Z) computes the sum of the twenty-six columns A, B, C, ..., Z.
It does this for each row separately.
* You may replace 'a..z' by any valid interval of columns, such as 'C..H' or 'W..AC'.
There must be exactly two periods between the column labels. Columns may be given in
reverse order, such as SUM(Z..A).

Overlaying a Filled Contour Map on a Surface Plot

You can create a surface plot and a filled contour map of the same grid file and overlay the
contour map on the surface plot using the Overlay Maps command from the Map menu.

To overlay a filled contour map on a surface plot:

1. Create a surface plot based on the grid [.GRD] file or USGS DEM file. Set the
orientation and scaling parameters for the surface plot if necessary.
2. Create a contour map based on the same grid [.GRD] or DEM file, and add the color
fill between contours to create the filled contour map. You might want to turn off the display
of contour lines so there are not too many lines displayed on the overlay.

3. Select both the surface plot and the filled contour map. Choose the Overlay Maps
command from the Map menu, and the filled contour map is automatically overlain on the
surface plot. Note that hidden line removal is not performed on contour maps included in
overlays.
4. If you want to modify either the surface plot or the contour map, click the overlay and
choose the Edit Overlays command from the Map menu. Select the map to be edited from the
list in the Edit Components dialog box and click the Edit button. The dialog box for the
selected map is displayed. Make any changes and click OK, and the overlay is updated to
reflect the change.

You might also like