X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?p=CreaPhase.git;a=blobdiff_plain;f=octave_packages%2Fsymbolic-1.1.0%2Ffindsym.m;fp=octave_packages%2Fsymbolic-1.1.0%2Ffindsym.m;h=8347262190bcc3a9993a74eaf815afb87a021117;hp=0000000000000000000000000000000000000000;hb=c880e8788dfc484bf23ce13fa2787f2c6bca4863;hpb=1705066eceaaea976f010f669ce8e972f3734b05 diff --git a/octave_packages/symbolic-1.1.0/findsym.m b/octave_packages/symbolic-1.1.0/findsym.m new file mode 100644 index 0000000..8347262 --- /dev/null +++ b/octave_packages/symbolic-1.1.0/findsym.m @@ -0,0 +1,92 @@ +## Copyright (C) 2003 Willem J. Atsma +## +## 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 2, or (at your option) any later version. +## +## This software 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 software; see the file COPYING. If not, +## see . + +## -*- texinfo -*- +## @deftypefn {Function File} {@var{vars} =} findsym (@var{f}, @var{n}) +## Find symbols in expression @var{f} and return them comma-separated in +## string @var{vars}. The symbols are sorted in alphabetic order. If @var{n} +## is specified, the @var{n} symbols closest to "x" are returned. +## +## Example: +## @example +## symbols +## x = sym ("x"); +## y = sym ("y"); +## f = x^2+3*x*y-y^2; +## vars = findsym (f); +## vars2 = findsym (f,1); +## @end example +## +## This is intended for m****b compatibility, calls findsymbols(). +## @seealso{findsymbols} +## @end deftypefn + +function VARS = findsym(F,Nout) + + symlist = findsymbols(F); + Nlist = length(symlist); + if Nlist==0 + warning("No symbols were found.") + VARS = ""; + return + endif + + if exist("Nout")!=1 + VARS = disp(symlist{1}); + for i=2:Nlist + VARS = [VARS "," disp(symlist{i})]; + endfor + return + else + ## If Nout is specified, sort anew from x. + symstrings = disp(symlist{1}); + for i=2:Nlist + symstrings = [symstrings ; disp(symlist{i})]; + endfor + + symasc = toascii(symstrings); + + if Nlist