changeset 23896:fe1763af4021

humps.m: Overhaul function. * humps.m: Use a single line summary of function as first docstring line. Add @seealso references. Use same variable names in function prototype as in documentation.
author Rik <rik@octave.org>
date Fri, 11 Aug 2017 18:31:04 -0700
parents d37e8e9decce
children c3cfd3115b78
files scripts/optimization/humps.m
diffstat 1 files changed, 20 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/optimization/humps.m	Fri Aug 11 18:09:51 2017 -0700
+++ b/scripts/optimization/humps.m	Fri Aug 11 18:31:04 2017 -0700
@@ -19,9 +19,11 @@
 ## Author: Nicholas R. Jankowski <jankowskin@asme.org>
 
 ## -*- texinfo -*-
-## @deftypefn {} {} humps (@var{x})
+## @deftypefn  {} {@var{y} =} humps (@var{x})
 ## @deftypefnx {} {[@var{x}, @var{y}] =} humps (@var{x})
-## Return the output of the rational function:
+## Evaluate a function with multiple minima, maxima, and zero crossings.
+##
+## The output @var{y} is the evaluation of the rational function:
 ##
 ## @tex
 ## $$y = -{ {1200x^4 - 2880x^3 + 2036x^2 - 340x - 88} \over {200x^4 - 480x^3 + 406x^2 - 138x - 17} }$$
@@ -38,46 +40,43 @@
 ##
 ## @end ifnottex
 ##
-## @var{x} may be a scalar, vector or array.  @code{humps} is vectorized such
-## that @var{yi} = humps (@var{xi})
+## @var{x} may be a scalar, vector or array.  If @var{x} is omitted, the
+## default range [0:0.05:1] is used.
 ##
-## If @var{x} is omitted, the range [0:0.05:1] is used instead.
-##
-## When called with two output arguments, [@var{x},@var{y}], @var{x} will
-## contain the input value(s), and @var{y} will contain the output from
+## When called with two output arguments, [@var{x}, @var{y}], @var{x} will
+## contain the input values, and @var{y} will contain the output from
 ## @code{humps}.
 ##
-## @code{humps} has two local maxima located near @var{x} = 0.300 and 0.893,
-## a local minimum near @var{x} = 0.637, and zeros near @var{x} = -0.132 and
-## 1.300. @code{humps} is a useful function for testing algorithms to find
-## zeros or local minima and maxima.
+## Programming Notes: @code{humps} has two local maxima located near @var{x} =
+## 0.300 and 0.893, a local minimum near @var{x} = 0.637, and zeros near
+## @var{x} = -0.132 and 1.300.  @code{humps} is a useful function for testing
+## algorithms which find zeros or local minima and maxima.
 ##
 ## Try @code{demo humps} to see a plot of the @code{humps} function.
+## @seealso{fzero, fminbnd, fminunc, fminsearch}
 ## @end deftypefn
 
-function varargout = humps (x = [0:0.05:1])
+function [x, y] = humps (x = [0:0.05:1])
 
   if (nargin > 1)
     print_usage ();
   endif
 
- y = - 4*( 300*x.^4 - 720*x.^3 + 509*x.^2 - 87*x - 22) ./ ...
-         ((10*x.^2 - 6*x + 1).*(20*x.^2 - 36*x + 17));
+  y = - 4*( 300*x.^4 - 720*x.^3 + 509*x.^2 - 87*x - 22) ./ ...
+          ((10*x.^2 - 6*x + 1).*(20*x.^2 - 36*x + 17));
 
-  if (nargout > 1)
-    varargout = {x, y};
-  else
-    varargout = {y};
+  if (nargout <= 1)
+    x = y;
   endif
 
 endfunction
 
+
 %!demo
 %! clf;
 %! fplot (@humps, [0, 2]);
 %! title ("humps() function");
 
-## tests
 ## value checks
 %!assert (humps (0), 88/17, 10*eps)
 %!assert (humps (1), 16, 10*eps)
@@ -100,5 +99,5 @@
 %!assert (humps (NaN), NaN)
 %!assert (humps ([]), [])
 
-## errors
+## Test input validation
 %!error humps (1,3)