From help-request at octave dot org Sun Mar 6 18:17:08 2005 Subject: Re: 0-1 function From: Geordie McBain To: Gorazd Brumen Cc: help at octave dot org Date: Tue, 8 Mar 2005 03:19:22 +1100 On Sun, Mar 06, 2005 at 10:03:40PM +0100, Gorazd Brumen wrote: > Hi again, > > I have a function of 2 variables which takes only the values > 0 and 1. What would be in your oppinion > the best way to present this > function graphically? If I draw a mesh plot or a contour > plot, gnuplot always wants to make graphs continuous and > they look weird. > > Gorazd Hello. One way is to colour-in the region f=1. For example octave> function p = pred (x, y); p = y < sqrt (abs (x) + x.**2); endfunction octave> [XX, YY] = meshgrid (linspace (-2, 2, 100), linspace (3, 0, 100)); octave> imagesc (pred (XX, YY)) warning: in fopen near line 197, column 11: warning: fopen: default open mode is now binary This draws a somewhat pixellated black-and-white plot of the function pred. (Note that the y-coordinates are reversed.) Another way to display a function f(x,y) -> {0,1} is to draw the margin separating the regions f=0 and f=1. This involves a lot less function evaluations that the first method. I came up with an algorithm to walk along such marginal curves, given two initial points, one on either side of the curve. If this is of interest, see http://www.aeromech.usyd.edu.au/~mcbain/stability/skirting.html for the m-file, or http://anziamj.austms.org.au/V45/CTAC2003/McBa/ for detailed description, theory, examples, etc. This could also be useful for that question from someone else over the weekend about drawing tricky contours. Say you wanted to draw the level-curve f(x,y) = z0, define a function p(x,y)=(f(x,y)