## Optplot (Scripts) Publisher's description

from Jim Ward

### OPTPLOT finds a nearly optimal number of points between given x-limits at which a real scalar function f(x) has to be calculated so that the plot of this function has a nearly uniform accuracy on the screen

OPTPLOT finds a nearly optimal number of points between given x-limits at which a real scalar function f(x) has to be calculated so that the plot of this function has a nearly uniform accuracy on the screen, specified by a parameter TOL, and either plots the graph or returns the calculated points for use with PLOT.

It uses an auxiliary function that bisects x-intervals recursively until the perpendiculars from each point to the line joining its two neighbouring points are less than TOL pixels on a full screen. Each bisection increases the accuracy by a factor of about four ultimately, so convergence is rapid. In order to attain correct screen geometry, this process requires the calculated y-values to be scaled appropriately; but the correct initial scaling factor cannot be found accurately so an approximation to it is estimated by finding the maximum and minimum y-values for a small initial set of x-values chosen (with some randomness) to divide the x-range into nearly equal sub-intervals. Undoubtedly this is a weakness in OPTPLOT, but the too-small estimated y-range increases rather than decreases the accuracy and in practice it seems to work quite well. The bisection process is applied to each of these sub-intervals in turn.

For slowly-varying functions, OPTPLOT does not offer much advantage over an equi-spaced set of x-values, using about half the number of points needed to give the same accuracy, although it is not necessary to guess the required number of points to use. But for plots of functions with regions of high curvature, the use of OPTPLOT can reduce the number of points by a factor of five or so.

Very often a satisfactory screen plot can be obtained with TOL > 1. However, the primary purpose of OPTPLOT is to provide a set of points that gives an accurate printout of the plot, in which case a much smaller value is needed, say 1/4 or 1/8 for printing at 600 dpi.

There is an accompanying test program OPTPLOTTEST to illustrate the remarks made above from which some pre-set functions and ranges can be chosen from a main menu. Menus on the toolbar allow the tolerances for them to be varied, and the calculated points to be shown or omitted. The number of calculated points and the number of equi-spaced x-values required to attain the same accuracy are displayed.

#### System Requirements:

MATLAB 5.2 (R10)**Program Release Status:**New Release

**Program Install Support:**Install and Uninstall