# HG changeset patch # User LYH # Date 1380222071 -28800 # Node ID 534247e14b036f74fc74465b9acbcbc235181401 # Parent 417fae0562da525a015c6f1f3cd6cc14c94536ba# Parent 55680de6a8976d167c9bb8a0a967e82468cabeae Merge the official development diff --git a/NEWS b/NEWS --- a/NEWS +++ b/NEWS @@ -17,6 +17,16 @@ Summary of important user-visible changes for version 3.8: --------------------------------------------------------- + ** Octave now uses OpenGL graphics by default with FLTK widgets. If + OpenGL libraries or FLTK widgets are not available when Octave is + built, gnuplot is used. You may also choose to use gnuplot for + graphics by executing the command + + graphics_toolkit ("gnuplot") + + Adding this command to your ~/.octaverc file will set the default + for each session. + ** Octave now supports nested functions with scoping rules that are compatible with Matlab. A nested function is one declared and defined within the body of another function. The nested function is only @@ -265,25 +275,24 @@ inputdlg msgbox warndlg ** Other new functions added in 3.8.0: - + atan2d erfi jit_startcnt - base64_decode expint lines - base64_encode findfigs polyeig - betaincinv flintmax prefdir - built_in_docstrings_file fminsearch preferences - cmpermute gallery readline_re_read_init_file - cmunique gco readline_read_init_file - colorcube hdl2struct rgbplot - copyobj history_save save_default_options - dawson imformats shrinkfaces - dblist importdata splinefit - debug_jit isaxes stemleaf - desktop iscolormap strjoin - doc_cache_create isequaln struct2hdl - ellipj jit_debug tetramesh - ellipke jit_enable waterfall - erfcinv - + base64_decode expint lines + base64_encode findfigs linsolve + betaincinv flintmax polyeig + built_in_docstrings_file fminsearch prefdir + cmpermute gallery preferences + cmunique gco readline_re_read_init_file + colorcube hdl2struct readline_read_init_file + copyobj history_save rgbplot + dawson imformats save_default_options + dblist importdata shrinkfaces + debug_jit isaxes splinefit + desktop iscolormap stemleaf + doc_cache_create isequaln strjoin + ellipj jit_debug struct2hdl + ellipke jit_enable tetramesh + erfcinv waterfall ** Deprecated functions. diff --git a/doc/interpreter/contrib.txi b/doc/interpreter/contrib.txi --- a/doc/interpreter/contrib.txi +++ b/doc/interpreter/contrib.txi @@ -355,7 +355,7 @@ @noindent The function name should start in column 1, and multi-line argument lists should be aligned on the first char after the open parenthesis. -You should put a space after the left open parenthesis and after commas, +You should put a space before the left open parenthesis and after commas, for both function definitions and function calls. Recommended indent is 2 spaces. When indenting, indent the statement diff --git a/doc/interpreter/linalg.txi b/doc/interpreter/linalg.txi --- a/doc/interpreter/linalg.txi +++ b/doc/interpreter/linalg.txi @@ -96,6 +96,8 @@ @DOCSTRING(inv) +@DOCSTRING(linsolve) + @DOCSTRING(matrix_type) @DOCSTRING(norm) diff --git a/libinterp/corefcn/graphics.cc b/libinterp/corefcn/graphics.cc --- a/libinterp/corefcn/graphics.cc +++ b/libinterp/corefcn/graphics.cc @@ -9501,6 +9501,16 @@ gtk_manager *gtk_manager::instance = 0; +gtk_manager::gtk_manager (void) + : dtk (), available_toolkits (), loaded_toolkits () +{ +#if defined (HAVE_FLTK) + dtk = "fltk"; +#else + dtk = "gnuplot"; +#endif +} + void gtk_manager::create_instance (void) { diff --git a/libinterp/corefcn/graphics.in.h b/libinterp/corefcn/graphics.in.h --- a/libinterp/corefcn/graphics.in.h +++ b/libinterp/corefcn/graphics.in.h @@ -2361,10 +2361,7 @@ private: - // FIXME: default toolkit should be configurable. - - gtk_manager (void) - : dtk ("gnuplot"), available_toolkits (), loaded_toolkits () { } + gtk_manager (void); ~gtk_manager (void) { } @@ -3458,7 +3455,7 @@ radio_property xvisualmode , "{auto}|manual" // Octave-specific properties bool_property __enhanced__ h , "on" - string_property __graphics_toolkit__ s , "gnuplot" + string_property __graphics_toolkit__ s , gtk_manager::default_toolkit () any_property __guidata__ h , Matrix () any_property __plot_stream__ h , Matrix () END_PROPERTIES diff --git a/scripts/linear-algebra/linsolve.m b/scripts/linear-algebra/linsolve.m new file mode 100644 --- /dev/null +++ b/scripts/linear-algebra/linsolve.m @@ -0,0 +1,135 @@ +## Copyright (C) 2013 Nir Krakauer +## +## This program 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. +## +## This program 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 this program; If not, see . + +## -*- texinfo -*- +## @deftypefn {Function File} {@var{x} =} linsolve (@var{A}, @var{b}) +## @deftypefnx {Function File} {@var{x} =} linsolve (@var{A}, @var{b}, @var{opts}) +## @deftypefnx {Function File} {[@var{x}, @var{R}] =} linsolve (@dots{}) +## Solve the linear system @code{A*x = b}. +## +## With no options, this function is equivalent to the left division operator +## @w{(@code{x = A \ b})} or the matrix-left-divide function +## @w{(@code{x = mldivide (A, b)})}. +## +## Octave ordinarily examines the properties of the matrix @var{A} and chooses +## a solver that best matches the matrix. By passing a structure @var{opts} +## to @code{linsolve} you can inform Octave directly about the matrix @var{A}. +## In this case Octave will skip the matrix examination and proceed directly +## to solving the linear system. +## +## @strong{Warning:} If the matrix @var{A} does not have the properties +## listed in the @var{opts} structure then the result will not be accurate +## AND no warning will be given. When in doubt, let Octave examine the matrix +## and choose the appropriate solver as this step takes little time and the +## result is cached so that it is only done once per linear system. +## +## Possible @var{opts} fields (set value to true/false): +## +## @table @asis +## @item LT +## @var{A} is lower triangular +## +## @item UT +## @var{A} is upper triangular +## +## @item UHESS +## @var{A} is upper Hessenberg (currently makes no difference) +## +## @item SYM +## @var{A} is symmetric or complex Hermitian (currently makes no difference) +## +## @item POSDEF +## @var{A} is positive definite +## +## @item RECT +## @var{A} is general rectangular (currently makes no difference) +## +## @item TRANSA +## Solve @code{A'*x = b} by @code{transpose (A) \ b} +## @end table +## +## The optional second output @var{R} is the inverse condition number of +## @var{A} (zero if matrix is singular). +## @seealso{mldivide, matrix_type, rcond} +## @end deftypefn + +## Author: Nir Krakauer + +function [x, R] = linsolve (A, b, opts) + + if (nargin < 2 || nargin > 3) + print_usage (); + endif + + if (! (isnumeric (A) && isnumeric (b))) + error ("linsolve: A and B must be numeric"); + endif + + ## Process any opts + if (nargin > 2) + if (! isstruct (opts)) + error ("linsolve: OPTS must be a structure"); + endif + trans_A = false; + if (isfield (opts, "TRANSA") && opts.TRANSA) + trans_A = true; + A = A'; + endif + if (isfield (opts, "POSDEF") && opts.POSDEF) + A = matrix_type (A, "positive definite"); + endif + if (isfield (opts, "LT") && opts.LT) + if (trans_A) + A = matrix_type (A, "upper"); + else + A = matrix_type (A, "lower"); + endif + endif + if (isfield (opts, "UT") && opts.UT) + if (trans_A) + A = matrix_type (A, "lower"); + else + A = matrix_type (A, "upper"); + endif + endif + endif + + x = A \ b; + + if (nargout > 1) + if (issquare (A)) + R = rcond (A); + else + R = 0; + endif + endif +endfunction + + +%!test +%! n = 4; +%! A = triu (rand (n)); +%! x = rand (n, 1); +%! b = A' * x; +%! opts.UT = true; +%! opts.TRANSA = true; +%! assert (linsolve (A, b, opts), A' \ b); + +%!error linsolve () +%!error linsolve (1) +%!error linsolve (1,2,3) +%!error linsolve ({1},2) +%!error linsolve (1,{2}) +%!error linsolve (1,2,3) diff --git a/scripts/linear-algebra/module.mk b/scripts/linear-algebra/module.mk --- a/scripts/linear-algebra/module.mk +++ b/scripts/linear-algebra/module.mk @@ -12,6 +12,7 @@ linear-algebra/ishermitian.m \ linear-algebra/issymmetric.m \ linear-algebra/krylov.m \ + linear-algebra/linsolve.m \ linear-algebra/logm.m \ linear-algebra/normest.m \ linear-algebra/null.m \