Class FunctionExpander

java.lang.Object
math.numericalmethods.FunctionExpander

public class FunctionExpander extends Object
Objects of this class take a function as input and convert it into its polynomial form.
  • Field Details

    • degree

      private int degree
      The degree of the polynomial. It determines how accurately the polynomial will describe the function. The unit step along x will then be (xUpper - xLower)/polySize
    • xUpper

      private double xUpper
      The upper boundary value of x.
    • xLower

      private double xLower
      The lower boundary value of x.
    • function

      private Function function
      The function string.
    • polynomial

      private String polynomial
      The polynomial generated.
    • DOUBLE_PRECISION

      public static final int DOUBLE_PRECISION
      Uses the precision of double numbers to expand the function. This is about 16 places of decimal.
      See Also:
    • BIGDECIMAL_PRECISION

      public static final int BIGDECIMAL_PRECISION
      Uses the precision of double numbers to expand the function. This is about 33 places of decimal.
      CAUTION!!!!
      This should be used only if the algorithm of the parser that expands the function has this accuracy.
      See Also:
  • Constructor Details

    • FunctionExpander

      public FunctionExpander(double xLower, double xUpper, int degree, int precision, Function function)
      Objects of this class will employ this constructor in creating the polynomial of best fit for the input function between the given boundary values of x. The degree parameter is the highest power of the polynomial formed. Creates a new object of this class and initializes it with the following attributes:
      Parameters:
      xLower - The lower boundary value of x.
      degree - The degree of the polynomial. It determines how accurately the polynomial will describe the function. The unit step along x will then be (xUpper - xLower)/polySize
      precision - The precision mode to employ in expanding the Function.
      function - The function string.
    • FunctionExpander

      public FunctionExpander(String expression, int precision)
      Parameters:
      expression - An expression containing information about the function whose polynomial expansion is to be deduced and the limits of expansion. For example: function,2,4,20....means expand the function between horizontal coordinates 2 and 3 as a polynomial up to degree 20.. Direct examples would be: sin(x+1),3,4,20 cos(sinh(x-2/tan9x)),4,4.32,32 and so on. F(x)=var x=3;3x; poly(F,4,4.32,32)
      precision - The precision mode to employ in expanding the Function.
  • Method Details

    • setFunction

      public void setFunction(String expression, int precision)
      Parameters:
      expression - An expression containing information about the function whose polynomial expansion is to be deduced and the limits of expansion. For example: function,2,4,20....means expand the function between horizontal coordinates 2 and 3 as a polynomial up to degree 20.. Direct examples would be: sin(x+1),3,4,20 cos(sinh(x-2/tan9x)),4,4.32,32 and so on. F(x)=var x=3;3x; poly(F,4,4.32,32)
      precision - The precision mode to employ in expanding the Function.
    • setFunction

      public void setFunction(Function function)
      Changes the Function object dealt with by this class.
      Parameters:
      function - The new Function object
    • getFunction

      public Function getFunction()
    • getDegree

      public int getDegree()
    • setDegree

      public void setDegree(int degree)
    • setxLower

      public void setxLower(double xLower)
    • getxLower

      public double getxLower()
    • setxUpper

      public void setxUpper(double xUpper)
    • getxUpper

      public double getxUpper()
    • getXStep

      private double getXStep()
      Returns:
      the unit step along x.
    • setPolynomial

      public void setPolynomial(String polynomial)
    • getPolynomial

      public String getPolynomial()
    • getMatrix

      public Matrix getMatrix()
      Returns:
      the coefficient matrix of the function's polynomial.
    • getPrecisionMatrix

      public PrecisionMatrix getPrecisionMatrix()
      Returns:
      the coefficient matrix of the function's polynomial.
    • parsePolynomialCommand

      public void parsePolynomialCommand(String expression)
      Method that processes the format that this software will recognize for user input of an integral expression. The general format is: expression,lowerLimit,upperLimit,iterations(optional) e.g... sin(3x-5),2,5.//assuming default number of iterations which will be computed automatically sin(3x-5),2,5,50.//specifies 50 iterations. Please ensure that the function is continuous in the specified range.
      Parameters:
      expression - The expression containing the function to integrate and the lower and upper boundaries of integration. Produces an array which has: At index 0.....the expression to integrate At index 1.....the lower limit of integration At index 2.....the upper limit of integration. At index 3(optional)...the number of iterations to employ in evaluating this expression. F(x)=3x+1; poly( F,0,2,3 ) poly(F(x)=3x+1,0,2,5) OR poly(F(x),0,2,5) OR poly(F,0,2,5)
    • buildPolynomial

      public void buildPolynomial(int precisionMode)
      Builds the polynomial expansion of the function.
      Parameters:
      precisionMode - The precision mode to employ in expanding the Function.
    • getPolynomialDerivative

      public String getPolynomialDerivative()
      Returns:
      the derivative of the polynomial.
    • getPolynomialIntegral

      public String getPolynomialIntegral()
      Returns:
      the integral of the polynomial.
    • main

      public static void main(String[] args)