Class DJep

  • All Implemented Interfaces:
    java.io.Serializable
    Direct Known Subclasses:
    MDJep

    public class DJep
    extends XJep
    Adds differentiation facilities to Jep. For example
     DJep j = new DJep();
     j.addStandardDiffRules();
     ....
     Node node = j.parse("x^3");
     Node diff = j.differentiate(node,"x");
     Node simp = j.simplify(diff);
     j.println(simp);
     Node node2 = j.parse("diff(x^4,x)");
     Node proc = j.preprocess(node2);
     Node simp2 = j.simplify(proc);
     j.println(simp2);
     
    Author:
    Rich Morris Created on 16-Nov-2003
    See Also:
    Serialized Form
    • Constructor Detail

      • DJep

        public DJep()
        Standard constructor. Use this instead of Jep or Jep if differentiation facilities are required.
    • Method Detail

      • getDifferentationVisitor

        public DifferentiationVisitor getDifferentationVisitor()
        Returns the visitor used for differentiation. Allows more advanced functions.
      • addStandardDiffRules

        public boolean addStandardDiffRules()
        Adds the standard set of differentiation rules. Corresponds to all standard functions in the Jep plus a few more.
         sin,cos,tan,asin,acos,atan,sinh,cosh,tanh,asinh,acosh,atanh
         sqrt,log,ln,abs,angle
         sum,im,re are handled separately.
         rand and mod currently un-handled
         
         Also adds rules for functions not in Jep function list:
                sec,cosec,cot,exp,pow,sgn 
         
         
        Returns:
        false on error
      • addDiffRule

        public void addDiffRule​(DiffRulesI rule)
        Adds a rule with instruction on how to differentiate a function.
        Parameters:
        rule -
      • differentiate

        public Node differentiate​(Node node,
                                  java.lang.String name)
                           throws ParseException
        Differentiate an equation with respect to a variable.
        Parameters:
        node - top node of the expression tree to differentiate.
        name - differentiate with respect to this variable.
        Returns:
        the top node of a new parse tree representing the derivative.
        Throws:
        ParseException
        java.lang.IllegalArgumentException
      • replacePartialDerivativeByExpressions

        public Node replacePartialDerivativeByExpressions​(Node node)
                                                   throws JepException
        Replace any partial derivatives found in the expression by their expressions.
        Parameters:
        node - expression to process, may be modified
        Returns:
        the expression after replacement
        Throws:
        JepException
      • differentiate

        public DVariable differentiate​(DVariable var,
                                       java.lang.String... names)
                                throws ParseException
        Finds the derivative of a differentiable variable. Will look up existing derivative if it exists or calculate the derivative if needed.
        Parameters:
        var - variable to differentiate
        names - names of the partial derivatives to find, either a single name "x" or an array of names to find higher derivatives
        Returns:
        a variable representing the partial derivative
        Throws:
        ParseException