# HG changeset patch # User jwe # Date 1197320673 0 # Node ID 72b5e1701da2fd9c7e3e57dfd6f1ffc6fe705899 # Parent f1c1d837ba9fb3860ff424523bdf5956fd85e829 [project @ 2007-12-10 21:01:48 by jwe] diff -r f1c1d837ba9f -r 72b5e1701da2 NEWS --- 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. diff -r f1c1d837ba9f -r 72b5e1701da2 liboctave/ChangeLog --- 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 + * 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. diff -r f1c1d837ba9f -r 72b5e1701da2 liboctave/NLEqn.cc --- 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; diff -r f1c1d837ba9f -r 72b5e1701da2 liboctave/NLEqn.h --- 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 #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); diff -r f1c1d837ba9f -r 72b5e1701da2 scripts/ChangeLog --- 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 + * 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 diff -r f1c1d837ba9f -r 72b5e1701da2 scripts/signal/detrend.m --- 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))); + diff -r f1c1d837ba9f -r 72b5e1701da2 src/ChangeLog --- 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 + + * 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 * graphics.h.in (data_property::data): Declare as NDArray instead diff -r f1c1d837ba9f -r 72b5e1701da2 src/DLD-FUNCTIONS/fsolve.cc --- 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 (hybrd_info_to_fsolve_info (info)); - + retval(2) = static_cast (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 fsolve_options ("foo", 1, 2); +*/ + +/* ;;; Local Variables: *** ;;; mode: C++ *** ;;; End: *** diff -r f1c1d837ba9f -r 72b5e1701da2 test/ChangeLog --- 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 + + * test_nonlin.m: Delete. + 2007-12-03 David Bateman * fntests.m: Also count the skipped tests. diff -r f1c1d837ba9f -r 72b5e1701da2 test/test_nonlin.m --- 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 -## . - -%% 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 fsolve_options ("foo", 1, 2); - diff -r f1c1d837ba9f -r 72b5e1701da2 test/test_signal.m --- 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 %%