help-octave
[Top][All Lists]

## Re: 0-1 function

 From: Gorazd Brumen Subject: Re: 0-1 function Date: Mon, 07 Mar 2005 10:52:02 +0100 User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.3) Gecko/20040913

```Thanks for the answer. I tried the image solution and it looks quite ok.
```
But is there any way of putting axes to the plot or I have to do it manually?
```Can you do similar thing as with image command with some gnuplot command?

G.

Geordie McBain wrote:
```
```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)<z0), then
p(x,y) takes only two values and proceed as above.

Geordie McBain
www.aeromech.usyd.edu.au/~mcbain

-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------

```
```
--
Gorazd Brumen
WWW: http://valjhun.fmf.uni-lj.si/~brumen
PGP: Key at http://pgp.mit.edu, ID BCC93240

-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------

```