Contour Plotting for the TI-85
-- a program --
Page Contents:
Purpose of the program | Using
the program | Examples to try | Warnings | Downloading
the program | How the program works | Contacting
the author
Purpose of program:
This program makes contour plots for functions of the form F(x,y).
This program is still in development. A friendly interface will probably
be added in the future. Unfortunately, currently the program is not much
faster than the brute-force pixel scanning method, but I think the results
are nicer.
Using the program:
This version does not have a friendly interface. To use the program,
- Store a function in y1 using the variables x and
y. These must be lower case.
- Set the range on x and y using the [RANGE]
setting on the TI-85.
- Run the program. Execution takes 2-5 minutes, depending on the function
and range. The program will graph around 8 contour levels that are automatically
selected. The program can only graph contours that intersect the edge of
the screen, so there may be some contours wholly contained on the screen
that the program misses.
Examples to try:
Examples:
(Set these on the [GRAPH][y(x)=] and [GRAPH][RANGE]
screens, respectively.) Then run the program and enjoy the show.
- y1=8y^3+12x2-24xy, xMin = -2,
xMax = 2, yMin = -2, yMax = 2
- y1=y^3+3y-3y2-x2y+x2+x^4-1,
xMin = -0.4, xMax = 0.4,
yMin = 0.46965, yMax = 1.5
Warnings:
While the program has been tested with some care, it can still crash.
Please send SPECIFIC examples that cause crashes, including the exact formula
used for the function and the exact range, to mjanebawillamette.edu . Thank you for your assistance in this.
This program cannot make contour plots for functions that are not differentiable
functions of x and y. In fact, any function that the TI-85's
[der1] command cannot handle will cause a crash. Changing to [NDer]
won't help, since the base algorithm depends on differentiability. For
example, the program cannot handle y1=abs(x)+abs(y)if the range
includes any of the contours' "corners".
Downloading the program:
Here is the binary version: contour.85p
that you can load directly into the graphlink program and download to your
calculator. NOTE: If you have trouble downloading this, try holding
the shift button on your keyboard when you click on the link.
I am providing this program in binary format only. I do not anticipate
posting an ASCII version. This program is very long and complex (about
2900 keystrokes), and the likelihood of making typos if it were hand-entered
is very great. The program is NOT edit-locked, so you are welcome to download
it, and read it using TI's Graph-link software. You can download
Graph-link from TI and use it to read the program even if you
don't have the cable to pass it to your calculator.
How the program works:
Let's assume we have entered F(x,y) in y1,
and the range has been set as desired.
- Sample values of F are taken around the edge of the screen to
determine the range of values. This range is divided by 8, the default
number of contour levels. The quotient is called z
and is the spacing between contour levels.
- Starting 4 pixels up from the bottom left of the screen, a contour
is started. After that the program scans around the edge of the screen
looking for points (x,y) for which the value of F
differs from the previous contour level by more than z.
When such a point is found, a new contour is begun.
- To plot a contour, we use the fact that a contour line is perpendicular
to the gradient of F. Alternately, you can say that since F(x,y) = c
on the contour, then dF = Fxdx+ Fydy = 0,
so dy/dx = -Fx/Fy
(again, along the contour). The TI-85 can compute this (assuming F
is stored in y1) as -der1(y1,x)/der1(y1,y). The program
uses a combination of three methods to plot the actual curve:
- A predictor-corrector method with a variable step-size is used to plot
the curve as the solution to a differential equation. This variable step-size
makes this method adaptive; if the curve begins to turn tightly, the stepsize
is automatically reduced, then lengthened later. This gives the visual
impression of the curve "feeling its way" around tight corners
in contours as the graph slows down dramatically at such points. More specifically,
my method adds adaptive stepsize to what is called a trapezoid method,
a modified Euler method, or a second-order Runge-Kutta method by various
texts. Using the trapezoid estimate, the program subdivides an interval
if the angle between the tangents at the two ends of the current step exceeds
15 degrees. AC is the tangent of the critical angle, and is set
at the beginning of the program. This adaptive aspect not only makes sure
the endpoints of each plotted segment are close to correct, but also that
no corners on a contour are "cut" as a segment is plotted.
- When the adaptive portion of the program settles on a point, the program
evaluates F there, and performs a linear projection along the gradient
to move the point so that the value of F is correct for the contour
being plotted. This fixed the annoying problem of distinct contours being
plotted as crossing each other.
- Finally, if the slope of the graph exceeds Mc (critical slope,
default set at 1.4), the program ceases to plot y as a function
of x and instead plots x as a function of y. This
solves two problems: First, the base adaptive predictor-corrector method
can only plot functions. Contours often fail the vertical-line test. Secondly,
to plot those non-function curves, there will be a vertical tangent somewhere.
Large slope values, and especially singularities, cause serious errors
in predictor-corrector methods, adaptive or not.
- Contours terminate when the graph wanders off the screen. Points where
the contours exit the screen are stored. New contours are not initiated
within 4 pixels of an exit point, to keep the program from double-plotting
a single contour.
- This program computes slopes as -der1(y1,x)/der1(y1,y) or
-der1(y1,y)/der1(y1,x). Since the denominator could be zero, this
is a source of crashes. Further, either der1(y1,x) or der1(y1,y)
could themselves be undefined at any given point. To eliminate crashes
from common math-course examples, I have perturbed the graphing range variables
xMin, xMax, yMin, and yMax by a factor of (1+1E-12) (or just added
1E-12 if the variable is zero). Consequently der1(y1,y)
and der1(y1,x)are rarely evaluated at integers. This
fix was suggested by a kind contributor to the graph-TI discussion list,
Tom Bird of Austin Community College. Thanks, Tom.
Last modified April 23, 1997
Please mail comments or questions to: mjanebawillamette.edu
Return to
Prof. Janeba's Home Page
Willamette University
Home Page