[Pkg-octave-commit] [SCM] octave-symbolic branch, master, updated. a718b53403d9f164f8c2a3df521385a01d28a11b

watsma watsma at 416fae20-06d0-4450-9b69-c6c34d4b5f03
Mon Jan 3 03:40:38 UTC 2011


The following commit has been merged in the master branch:
commit 8d93fa0584df9a4458a0abe4de747eb8d45af608
Author: watsma <watsma at 416fae20-06d0-4450-9b69-c6c34d4b5f03>
Date:   Wed May 14 20:13:55 2003 +0000

    Initial commit. Returns the summed terms of an equation, used in
    sym2poly.
    
    
    git-svn-id: https://octave.svn.sourceforge.net/svnroot/octave/trunk/octave-forge/main/symbolic@934 416fae20-06d0-4450-9b69-c6c34d4b5f03

diff --git a/numden.cc b/sumterms.cc
similarity index 63%
copy from numden.cc
copy to sumterms.cc
index f3e50f9..1464ea6 100644
--- a/numden.cc
+++ b/sumterms.cc
@@ -19,36 +19,46 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 #include <octave/oct.h>
 
 #include <ginac/ginac.h>
-#include "ov-vpa.h"
 #include "ov-ex.h"
 #include "symbols.h" 
 
 
-DEFUN_DLD(numden,args,nargout,
+DEFUN_DLD(sumterms,args, ,
 "-*- texinfo -*-\n\
- at deftypefn Loadable Function {[num,den] =} numden(@var{f})\n\
+ at deftypefn {Loadable Function} {@var{terms} =} sumterms(@var{f})\n\
 \n\
-Return the numerator and denominator of symbolic expression @var{f}.\n\
+Returns a list of terms that are summed in expression @var{f}.\n\
 @end deftypefn")
 {
-	GiNaC::ex expression, numden_list;
-	octave_value_list retval;
+	GiNaC::ex expression;
+	octave_value retval;
+	octave_value_list termlist;
 	int nargin = args.length();
+
 	if (nargin != 1) {
-		print_usage ("numden");
+		error("Need one argument.");
 		return retval;
 	}
-	try { 
+	try {
 		if (!get_expression (args(0), expression)) {
 			error("Argument must be a symbolic expression.");
 			return retval;
 		}
-		numden_list = expression.numer_denom();
-		retval.append(new octave_ex(numden_list[0]));
-		retval.append(new octave_ex(numden_list[1]));
-	} catch(std::exception &e) {
+		if(GiNaC::is_a<GiNaC::add>(expression)) {
+			int i, n = expression.nops();
+			for(i=0;i<n;i++) {
+				OCTAVE_QUIT;
+				termlist.append(octave_value(new octave_ex(expression.op(i))));
+			}
+		} else {
+			// no sum terms, return expression
+			termlist.append(octave_value(new octave_ex(expression)));
+		}
+		retval = termlist;
+	} catch (std::exception &e) {
 		error (e.what ());
 		retval = octave_value ();
 	}
+
 	return retval;
 }

-- 
octave-symbolic



More information about the Pkg-octave-commit mailing list