No BSD License  

Highlights from
Optplot

Be the first to rate this file! 2 Downloads (last 30 days) File Size: 3.86 KB File ID: #5022

Optplot

by Jim Ward

 

27 May 2004 (Updated 01 Jun 2004)

Gives a nearly optimal set of points [x y] for a plot of y = f(x) with uniform specified accuracy.

| Watch this File

File Information
Description

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.

MATLAB release MATLAB 5.2 (R10)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
specialized Jim Ward 22 Oct 2008 07:21:04
plotting Jim Ward 22 Oct 2008 07:21:04
optimal Jim Ward 22 Oct 2008 07:21:04
2dcurves Jim Ward 22 Oct 2008 07:21:04
plots Jim Ward 22 Oct 2008 07:21:04
graphics Jim Ward 22 Oct 2008 07:21:04

Contact us at files@mathworks.com