/** * Parse the given <code>expression String</code> and return the resulting * ASTNode. * * @param expression the expression * @return the AST node * @throws SyntaxError the syntax error */ public static ASTNode parseNode( String expression ) { DoubleEvaluator doubleEvaluator = new DoubleEvaluator(); return doubleEvaluator.parse( expression ); }
/** * Instantiates a new complex evaluator. */ public ComplexEvaluator() { this( new ComplexEvalVisitor() ); }
/** * Visit. * * @param node the node * @return the complex */ @Override public Complex visit( ComplexNode node ) { return node.complexValue(); }
public double evaluate(DoubleEvaluator engine, FunctionNode function) { double result = 0.0; for (int i = 1; i < function.size(); i++) { result += engine.evaluateNode(function.getNode(i)); } return result; } }
/** * Get the variable names from the given expression. * * @param expression * @param result * a set which contains the variable names */ public static void getVariables(String expression, Set<String> result) { getVariables(expression, result, true); }
/** * Visit. * * @param node the node * @return the complex */ @Override public Complex visit( DoubleNode node ) { return new Complex( node.doubleValue(), 0.0 ); }
public static boolean isValid(String fun, String[] var) { EvalDouble dEval = new EvalDouble(true); for (String v : var) { dEval.defineVariable(v, new DoubleVariable(0.0)); } try { dEval.parse(fun); return true; } catch (Exception e) { return false; } }
/** * To string. * * @return the string */ @Override public String toString() { return ComplexEvaluator.toString( value ); }
/** * * @param node * @param var * @return */ public ASTNode derivative(final ASTNode node, String var) { SymbolNode sym = fASTFactory.createSymbol(var); return derivative(node, sym); }
/** * Parse the given <code>expression String</code> and return the resulting ASTNode * * @param expression * @return * @throws SyntaxError */ public static ASTNode parseNode(String expression, boolean relaxedSyntax) { DoubleEvaluator doubleEvaluator = new DoubleEvaluator(relaxedSyntax); return doubleEvaluator.parse(expression); }
public double evaluate(DoubleEvaluator engine, FunctionNode function) { double result = 1.0; for (int i = 1; i < function.size(); i++) { result *= engine.evaluateNode(function.getNode(i)); } return result; } }
/** * Get the variable names from the given expression. * * @param expression * @param result * a set which contains the variable names */ public static void getVariables(String expression, Set<String> result) { Parser p = new Parser(); ASTNode node = p.parse(expression); getVariables(node, result); }
public ComplexEvaluator() { this(new ComplexEvalVisitor()); }
public Complex visit(ComplexNode node) { return node.complexValue(); }
public String toString() { return ComplexEvaluator.toString(value); }
/** * Parse the given <code>expression String</code> and return the resulting * ASTNode * * @param expression * @return * @throws SyntaxError */ public static ASTNode parseNode(String expression) { DoubleEvaluator doubleEvaluator = new DoubleEvaluator(); return doubleEvaluator.parse(expression); }
public double evaluate(DoubleEvaluator engine, FunctionNode function) { double result = Double.NaN; int end = function.size(); for (int i = 1; i < end; i++) { result = engine.evaluateNode(function.getNode(i)); if (DEBUG) { System.out.println(result); } } return result; } }
/** * Get the variable names from the given expression. * * @param expression the expression * @param result a set which contains the variable names */ public static void getVariables( String expression, Set<String> result ) { Parser p = new Parser(); ASTNode node = p.parse( expression ); getVariables( node, result ); }
@Override public double evaluate(DoubleEvaluator engine, FunctionNode function) { double result = 0.0; for (int i = 1; i < function.size(); i++) { result += engine.evaluateNode(function.getNode(i)); } return result; } }
@Override public double evaluate(DoubleEvaluator engine, FunctionNode function) { double result = 1.0; for (int i = 1; i < function.size(); i++) { result *= engine.evaluateNode(function.getNode(i)); } return result; } }