Class FunctionExpander

java.lang.Object
math.numericalmethods.FunctionExpander

public class FunctionExpander
extends java.lang.Object
Objects of this class take a function as input and convert it into its polynomial form.
Author:
JIBOYE Oluwagbemiro Olaoluwa
  • Field Summary

    Fields 
    Modifier and Type Field Description
    static int BIGDECIMAL_PRECISION
    Uses the precision of double numbers to expand the function.
    static int DOUBLE_PRECISION
    Uses the precision of double numbers to expand the function.
  • Constructor Summary

    Constructors 
    Constructor Description
    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.
    FunctionExpander​(java.lang.String expression, int precision)  
  • Method Summary

    Modifier and Type Method Description
    void buildPolynomial​(int precisionMode)
    Builds the polynomial expansion of the function.
    int getDegree()  
    Function getFunction()  
    Matrix getMatrix()  
    java.lang.String getPolynomial()  
    java.lang.String getPolynomialDerivative()  
    java.lang.String getPolynomialIntegral()  
    PrecisionMatrix getPrecisionMatrix()  
    double getxLower()  
    double getxUpper()  
    static void main​(java.lang.String[] args)  
    void parsePolynomialCommand​(java.lang.String expression)
    Method that processes the format that this software will recognize for user input of an integral expression.
    void setDegree​(int degree)  
    void setFunction​(java.lang.String expression, int precision)  
    void setFunction​(Function function)
    Changes the Function object dealt with by this class.
    void setPolynomial​(java.lang.String polynomial)  
    void setxLower​(double xLower)  
    void setxUpper​(double xUpper)  

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • 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:
      Constant Field Values
    • 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:
      Constant Field Values
  • 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​(java.lang.String expression, int precision)
      Parameters:
      precision - The precision mode to employ in expanding the Function.
      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)
  • Method Details

    • setFunction

      public void setFunction​(java.lang.String expression, int precision)
      Parameters:
      precision - The precision mode to employ in expanding the Function.
      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)
    • 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()
    • setPolynomial

      public void setPolynomial​(java.lang.String polynomial)
    • getPolynomial

      public java.lang.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​(java.lang.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 java.lang.String getPolynomialDerivative()
      Returns:
      the derivative of the polynomial.
    • getPolynomialIntegral

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

      public static void main​(java.lang.String[] args)