package jasymca; /* Jasymca - - Symbolic Calculator for Mobile Devices This version is written for J2ME, CLDC 1.1, MIDP 2, JSR 75 or J2SE Copyright (C) 2006 - Helmut Dersch der@hs-furtwangen.de 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 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, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /*------------------------------------------------------------*/ import java.util.Vector; // Strategy: // (1) Normalize equations // (2) Solve for all linear variables; use pivoting // (3) Solve remaining equations using SOLVE // (4) Keep multiple solutions // (5) Return as linear factors (x-solution) (might look weird) class LambdaALGSYS extends Lambda{ public Object lambda(Object x) throws ParseException, JasymcaException{ Vector args = getArgs(car(x)); if(args.size()!=2) throw new ParseException("algsys requires 2 arguments."); Algebraic expr = ((Algebraic)Jasymca.evalPrefix(args.elementAt(0), true, env)).rat(); Algebraic vars = (Algebraic)Jasymca.evalPrefix(args.elementAt(1), true, env); if(!(expr instanceof Vektor) || !(vars instanceof Vektor) || ((Vektor)expr).coord.length != ((Vektor)vars).coord.length ) throw new ParseException("Wrong type of arguments to algsys."); // Normalize all equations expr = new ExpandUser().f_exakt(expr); expr = new TrigExpand().f_exakt( expr ); expr = new NormExp().f_exakt(expr); expr = new CollectExp(expr).f_exakt(expr); expr = new SqrtExpand().f_exakt(expr); Vector v = new Vector(); for(int i=0; i<((Vektor)vars).coord.length; i++){ Algebraic p = ((Vektor)vars).coord[i]; if(!(p instanceof Polynomial)) throw new ParseException("Wrong type of arguments to algsys."); v.addElement(((Polynomial)p).var); } return solvesys(((Vektor)expr).vector(), v); } Vektor solvesys( Vector expr, Vector x) throws JasymcaException{ int nvars = x.size(); Vector lsg = new Vector(), vars = new Vector(); lsg.addElement(expr); vars.addElement(x); int n = nvars; while(n>0){ for(int i=0; inorm){ norm=nm; equ =exp; ke=k; iv=i; } } } } if(equ==null){ // Search any dependend Variable for(i=0; i