changeset 1693:52ec826105e5 octave-forge

Improvement of help strings and argument checking for internal use functions. Still need to check types.
author mcreel
date Mon, 06 Sep 2004 12:48:49 +0000
parents fdd97ed3e888
children 54861d566a51
files main/optim/bfgsmin-example.m main/optim/bfgsmin.cc main/optim/bisectionstep.cc main/optim/finitedifference.cc main/optim/lbfgsmin.cc main/optim/newtonstep.cc
diffstat 6 files changed, 47 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/main/optim/bfgsmin-example.m	Mon Sep 06 05:59:04 2004 +0000
+++ b/main/optim/bfgsmin-example.m	Mon Sep 06 12:48:49 2004 +0000
@@ -33,7 +33,7 @@
 printf("EXAMPLE 1: Numeric gradient");
 x0 = ones(2,1);
 y0 = 2*ones(2,1);
-control = {50,2,1,1};  # maxiters, verbosity, conv. reg., arg_to_min
+control = {-1,2,1,1};  # maxiters, verbosity, conv. reg., arg_to_min
 [theta, obj_value, convergence] = bfgsmin("objective1", {x0, y0}, control);
 printf("\n");
 
--- a/main/optim/bfgsmin.cc	Mon Sep 06 05:59:04 2004 +0000
+++ b/main/optim/bfgsmin.cc	Mon Sep 06 12:48:49 2004 +0000
@@ -64,7 +64,7 @@
 
 
 DEFUN_DLD(bfgsmin, args, ,
-	  "bfgsmin: bfgs minimization of a function.\n\
+	  "bfgsmin: bfgs minimization of a function. See bfgsmin-example.m\n\
 \n\
 [x, obj, convergence] = bfgsmin(\"f\", {args}, {control}, {tols})\n\
 \n\
@@ -100,7 +100,7 @@
 In this example, x is optimized since it's the first\n\
 element of the cell array, y is a fixed constant = 1\n\
 \n\
-bfgsmin(\"f\", {ones(2,1), 1}, [10,2,1,1])\n\
+bfgsmin(\"f\", {ones(2,1), 1}, {10,2,1,1})\n\
 \n\
 bfgsmin final results: Iteration 1\n\
 Stepsize 0.0000000\n\
--- a/main/optim/bisectionstep.cc	Mon Sep 06 05:59:04 2004 +0000
+++ b/main/optim/bisectionstep.cc	Mon Sep 06 12:48:49 2004 +0000
@@ -33,8 +33,21 @@
 #include <octave/lo-ieee.h>
 #include <float.h>
 
-DEFUN_DLD(bisectionstep, args, , "bisectionstep.cc")
+DEFUN_DLD(bisectionstep, args, , "bisectionstep.cc - for internal use by bfgsmin and related functions")
 {
+  
+  int nargin = args.length ();
+  if (nargin < 3)
+    {
+      error("bisectionstep: you must supply at least 3 arguments");
+      return octave_value_list();
+    }
+	
+  if (nargin > 4)
+    {
+      error("bisectionstep: you must supply at most 4 arguments");
+      return octave_value_list();
+    }
   std::string f (args(0).string_value());
   Cell f_args (args(1).cell_value());
   ColumnVector dx (args(2).column_vector_value());
--- a/main/optim/finitedifference.cc	Mon Sep 06 05:59:04 2004 +0000
+++ b/main/optim/finitedifference.cc	Mon Sep 06 12:48:49 2004 +0000
@@ -18,9 +18,18 @@
 //  finite differences for numeric differentiation
 #include <oct.h>
 #include <float.h>
-DEFUN_DLD(finitedifference, args, ,"finitedifference, C++ version\n\
-differences for numgradient and numhessian")
+DEFUN_DLD(finitedifference, args, ,"finitedifference,\n\
+for internal use by numgradient and numhessian")
 {
+  
+	
+  int nargin = args.length ();
+  if (!(nargin == 2))
+    {
+      error("finitedifference: you must supply exactly 2 arguments");
+      return octave_value_list();
+    }
+	
   double x = args(0).double_value();
   int order = args(1).int_value();
   int test;
--- a/main/optim/lbfgsmin.cc	Mon Sep 06 05:59:04 2004 +0000
+++ b/main/optim/lbfgsmin.cc	Mon Sep 06 12:48:49 2004 +0000
@@ -96,7 +96,7 @@
 	
 
 DEFUN_DLD(lbfgsmin, args, ,
-	  "lbfgsmin: limited memory bfgs minimization of a function.\n\
+	  "lbfgsmin: limited memory bfgs minimization of a function. See lbfgsmin-example.m\n\
 \n\
 [x, obj, convergence] = lbfgsmin(\"f\", {args}, {control}, {tols}]\n\
 \n\
@@ -132,7 +132,7 @@
 In this example, x is optimized since it's the first\n\
 element of the cell array, y is a fixed constant = 1\n\
 \n\
-lbfgsmin(\"f\", {ones(2,1), 1}, [10,2,1,1])\n\
+lbfgsmin(\"f\", {ones(2,1), 1}, {10,2,1,1})\n\
 \n\
 bfgsmin final results: Iteration 1\n\
 Stepsize 0.0000000\n\
--- a/main/optim/newtonstep.cc	Mon Sep 06 05:59:04 2004 +0000
+++ b/main/optim/newtonstep.cc	Mon Sep 06 12:48:49 2004 +0000
@@ -28,8 +28,24 @@
 #include <octave/lo-ieee.h>
 #include <float.h>
 
-DEFUN_DLD(newtonstep, args, , "newtonstep.cc")
+DEFUN_DLD(newtonstep, args, , "newtonstep.cc - for internal use by bfgsmin and related functions")
 {
+  
+	
+  int nargin = args.length ();
+  if (nargin < 3)
+    {
+      error("newtonstep: you must supply at least 3 arguments");
+      return octave_value_list();
+    }
+	
+  if (nargin > 4)
+    {
+      error("bisectionstep: you must supply at most 4 arguments");
+      return octave_value_list();
+    }
+
+	
   std::string f (args(0).string_value());
   Cell f_args (args(1).cell_value());
   Matrix dx (args(2).matrix_value());