Guide to Script & Graph

last modified Sep/6th/2002

About the program   Installation and the first use   More about scripting   Operators and functions   View modes   Keyboard accelerators   Other   Contact  

 

About the program

This program allows you to graph any mathematical function in two-dimensional Cartesian space provided it is not parametric. You can draw any number of graphs in different colors, define constants, change them interactively and watch how the graph changes itself. In addition, you can plunge into depth with zooming rectangle and use mouse to pick individual function values.

The application was designed for Windows 98 and Windows NT 4.

What the program doesn't do

This program cannot print. Unfortunately, this feature was not programmed in freeware version.

Installation and the first use

Unzip the .zip file to the folder of your choice. To uninstall, just delete the folder.

To begin, follow these steps:

1. Open a blank window.

2. Copy the following line to the window:

color red; f = 1; draw sin (f*pi*x);

3. Plot the graph by pressing the toolbar button or by Ctrl+F8 keyboard shortcut.

4. You can modify f. Invoke Modify Constants window and press plus or minus button to do so. The increase, that is being added to the original value, is changeable. By default it is 1.0. This window may be easily invoked by menu command, the toolbar button, or by pressing F5 anytime later.

5. When you haven't defined initial x, it is -1 by default. The script is perfomed for each x from the interval [initial x, initial x + horizontal extent], including these borders. To set another initial value, for example 0, just include x = 0; anywhere in the script. The horizontal extent is 2.0 by default. You may give any positive number.

More about scripting

The scripting language comprises four simple commands. These are as follows:

Rem stands for remark or remove. You can remove extensive parts of script by this command. Everything after rem up to next semicolon is ignored.

rem [text];

rem This is a remark;

Assignment serves to define variables and constants.

[identifier] = [expression];

a = 2 + 3 * tan (pi/4);

b = x^2;

An expression is considered constant if it doesn't contain an identifier already defined by another assignment. The first example above defines a constant, the second one is a variable. Once defined, the identifier may be used in subsequent commands. The only predefined identifier is x and is set to -1 by default.

As mentioned above, x is changing progressively from the initial value (-1 or other) to the initial value plus the horizontal extent. The values are being regularly picked from the interval and the script is executed for each of them.

Draw computes given expressions and plots them as a graph. One or more expressions are allowed.

draw [expression], [expression], ... ;

draw a;

draw b, x * e^x;

Color sets the current color. Draw uses that color to paint the graph.

color [expression];

color yellow;

rem Yellow;
red = 255; green = 255; blue = 0;
color 2^0 * red + 2^8 * green + 2^16 * blue;

The color is an integer in the range 0 ... 2^24 - 1. Zero is for black and 2^24 - 1 is for white. This model gives you 16.8 million different colors. The second example creates a color from red, green, and blue component. Each component is an integer, varies from 0 to 255, and acts as an intensity. You have 256 distinct values for the component, that's why 256 * 256 * 256 = 16.8 million makes the number of all available colors.

There are also 20 commonly used colors. Here is a list of them:

black, white, red, green, blue, cyan, magenta, yellow, darkred, darkgreen, darkblue, darkcyan, darkmagenta, darkyellow, moneygreen, skyblue, cream, gray, darkgray, silver

These are predefined identifiers like e, or pi, and may be used in any expression. These twenty colors are the only you can use on 256 color displays.

Writing scripts

The following is an example of valid script. It defines time as a constant, making it available in Modify Constants window. The script is performed for each new time, producing an animated graph this way.

rem Oscillations
'x' as well as the horizontal extent are multiples of pi;

x = -0.5;
time = 0;

f = 10 + 8 * sin (time/100*2*pi);
g = 10 + 7 * cos (time/100*2*pi);
a = 0.1 * sin (x*f) * impulse (x/pi);
b = 0.1 * sin (x*g) * impulse (x/pi);

color red;
draw a;
color green;
draw -0.3 + b;
color blue;
draw -0.15 + 0.27 * (a + b);

Identifiers may be any length but only first 16 characters are significant. Also note that all commands are terminated by semicolons. Scripts are not case-sensitive.

Operators and functions

This paragraph guides you through the list of operators and functions available for using in expressions. It also indroduces e and pi constants. Operators are listed in order of their precedence.

parentheses
()
([expression])

unary minus
-
-[expression]
-a

exponentiation
^
[expression] ^ [expression]
a ^ b
a is raised to the power of b

multiplication
*
[expression] * [expression]
a * b

division
/
[expression] / [expression]
a / b

addition
+
[expression] + [expression]
a + b

subtraction
-
[expression] - [expression]
a - b

sine
sin ([expression])

arcus sine
asin ([expression])

hyperbolic sine
sinh ([expression])

cosine
cos ([expression])

arcus cosine
acos ([expression])

hyperbolic cosine
cosh ([expression])

tangent
tan ([expression])

arcus tangent
atan ([expression])

hyperbolic tangent
tanh ([expression])

cotangent
cotan ([expression])

arcus cotangent
acotan ([expression])

hyperbolic cotangent
cotanh ([expression])

10-base logarithm
log ([expression])

natural logarithm
ln ([expression])

abolute value
abs ([expression])

factorial
fac ([expression])

truncation
trunc ([expression])
evaluates an expression and returns integer part of the result

square root
sqrt ([expression])

floor
floor ([expression])
evaluates an expression and returns the largest integer that is less or equal to the result

ceiling
ceil ([expression])
evaluates an expression and returns the smallest integer that is greater or equal to the result

impulse
impulse ([expression])
evaluates an expression and returns 1.0, if the result was greater or equal to 0 and less than 0.5, otherwise the return value is zero

remainder
mod ([expression], [expression])
mod (a, b)
returns the remainder of a / b such that a = i * b + f; i is an integer, the remainder f has the same sign as a, and the absolute value of remainder is less than the absolute value of b

range
range ([expression])
evaluates an expression and returns decimal part of the result if the result was greater than 0, otherwise the return value is complement of absolute value of that decimal part to 1.0

e
e = 2.71828182845905

pi
pi = 3.14159265358979

All values in this application are stored in double precision. Very large or very small numbers can have scientific notation, i.e. they can have added e or E and the exponent. For example, -1.2e-2 means -1.2 * 10 ^ -2.

View modes

The program provides with three view modes. The first one is anisotropic and the remaining two are isotropic. The unit sizes of the horizontal and the vertical axis are not necessarily the same in the anisotropic mode and both depend on window size. On the other hand, the isotropic mode makes them equal with first one dependent on appropriate vertical or horizontal window size and the second one totally independent, giving you much larger views than the anisotropic one.

This design leads into problems when the aspect ratio of axes is too large or too small. Take for example, y = 1 * 10^6; and display it in the range 0 ... 1.0. The aspect ratio is 1000000 / 1 and with either isotropic mode you get this message:

Simply, the window cannot accommodate such large area. But this poses no problem for the anisotropic mode.

The reason for this message is any situation that prevents the graph from being painted. For example, the presence of the sole draw 0; (and no other) command leads to that message. In another words, when the values that should be plotted are all zeros or infinite, or are all NaN (not a number), or are at least outside the borders created by the zooming rectangle, this message is issued.

Keyboard accelerators

They are always the best way of invoking the commands. Several of them have no toolbar or menu equivalent. Here are some of the most important shortcuts:

Ctrl+N, opens new window
Ctrl+F4, closes the window
Ctrl+F6, activates the next window
Ctrl+F8, displays the graph in the window, or displays the script for the graph
Ctrl+J, Ctrl+K, Ctrl+L, switch between the view modes
F8, moves the keyboard focus between the window and the horizontal extent box
Ctrl+A, selects all the text in the window
ESC, zooms out - moves the stack pointer up of one frame
F5, shows or hides Modify Constants window
TAB, moves the keyboard focus between the controls in Modify Constants window, it may also show this window
F3, F4, animate the graph, but Modify Constants window must be visible

Other features

These properties have not been mentioned yet and are explained here. You can make graphs more accurate, or make axis numbered by multiples of pi.

Sometimes when Isotropic Full Y mode is active and the graph exceeds far beyond visible window area, it looks as if it was made from broken lines. It is because only 400 samples per a function have been computed. This is normal precision and it would suffice for routine use. However, higher precisions are better in these situations. With the highest precision, the program has to compute 3000 samples per a function. This is a drawback, too, because it may significantly slowdown program performance.

The application is simple enough to work with. The mouse support promoted this feature even more. The mouse is required when zooming into a graph or finding certain value of a function. To zoom in, hold the right mouse down and drag it over requested part of graph. Use the left mouse button to pick the function value.

You can have horizontal axis numbered by multiples of pi. This may be useful when drawing functions which take arguments in radians (sin, etc). This property is turned off by default and can be activated by View/Radians menu command. In this case, x is implicitly multiplied by pi anywhere it stands in the script.

Some functions are continuous and some are not. The last property that should be talked over is possibility to have discontinuous function drawn properly, taking existing discontinuities into account. View/Discontinuous f(x) menu command turns this feature on or off. After the property has been activated, the program tracks all points of a function and computes the difference of angles of tangent lines to a function at two neighbouring points. When this difference is too large in its absolute value, discontinuity is detected, and the two points are not connected.

Contact

Mail to: co2@pobox.sk

News: http://doc.webpark.sk

© 2002 M.Sveton