changeset 890:9149e6b1cf93 octave-forge

(for Fabio Rainone) surf using gnuplot 3.8i color extensions (for Paul Kienzle) peaks test surface
author pkienzle
date Fri, 11 Apr 2003 04:34:44 +0000
parents 36ba03a76a6d
children 1a4d5fe2ff63
files main/plot/peaks.m main/plot/surf.m
diffstat 2 files changed, 54 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main/plot/peaks.m	Fri Apr 11 04:34:44 2003 +0000
@@ -0,0 +1,47 @@
+## Generate a function with lots of local maxima and minima.
+##
+## f(x,y) = 3*(1-x)^2*exp(-x^2 - (y+1)^2) ...
+##          - 10*(x/5 - x^3 - y^5)*exp(-x^2-y^2) ...
+##          - 1/3*exp(-(x+1)^2 - y^2)
+##
+## peaks                plot a 49x49 mesh over the range [-3,3]
+## peaks(n)             plot an nxn mesh over the range [-3,3]
+## peaks(v)             plot over [X,Y]=meshgrid(v,v)
+## peaks(x,y)           plot over [X,Y]=meshgrid(x,y)
+## Z = peaks(...)       return Z instead of plotting
+## [X,Y,Z] = peaks(...) return X,Y,Z instead of plotting
+
+## This program is public domain
+
+## Expression for peaks function was taken from the following paper:
+##   http://www.control.hut.fi/Kurssit/AS-74.115/Material/GENALGgoga.pdf
+function [X_out,Y_out,Z_out] = peaks(x,y)
+
+  if nargin == 0
+    x = y = linspace(-3,3,49);
+  elseif nargin == 1
+    if length(x) > 1
+      y = x;
+    else
+      x = y = linspace(-3,3,x);
+    endif
+  endif
+
+
+  [X,Y] = meshgrid(x,y);
+  Z = 3*(1-X).^2.*exp(-X.^2 - (Y+1).^2) \
+      - 10*(X/5 - X.^3 - Y.^5).*exp(-X.^2-Y.^2) \
+      - 1/3*exp(-(X+1).^2 - Y.^2);
+
+  if nargout == 0
+    mesh(x,y,Z);
+  elseif nargout == 1
+    X_out = Z;
+  else
+    X_out = X;
+    Y_out = Y;
+    Z_out = Z;
+  endif
+
+endfunction
+
--- a/main/plot/surf.m	Tue Apr 08 08:43:52 2003 +0000
+++ b/main/plot/surf.m	Fri Apr 11 04:34:44 2003 +0000
@@ -16,4 +16,11 @@
 
 ## Draw a surface plot.  Presently only draws mesh surfaces.
 function surf(varargin)
+   try
+      gset pm3d at s ftriangles hidden3d 100;
+      gset line style 100 lt 5 lw 0.5;
+      gset nohidden3d;
+      gset nosurf;
+   catch
+   end
    mesh(varargin{:});