home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Fred Fish Collection 1.5
/
ffcollection-1-5-1992-11.iso
/
ff_disks
/
200-299
/
ff280.lzh
/
Graph
/
graph.doc
< prev
next >
Wrap
Text File
|
1989-11-20
|
30KB
|
730 lines
GRAPH, Version 1.00 - 4 August 1989
Copyright 1989, David Gay. All Rights Reserved.
This software is freely redistrubatable.
mail:
David Gay
19 Chemin de la Source
1296 Coppet
Vaud
Switzerland
From September 89 to June 1990
Somewhere in Pittsburgh :-)
e-mail:
GAY_D@ELMA.EPFL.CH
From September 89 to June 1990
???@???.cmu.edu
Thanks to:
Matt Dillon, for DME & DMouse
Checkpoint Technologies <ckp@grebyn.com> (whoever that is ...), for
finding a bug that I've been chasing for far too long.
Karl Lehenbauer for his tracking routines.
The ARP project, for its file requester (I didn't quite feel like
writing one ...).
CONTENTS
1) Introduction
2) Operation
a) Basic Concepts
b) User Interface
c) A Quick Overview
d) Example
3) Detailed description
a) Display
b) Expression Syntax
c) Menus
4) Appendices
a) Function "Improvement"
b) Known bugs, Possible enhancements
1) INTRODUCTION
This program draws mathematical functions on a plane. Text & axes may
be added, and the result saved to disk or printed.
All this is done through a fully Intuitionalised interface, with
multiple windows (for multiple graphs), requesters, etc. The whole
approach is WYSIWYG.
This program requires the arp.library (for the file requester), and
WB 1.3 (or WB 1.2 if you don't want to print anything).
This program should be fairly easy to use, I'm not sure how readable
this documentation is ! So, don't read it in isolation, experiment with
the program at the same time ...
2) OPERATION
a) Some basic concepts:
- One POINT = 1/72th of an inch.
- A GRAPH is composed of a SCALE (which selects which part of the plane
to view), optional X & Y AXES, and OBJECTS.
- The SCALE defines the minimum and maximum values for the X & Y axes,
as well as if these are linear or logarithmic (in which case the
minimum must be greater than 0). Finally you can give a display ratio
(ie the size/unit of the Y axis / size/unit of the X axis. With 1, a
line y = x will appear "correct", that is at 45 degrees).
- The (optional) drawing of AXES is specified through their position
on the other ax, the spacing between ticks, and the frequency with
which they should be numbered.
Note that the spacing between ticks is interpreted differently for
logarithmic axes. If x0 is the position of the Y ax on the (loga-
rithmic) X ax, and s is the tick spacing, you will get ticks at
x0, x0+s, x0+2s, x0+3s, ..., 10*x0, 10*x0+s, ...
For a linear ax, there is simply a tick every s, with a tick at x0.
- OBJECTS can (in this version) only be FUNCTIONS and LABELS (Planned
extensions include lines & rectangles).
- There are 4 types of FUNCTIONS:
y = f(x)
x = x(t), y = y(t)
r = r(theta)
r = r(t), theta = theta(t)
(the last two are in polar coordinates of course). A function
definition can contain VARIABLES (or if you prefer, constants :-)),
these are global.
- LABELS can be multi-line, in any font, size or colour (more on this
later).
- VARIABLES are defined globally to all graphs and functions, they
simply associate a name with an expression (which is evaluated when
the expression containing the variable is).
Positions are generally specified in planar coordinates, and sizes in
inches (so as to provide device-independent output).
b) User interface
The program is operated through a mix of menus, requesters, and mouse
clicking & dragging.
When a menu option contains the characters "..." it means that there is
a requester associated with this command, a >> indicates a submenu.
Most requesters contain OK and CANCEL gadgets, which act as expected.
You can use Left-Amiga V as a shortcut for clicking on OK, Left-Amiga B
for CANCEL, at *any* time. When entering text in a string gadget,
pressing RETURN will activate the next one, greatly simplyfing data
entry.
Leaving a blank when a number is expected means to use the default
value, or not to display whatever is associated with this (if this
makes any sense).
The two gadgets in the right hand border select the mode of operation
(see below).
While a requester is present in one window, all operations are disabled
in other windows.
c) A Quick Overview
A SCALE must be set before you can do most operations, this is done by
selecting the Scale menu option.
Two modes exist, selected by the gadgets in the window:
- Selection (Arrow gadget) : This mode allows you to select with the
mouse, and drag if applicable, objects on the graph.
- Position (Crosshairs gadget) : You define a point (by clicking), or
a rectangle (by clicking and dragging) for further operations.
You can add functions to the graph at any time (even before the scale
is set actually), to add a label you must have chosen the point where
it should appear. For a function, you must select a name for it and the
type you desire, you'll define the actual expression afterwards. For
text, you simply select the Add Label menu, and type the desired text.
Before doing anything with an object, you must first select it. This
can be done in several ways:
- By clicking on the object in select mode.
- Functions, which may not always be displayed, can be selected by
name (Select Function, in the Edit menu).
- A function is selected after it has been added(created).
(there is also a deselect operation).
The selected object can now be edited, deleted or improved (see
detailed description).
Edition for a function means defining the expression used, and the
boundaries for the parameter (eg x=3*cos(t), y=5*sin(t), with
0<=t<=6.3), for a label you can select the font, the colour and the
size (given in points) (see detailed description for the problems
involved here), change the text that you initially entered, its
position, its justification with respect to this. Also, you make the
text appear at an offset in inches from the given coordinates, for
example to make text appear at a constant distance above the axis
irrespective of the size of the output sheet.
The expressions for functions can contain VARIABLES (as noted above).
These are entered through the Edit Variables requester which works as
follows:
i) Enter the variable to be added/edited/deleted in the Variables
gadget and PRESS RETURN (if you don't do this, it won't work),
or select the variable in the list displayed.
ii) If the variable already exists, its value is displayed in the
Value gadget, which is activated.
iii) You can delete the variable by clicking on the delete gadget,
iv) Or, edit/add the value (which can be any expression, just avoid
circular definitions!). When this is done, PRESS RETURN
(otherwise the new value will be ignored). Syntax errors will
be indicated by a screen flash.
Don't forget that these variables are global, and shared by all graphs.
As such, they are saved/loaded separately to/from disk (with the
Load/Save Variables command).
AXES are added with the Axes menu option.
You can easily change the part of the plane you are viewing with the
Zoom/Zoom Out/Center options:
- Zoom: You first select a rectangle (in position mode), then choose
this option. The graph will be redrawn zoomed in this rectangle.
- Zoom Out: The plane area covered is made 4 times bigger (this isn't
really true if one or both axes is logarithmic).
- Center: The point selected becomes the new graph centre, the limits
are adjusted accordingly.
Graphs can be saved/loaded(this creates a new graph), and new graphs
created.
Finally, you can preserve your efforts for posterity with the Output
Graph submenu, either to your favourite printer or as an ILBM file. In
the latter case, you must specify the resolution you desire, as well as
the number of pixels per inch (to allow the sizes you specify in inches
to be calculated). You might specify 2400 by 3300, at 300 dpi if you
later plan to send the output to a laser printer (sizes of up to 32767
x 32767 should be possible). Note that with this option, the graph will
be full page, the Ratio specified in the SCALE is ignored. This isn't
necessarily the case with printer output, where the indications given
in.Preferences will be followed as far as makes sense.
You must then decide whether to have the functions drawn in a "thin"
pen (one pixel wide), or with a width of x points where you choose x.
Finally, your masterpiece will be printed/saved. As this can be a time
consuming process, you are given the possibility to abort it.
d) Example
We want to create a graph of the functions y = x, and y = e^(-x*x),
label it, and print the result. We proceed as follows:
i) run graph ; this helps :-)
ii) First we select a scale, x from -3 to 3, y from -0.1 to 1 is
reasonable, so:
Select menu option Scale (shortcut Amiga-L), and enter these
values for X: Min & Max, Y: Min & Max. One could also set the
ratio to 2. Click on OK, or press Right-Amiga V.
iii) We want the X & Y axes intersecting at (0,0) of course, you can
place ticks and numbering as you desire (eg a tick every 0.5 on
X, with values every two ticks). Press Amiga-X, and enter the
chosen values.
iv) It's now time to add the two functions, first y = x:
Press Amiga-F, and enter name "x" for the function, click on OK
(the default type, f(x), is the one we want). The function has
now been created, but we must still define it: Select Edit in the
Edit menu, this will edit the currently selected object (ie the
function we just created). If you've done something inbetween,
you can reselect the function in the Select Function option
(under the Edit menu), and then Edit. Define the function as
being f(x)=x, you can leave the "from" and "to" gadgets blank,
the limits of the x axis will be used.
y = exp(-x*x) : Add Function (giving it name exp), Edit it, and
define it as f(x)=exp(-sqr(x)) (don't forget that you must enter
the name of the independent variable, ie x).
The two functions should have been drawn as soon as you finished
editing them, if this wasn't the case, you probably made an error
(of which you should have been informed).
v) The graph is now complete, but you might want to label it a bit:
Add an "X" next to the X axis, a "Y" next to the Y axis, and a
title to the whole thing. Check that you are in "position" mode
before proceeding.
Labels on the axes: Click *on* the ax which you want to label, and
select Add Label, and type the text desired (ie "X" or "Y"). The
label will be drawn, rather unesthetically on the ax. Now pass
into "select" mode, and click on your label, it should be high-
lighted. Select Edit, and change the Y and dY fields (for the X
axis label): Set Y to 0, and dY to 0.1. This means that the label
will be drawn 0.1 inches *below* the Y ax. You could also change
the font, the font size (in points), etc
Title: In "position" mode, click wherever you want the title,
select Add Label and type the title. If you type a \, a line break
will be added at that place (two \\ are replaced by a single \),
so "Intersection of\two functions" would take two lines. As with
the labels on the axes, you can edit this label for font size and
so on.
vi) It is now time to save & print the graph. Save Graph will
accomplish the former, Output Graph / To Printer the latter. You
will be asked to select the line thickness, then printing will
start. You can press the Stop! gadget at any time if you get
bored (or want to abort the printing).
vii) You may want to change one of the functions, for example replace
y = x by y = a*x. Try the following:
- Select the function, either by clicking on it (in "select"
mode), or with Select Function in the Edit menu.
- Edit it, replacing f(x)=x by f(x)=a*x
- Select OK
The function will not be visible any more, because a has no
value.
viii) So, we must give "a" a value. Select Edit Variables (Amiga-V),
enter a in the Variables gadget, PRESS RETURN (!), enter the
value 0.5, PRESS RETURN (!!!). "a" should appear in the
variable list above. Select OK, and the line should be redrawn.
ix) That's it! (for now). You can close this graph with the close
gadget, or quit with the Quit option. You will be asked if you
want to save anything that has changed.
3) DETAILED DESCRIPTION
This section is more a reference than a tutorial, but should be read
carefully (all the details are here).
a) Display (ie the window)
The display is composed of a graph title, axes, and objects. It is a
view on a portion of the plane defined by the SCALE.
The graph title displays the name (for functions) of the currently
selected object, and the position on the plane where you
- currently are (while dragging something around)
- released the mouse button otherwise
(in this context, the rectangle/cross-hairs of "position" mode is
considered to be an object).
The axes are simply displayed as requested.
Objects are of two types:
- functions, which have a name, and are not always displayed.
- other objects (currently labels only) which are *always* visible.
If they are positioned outside the visible portion of the plane,
they are moved into it.
They can be selected by clicking on them (or near them for functions),
the currently selected object is highlighted and is the one on which
all object commands operate. If the operation is meaningful, they can
be dragged or resized with the mouse.
b) Expression syntax
The following is an informal description of the syntax of expressions,
the actual priorities of the operators are the usual arithmetic ones
(with unary minus higher than power), they all group left to right.
| indicates alternatives, [] optional parts.
expression := expression '+' expression |
expression '-' expression |
expression '*' expression |
expression '/' expression |
expression '^' expression |
'+' expression |
'-' expression |
'(' expression ')' |
number |
function '(' expression ')' |
variable
number := mantissa [exponent]
mantissa := integer [ '.' integer ]
exponent := 'E' [sign] integer
sign := '+' | '-'
function := <see Appendix B>
variable := <any name>
You will notice (?) that numbers do not allow a leading sign, negative
numbers are actually entered as an expression of the form -expression.
The following functions are available:
name description
---- -----------
sin sine
cos cosine
tan tangent
asin Arc sine
acos Arc cosine
atan Arc tangent
sinh hyperbolic sine
cosh hyperbolic cosine
tanh hyperbolic tangent
asinh inverse hyperbolic sine
acosh inverse hyperbolic cosine
atanh inverse hyperbolic tangent
exp e^x
exp10 10^x
abs absolute value - not differentiable
log base e logarithm
log10 base 10 logarithm
sqrt square root
sqr x^2
gamma gamma function - not differentiable
And these are the possible errors:
- the syntax of an expression was incorrect
- no memory for requested operation
- parenthesises are not matched
- left parenthesis expected (after a function)
- you have asked for a recursive evaluation ...
- the result isn't a number (quick_eval)
c) Menus
This is detailed description of what the various menu options do.
i) Project
New Graph: This creates a new window in which you can enter
another graph. All windows are independent, but variables are
shared. Note also that while a requester is up in one window, you
can't use the others.
Delete Graph: The current window is closed, this is equivalent to
the close window gadget. If this is the last window, the program
quits (see Quit). If the graph hasn't been saved, you are given a
last opportunity to do so (see Save Graph).
Load Graph: You choose a file to load (with the ARP file reques-
ter), if the file is really a saved graph it is loaded, and a new
graph created from it.
Save Graph: The graph in this window is saved to disk (you choose
a file with the ARP requester, again).
Output Graph: This is a submenu, for producing "hard" output
either to disk or printer. Sizes in inches are preserved (as far
as possible, see individual object descriptions under Add), but
the SCALE is adapted to the area available.
You must always choose a line thickness, either thin (1 pixel
wide), or in points (A requester appears just before output). You
can abort at any point by clicking on the Stop! gadget.
All the output is in black and white, this should be changed.
To Printer: The graph is sent to the printer, following the
indications in preferences as follows:
- Aspect is always horizontal.
- Scaling is always Fraction.
- The graph is printed at the chosen density (I hope you like
the output!).
- The Limits are interpreted as follows:
Multiply is equivalent to Ignore
Ignore is equivalent to Bounded, with the size limited to one
page (the size of one page is determined by the Page Length
and the Spacing).
In Bounded if no ratio is given the full size is used, other-
wise the size is determined to give the correct ratio.
In Absolute or Pixels, the given size is used. If one limit
is unspecified (ie width or height = 0) the ratio is used to
adjust it.
To Disk: A requester appears asking for the file name (you can
click on the Disk gadget to use the file requester), you must
give the size of the bitmap you want to produce, as well as its
resolution in dots per inch (to allow the size calculations to
be done). Once all this has been done, the graph is written as
an ILBM IFF file.
Load Variables: The variables are loaded from the specified file,
and are added to (or replace) the current ones.
Save Variables: All the existing variables are saved to a file.
Quit: All the graphs are closed (see Delete Graph). If the
variables have not been saved, Save Variables is called.
ii) Graph
Scale: This brings up a requester allowing you to set/change the
SCALE. If you leave the ratio blank, none will be used (ie the
graph will fill the wholde window/page).
Axes: Here you choose the options to display the AXES. If the
position of an ax is left blank none is displayed, if the tick
interval is blank no ticks are drawn, and if no frequency is
given no numbering is done.
Zoom: After defining a rectangle in "position" mode you can zoom
in to it with this option.
Zoom Out: The plane portion viewed is made "twice" as big,
keeping the same centre. The old visible portion now occupies
the centre of the new visible portion, and is half as wide (on
screen). If an ax is linear this is the expected effect: if
before we had -1<x<3, we get -3<x<5 (same centre (1), interval
twice as wide). However a logarithmic ax, 0.1<x<10 will become
0.01<x<100.
Centre: The point selected becomes the new graph centre (but the
graph stays the same "size"). Expect strange (or normal?)
behaviour similar to that described in Zoom Out.
iii) Add
Function: A new function is created, you must give it a unique
name, and select its type (which can not be changed afterwards).
Functions can not be dragged, they can be selected by clicking
on them when they are visible. The function is selected once you
have added it so that you can immediately define (edit) it.
Label: A new label is created at the current point (which must
exist!), you enter the text in a requester. A \ signals a new
line, except if it is followd by a second one in which case a
single \ is displayed. The label is created in the default font
and size (topaz, 10 points).
Labels are always visible, where they to be outside the shown
part of the plane they are moved just inside. They can be
selected and dragged around with the mouse.
The size of a font is specified in POINTS so that it appears the
same on all output devices (ever seen Topaz 8 at 240 dpi?).
However as the standard Amiga fonts are used, and these are not
scalable, the nearest available size is used. This can easily
cause problems if you ask for too big a font, which might exist
in the correct size to appear correctly on screen, but not on
paper. Beware! (You can work out the size needed from the reso-
lution of your printer, a 10 point font on a 300 dpi requires a
300*(10/72) = 42 pixel font on the Amiga). Also, the horizontal
size may vary a bit on different output devices ...
iv) Edit
Variables: The edit variables requester is brought up. It works
as follows:
- You select a variable by clicking in the list of existing
ones, or by typing its name in the Variables gadget and
PRESSING RETURN.
- Its value (if any) is then displayed. You can delete this
variable by clicking on the Delete gadget, or change its
value in the Value gadget. To store this value, you MUST
PRESS RETURN.
- When you are done, select OK.
Don't forget that the variables are global to all graphs.
Select Function: A list of all variables is presented, you can
choose one of them which then becomes the selected object (This
is most useful when a function is not displayed).
Deselect: Deselects the current selection.
Edit: Edits the currently selected object. This is of course
different for every type of object ...
Labels: You can change the text (max 255 characters), change
the font, font size and text colour. The position can be
entered exactly, and an offset in inches (dX & dY) can be
added. This allows for placement at a constant distance from
something else (object, ax) whatever the output device. Also
you can specify the justification of the rectangle containing
the text with respect to its position (by default, the chosen
point is in its top left corner).
Functions: For all types, you must define the independent
variable (eg x, t, but could be anything) for this function,
followed by the actual expressions defining the function (see
Expression Syntax). You must then give the bounds for the
independent variable, these are obligatory except for functions
of type f(x) where the bounds of the graph are used when none
are given here (Note that this implies that the points for the
function are recalculated every time the bounds for the graph
are changed, which is not the case when they are given expli-
citly). The numbers of points you wish to be calculated must
also be given (default: 100), the more the better the function
will look but the longer it will take to calculate & display
them. The colour can be selected, for the meaning of the Show
discontinuities and Allow flat discontinuities options see
Appendix on Improve. If the data given is valid, the points
will be calculated and the function drawn.
Improve: This command tries to improve the look of an object.
Currently this is only done for functions: extra points are
added if the program thinks this will make the function look
better. This requires some discussion ... (see Appendix). Note
that this improvement is temporary: If a graph is saved and
reloaded, if the function is changed (ie anything that necessi-
tates a recalculation of the points composing a function) will
discard the improvements made (Note that changing the bounds of
a graph will require the recalculation of functions of type
f(x) with unspecified bounds, as seen above).
Delete: The selected object is deleted, the graph redrawn.
4) APPENDICES
a) Function "Improvement"
When you draw a function like y = 1/x or y = sin(1/x) you encounter
various problems: discontinuities, lack of points to draw the func-
tion correctly. This function attemps to solve them by adding an
extra points between two points that are judged too far "apart". If
this process fails to solve the problem after a given number of
iterations (4) the program decides that there is a discontinuity
between the two points. This may well be incorrect (especially if
far too few points were initially calculated), so you can run
Improve repeatedly. This has the disadvantage that it may add a lot
of points.
This is were the Show/Allow flat discontinuities options intervene. If
the Show disc. option is not selected, a segment will be drawn between
two consecutive even if the above procedure thinks that there is a
discontinuity. The Allow flat disc. option proved emprically necessary,
it indicates that flat segments (ie quasi horizontal or vertical) should
be ignored in the search for discontinuities (otherwise one got severe
problems with functions like sin(x) around pi/2).
How does one judge if two points are two far "apart" you wonder ?
Given two points x0, x1 (in the f(x) case), the value of f(x1) is
estimated by e = f(x0) + (x1 - x0) * f'(x0) (First order Taylor
approximation). If e - f(x1) is too big (if |e - f(x1)| > 0.2 *
|f(x1) - f(x0)|) an extra point is added. This of course requires
f'(x), which can easily be obtained from f(x). If that function
wasn't differentiable, you'll get an error message when you try to
use the Improve command. For other types of functions, the approach
is very similar.
Finally, note that the above can be a time (and memory) consuming
process, so you can abort it at any time by clicking on the Stop!
gadget.
Comments on the above from numerical analysts are not welcome :-)
b) Known bugs, Possible enhancements
- The program was designed to recover from lack of memory (it makes
many, many allocations) but this feature has not been tested and
I'm pretty sure doesn't quite work.
- The very many and small memory allocations made could easily
fragment memory extensively. Something should be done about this
(an allocation is done for every point of every function !).
- More object types (lines, rectangles, circles, splines) could be
added.
- Add AREXX interface (?)
- Postscript output (I'll have to learn postscript first!)
- Make variables local to graphs ?
- Allow user to choose simple or smart refresh windows.
- Colour printing.
Very ambitious additions:
- Add scalable fonts (Very big :-))
- Add additional types of graphs, eg 3d, sampled (as in
histograms, that is with a non continous axis).
- ...