changeset 7279:72b5e1701da2

[project @ 2007-12-10 21:01:48 by jwe]
author jwe
date Mon, 10 Dec 2007 21:04:33 +0000
parents f1c1d837ba9f
children 96f86c256ca0
files NEWS liboctave/ChangeLog liboctave/NLEqn.cc liboctave/NLEqn.h scripts/ChangeLog scripts/signal/detrend.m src/ChangeLog src/DLD-FUNCTIONS/fsolve.cc test/ChangeLog test/test_nonlin.m test/test_signal.m
diffstat 11 files changed, 154 insertions(+), 151 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Mon Dec 10 20:30:17 2007 +0000
+++ b/NEWS	Mon Dec 10 21:04:33 2007 +0000
@@ -74,6 +74,7 @@
 
       on the gnuplot development list.
 
+
  ** The way Octave handles search paths has changed.  Instead of
     setting the built-in variable LOADPATH, you must use addpath,
     rmpath, or path to manipulate the function search path.  These
@@ -174,13 +175,26 @@
 
       [status, output] = system (cmd);
 
+
+ ** For compatibility with Matlab, the output of Octave's fsolve
+    function has been changed from
+
+      [x, info, msg] = fsolve (...);
+
+    to
+
+      [x, fval, info] = fsolve (...);
+
+
  ** For compatibility with Matlab, normcdf, norminv, normpdf, and
     normrnd have been modified to compute distributions using the
     standard deviation instead of the variance.
 
+
  ** For compatibility with Matlab, gamcdf, gaminv, gampdf, gamrnd,
     expcdf, expinv, exppdf and exprnd have been modified to compute 
     the distributions using the standard scale factor rather than
     one over the scale factor.
 
+
 See NEWS.2 for old news.
--- a/liboctave/ChangeLog	Mon Dec 10 20:30:17 2007 +0000
+++ b/liboctave/ChangeLog	Mon Dec 10 21:04:33 2007 +0000
@@ -1,5 +1,11 @@
 2007-12-10  John W. Eaton  <jwe@octave.org>
 
+	* NLEqn.h (NLEqn::fval): New data member.  Adjust constructors
+	and assignment operator.
+	(NLEqn::function_value): New function.
+	* NLEqn.cc (NLEqn::solve): If solution is successful, compute
+	function value.
+
 	* file-ops.cc (file_ops::concat): New function.
 	* file-ops.h: Provide decl.
 
--- a/liboctave/NLEqn.cc	Mon Dec 10 20:30:17 2007 +0000
+++ b/liboctave/NLEqn.cc	Mon Dec 10 21:04:33 2007 +0000
@@ -178,6 +178,8 @@
 
       if (f77_exception_encountered)
 	(*current_liboctave_error_handler) ("unrecoverable error in hybrj1");
+      else
+	fval = ColumnVector (fvec);
     }
   else
     {
@@ -195,6 +197,8 @@
 
       if (f77_exception_encountered)
 	(*current_liboctave_error_handler) ("unrecoverable error in hybrd1");
+      else
+	fval = ColumnVector (fvec);
     }
 
   return retval;
--- a/liboctave/NLEqn.h	Mon Dec 10 20:30:17 2007 +0000
+++ b/liboctave/NLEqn.h	Mon Dec 10 21:04:33 2007 +0000
@@ -27,6 +27,7 @@
 #include <cfloat>
 
 #include "NLEqn-opts.h"
+#include "lo-ieee.h"
 #include "lo-math.h"
 
 class
@@ -36,13 +37,15 @@
 public:
 
   NLEqn (void)
-    : NLFunc (), NLEqn_options (), x (), solution_status (0) { }
+    : NLFunc (), NLEqn_options (), x (), fval (),
+      solution_status (0) { }
 
   NLEqn (const ColumnVector& xx, const NLFunc f) 
-    : NLFunc (f), NLEqn_options (), x (xx), solution_status (0) { }
+    : NLFunc (f), NLEqn_options (), x (xx), fval (x.numel (), octave_NaN),
+      solution_status (0) { }
 
   NLEqn (const NLEqn& a)
-    : NLFunc (a.fun, a.jac), NLEqn_options (), x (a.x),
+    : NLFunc (a.fun, a.jac), NLEqn_options (), x (a.x), fval (a.fval),
       solution_status (a.solution_status) { }
 
   NLEqn& operator = (const NLEqn& a)
@@ -53,6 +56,7 @@
 	  NLEqn_options::operator = (a);
 
 	  x = a.x;
+	  fval = a.fval;
 	  solution_status = a.solution_status;
 	}
       return *this;
@@ -91,11 +95,14 @@
 
   bool solution_ok (void) const { return solution_status == 1; }
 
+  ColumnVector function_value (void) const { return fval; }
+
   std::string error_message (void) const;
 
 private:
 
   ColumnVector x;
+  ColumnVector fval;
   octave_idx_type solution_status;
 
   void error (const char* msg);
--- a/scripts/ChangeLog	Mon Dec 10 20:30:17 2007 +0000
+++ b/scripts/ChangeLog	Mon Dec 10 21:04:33 2007 +0000
@@ -1,5 +1,8 @@
 2007-12-10  John W. Eaton  <jwe@octave.org>
 
+	* signal/detrend.m: Move tests here from test/test_signal.m.
+	Loosen tolerance on first test from 10*eps to 20*eps.
+
 	* finance/rate.m: Don't request info from fsolve.
 
 2007-12-10  Michael Goffioul <michael.goffioul@gmail.com>
--- a/scripts/signal/detrend.m	Mon Dec 10 20:30:17 2007 +0000
+++ b/scripts/signal/detrend.m	Mon Dec 10 21:04:33 2007 +0000
@@ -59,3 +59,24 @@
   endif
 
 endfunction
+
+%!test
+%! N=32;
+%! x = (0:1:N-1)/N + 2;
+%! y = detrend(x);
+%! assert(all (all (abs (y) < 20*eps)));
+
+%!test
+%! N=32;
+%! t = (0:1:N-1)/N;
+%! x = t .* t + 2;
+%! y = detrend(x,2);
+%! assert(all (all (abs (y) < 30*eps)));
+
+%!test
+%! N=32;
+%! t = (0:1:N-1)/N;
+%! x = [t;4*t-3]';
+%! y = detrend(x);
+%! assert(all (all (abs (y) < 20*eps)));
+
--- a/src/ChangeLog	Mon Dec 10 20:30:17 2007 +0000
+++ b/src/ChangeLog	Mon Dec 10 21:04:33 2007 +0000
@@ -1,3 +1,9 @@
+2007-12-10  John W. Eaton  <jwe@octave.org>
+
+	* DLD-FUNCTIONS/fsolve.cc (Ffsolve):
+	For compatibility, return [x, fval, info] instead of [x, info, msg].
+ 	Move tests here from test/test_nonlin.m.
+
 2007-12-10  David Bateman  <dbateman@free.fr>
 
 	* graphics.h.in (data_property::data): Declare as NDArray instead
--- a/src/DLD-FUNCTIONS/fsolve.cc	Mon Dec 10 20:30:17 2007 +0000
+++ b/src/DLD-FUNCTIONS/fsolve.cc	Mon Dec 10 21:04:33 2007 +0000
@@ -223,7 +223,7 @@
 
 DEFUN_DLD (fsolve, args, nargout,
   "-*- texinfo -*-\n\
-@deftypefn {Loadable Function} {[@var{x}, @var{info}, @var{msg}] =} fsolve (@var{fcn}, @var{x0})\n\
+@deftypefn {Loadable Function} {[@var{x}, @var{fval}, @var{info}] =} fsolve (@var{fcn}, @var{x0})\n\
 Given @var{fcn}, the name of a function of the form @code{f (@var{x})}\n\
 and an initial starting point @var{x0}, @code{fsolve} solves the set of\n\
 equations such that @code{f(@var{x}) == 0}.\n\
@@ -405,15 +405,15 @@
 
       if (! error_state)
 	{
-	  std::string msg = nleqn.error_message ();
-
-	  retval(2) = msg;
-	  retval(1) = static_cast<double> (hybrd_info_to_fsolve_info (info));
-
+	  retval(2) = static_cast<double> (hybrd_info_to_fsolve_info (info));
+	  retval(1) = nleqn.function_value ();
 	  retval(0) = soln;
 
 	  if (! nleqn.solution_ok () && nargout < 2)
-	    error ("fsolve: %s", msg.c_str ());
+	    {
+	      std::string msg = nleqn.error_message ();
+	      error ("fsolve: %s", msg.c_str ());
+	    }
 	}
     }
   else
@@ -425,6 +425,85 @@
 }
 
 /*
+%!function retval = f (p) 
+%!  x = p(1);
+%!  y = p(2);
+%!  z = p(3);
+%!  retval = zeros (3, 1);
+%!  retval(1) = sin(x) + y**2 + log(z) - 7;
+%!  retval(2) = 3*x + 2**y -z**3 + 1;
+%!  retval(3) = x + y + z - 5;
+%!test
+%! x_opt = [ 0.599054;
+%! 2.395931;
+%! 2.005014 ];
+%! tol = 1.0e-5;
+%! [x, fval, info] = fsolve ("f", [ 0.5, 2.0, 2.5 ]);
+%! info_bad = (info != 1);
+%! solution_bad = sum (abs (x - x_opt) > tol);
+%! value_bad = sum (abs (fval) > tol);
+%! if (info_bad)
+%!   printf_assert ("info bad\n");
+%! else
+%!   printf_assert ("info good\n");
+%! endif
+%! if (solution_bad)
+%!   printf_assert ("solution bad\n");
+%! else
+%!   printf_assert ("solution good\n");
+%! endif
+%! if (value_bad)
+%!   printf_assert ("value bad\n");
+%! else
+%!   printf_assert ("value good\n");
+%! endif
+%! assert(prog_output_assert("info good\nsolution good\nvalue good"));
+
+%!function retval = f (p)
+%!  x = p(1);
+%!  y = p(2);
+%!  z = p(3);
+%!  w = p(4);
+%!  retval = zeros (4, 1);
+%!  retval(1) = 3*x + 4*y + exp (z + w) - 1.007;
+%!  retval(2) = 6*x - 4*y + exp (3*z + w) - 11;
+%!  retval(3) = x^4 - 4*y^2 + 6*z - 8*w - 20;
+%!  retval(4) = x^2 + 2*y^3 + z - w - 4;
+%!test
+%! x_opt = [ -0.767297326653401;
+%! 0.590671081117440;
+%! 1.47190018629642;
+%! -1.52719341133957 ];
+%! tol = 1.0e-5;
+%! [x, fval, info] = fsolve ("f", [-1, 1, 2, -1]);
+%! info_bad = (info != 1);
+%! solution_bad = sum (abs (x - x_opt) > tol);
+%! value_bad = sum (abs (fval) > tol);
+%! if (info_bad)
+%!   printf_assert ("info bad\n");
+%! else
+%!   printf_assert ("info good\n");
+%! endif
+%! if (solution_bad)
+%!   printf_assert ("solution bad\n");
+%! else
+%!   printf_assert ("solution good\n");
+%! endif
+%! if (value_bad)
+%!   printf_assert ("value bad\n");
+%! else
+%!   printf_assert ("value good\n");
+%! endif
+%! assert(prog_output_assert("info good\nsolution good\nvalue good"));
+
+%!test
+%! fsolve_options ("tolerance", eps);
+%! assert(fsolve_options ("tolerance") == eps);
+
+%!error <Invalid call to fsolve_options.*> fsolve_options ("foo", 1, 2);
+*/
+
+/*
 ;;; Local Variables: ***
 ;;; mode: C++ ***
 ;;; End: ***
--- a/test/ChangeLog	Mon Dec 10 20:30:17 2007 +0000
+++ b/test/ChangeLog	Mon Dec 10 21:04:33 2007 +0000
@@ -1,3 +1,7 @@
+2007-12-10  John W. Eaton  <jwe@octave.org>
+
+	* test_nonlin.m: Delete.
+
 2007-12-03  David Bateman  <dbateman@free.fr>
 
 	* fntests.m: Also count the skipped tests.
--- a/test/test_nonlin.m	Mon Dec 10 20:30:17 2007 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,103 +0,0 @@
-## Copyright (C) 2006, 2007 John W. Eaton
-##
-## This file is part of Octave.
-##
-## Octave is free software; you can redistribute it and/or modify it
-## under the terms of the GNU General Public License as published by
-## the Free Software Foundation; either version 3 of the License, or (at
-## your option) any later version.
-##
-## Octave is distributed in the hope that it will be useful, but
-## WITHOUT ANY WARRANTY; without even the implied warranty of
-## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-## General Public License for more details.
-##
-## You should have received a copy of the GNU General Public License
-## along with Octave; see the file COPYING.  If not, see
-## <http://www.gnu.org/licenses/>.
-
-%% Automatically generated from DejaGNU files
-
-%% test/octave.test/nonlin/fsolve-1.m
-%!function retval = f (p) 
-%!  x = p(1);
-%!  y = p(2);
-%!  z = p(3);
-%!  retval = zeros (3, 1);
-%!  retval(1) = sin(x) + y**2 + log(z) - 7;
-%!  retval(2) = 3*x + 2**y -z**3 + 1;
-%!  retval(3) = x + y + z - 5;
-%!test
-%! x_opt = [ 0.599054;
-%! 2.395931;
-%! 2.005014 ];
-%! tol = 1.0e-5;
-%! [x, info] = fsolve ("f", [ 0.5, 2.0, 2.5 ]);
-%! val = f (x);
-%! info_bad = (info != 1);
-%! solution_bad = sum (abs (x - x_opt) > tol);
-%! value_bad = sum (abs (val) > tol);
-%! if (info_bad)
-%!   printf_assert ("info bad\n");
-%! else
-%!   printf_assert ("info good\n");
-%! endif
-%! if (solution_bad)
-%!   printf_assert ("solution bad\n");
-%! else
-%!   printf_assert ("solution good\n");
-%! endif
-%! if (value_bad)
-%!   printf_assert ("value bad\n");
-%! else
-%!   printf_assert ("value good\n");
-%! endif
-%! assert(prog_output_assert("info good\nsolution good\nvalue good"));
-
-%% test/octave.test/nonlin/fsolve-2.m
-%!function retval = f (p)
-%!  x = p(1);
-%!  y = p(2);
-%!  z = p(3);
-%!  w = p(4);
-%!  retval = zeros (4, 1);
-%!  retval(1) = 3*x + 4*y + exp (z + w) - 1.007;
-%!  retval(2) = 6*x - 4*y + exp (3*z + w) - 11;
-%!  retval(3) = x^4 - 4*y^2 + 6*z - 8*w - 20;
-%!  retval(4) = x^2 + 2*y^3 + z - w - 4;
-%!test
-%! x_opt = [ -0.767297326653401;
-%! 0.590671081117440;
-%! 1.47190018629642;
-%! -1.52719341133957 ];
-%! tol = 1.0e-5;
-%! [x, info] = fsolve ("f", [-1, 1, 2, -1]);
-%! val = f (x);
-%! info_bad = (info != 1);
-%! solution_bad = sum (abs (x - x_opt) > tol);
-%! value_bad = sum (abs (val) > tol);
-%! if (info_bad)
-%!   printf_assert ("info bad\n");
-%! else
-%!   printf_assert ("info good\n");
-%! endif
-%! if (solution_bad)
-%!   printf_assert ("solution bad\n");
-%! else
-%!   printf_assert ("solution good\n");
-%! endif
-%! if (value_bad)
-%!   printf_assert ("value bad\n");
-%! else
-%!   printf_assert ("value good\n");
-%! endif
-%! assert(prog_output_assert("info good\nsolution good\nvalue good"));
-
-%% test/octave.test/nonlin/fsolve_options-1.m
-%!test
-%! fsolve_options ("tolerance", eps);
-%! assert(fsolve_options ("tolerance") == eps);
-
-%% test/octave.test/nonlin/fsolve_options-3.m
-%!error <Invalid call to fsolve_options.*> fsolve_options ("foo", 1, 2);
-
--- a/test/test_signal.m	Mon Dec 10 20:30:17 2007 +0000
+++ b/test/test_signal.m	Mon Dec 10 21:04:33 2007 +0000
@@ -18,44 +18,6 @@
 
 %% Automatically generated from DejaGNU files
 
-%% test/octave.test/signal/detrend-1.m
-%% detrend-1.m
-%%
-%% Author: David Billinghurst (David.Billinghurst@riotinto.com.au)
-%%         Comalco Research and Technology
-%%         02 May 2000
-%!test
-%! N=32;
-%! x = (0:1:N-1)/N + 2;
-%! y = detrend(x);
-%! assert(all (all (abs (y) < 10*eps)));
-
-%% test/octave.test/signal/detrend-2.m
-%% detrend-2.m
-%%
-%% Author: David Billinghurst (David.Billinghurst@riotinto.com.au)
-%%         Comalco Research and Technology
-%%         02 May 2000
-%!test
-%! N=32;
-%! t = (0:1:N-1)/N;
-%! x = t .* t + 2;
-%! y = detrend(x,2);
-%! assert(all (all (abs (y) < 30*eps)));
-
-%% test/octave.test/signal/detrend-3.m
-%% detrend-3.m
-%%
-%% Author: David Billinghurst (David.Billinghurst@riotinto.com.au)
-%%         Comalco Research and Technology
-%%         02 May 2000
-%!test
-%! N=32;
-%! t = (0:1:N-1)/N;
-%! x = [t;4*t-3]';
-%! y = detrend(x);
-%! assert(all (all (abs (y) < 20*eps)));
-
 %% test/octave.test/signal/fft-1.m
 %% fft-1.m
 %%