Class FunctionExpander
java.lang.Object
math.numericalmethods.FunctionExpander
Objects of this class take a function as input and convert it into its
polynomial form.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classFinds the derivative of polynomial functions generated from above. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intUses the precision of double numbers to expand the function.private intThe degree of the polynomial.static final intUses the precision of double numbers to expand the function.private FunctionThe function string.private StringThe polynomial generated.private doubleThe lower boundary value of x.private doubleThe upper boundary value of x. -
Constructor Summary
ConstructorsConstructorDescriptionFunctionExpander(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(String expression, int precision) -
Method Summary
Modifier and TypeMethodDescriptionvoidbuildPolynomial(int precisionMode) Builds the polynomial expansion of the function.intdoubleprivate doublegetXStep()doublestatic voidvoidparsePolynomialCommand(String expression) Method that processes the format that this software will recognize for user input of an integral expression.voidsetDegree(int degree) voidsetFunction(String expression, int precision) voidsetFunction(Function function) Changes the Function object dealt with by this class.voidsetPolynomial(String polynomial) voidsetxLower(double xLower) voidsetxUpper(double xUpper)
-
Field Details
-
degree
private int degreeThe 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 xUpperThe upper boundary value of x. -
xLower
private double xLowerThe lower boundary value of x. -
function
The function string. -
polynomial
The polynomial generated. -
DOUBLE_PRECISION
public static final int DOUBLE_PRECISIONUses 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_PRECISIONUses 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
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)/polySizeprecision- The precision mode to employ in expanding the Function.function- The function string.
-
FunctionExpander
- 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
- 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
Changes the Function object dealt with by this class.- Parameters:
function- The new Function object
-
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
-
getPolynomial
-
getMatrix
- Returns:
- the coefficient matrix of the function's polynomial.
-
getPrecisionMatrix
- Returns:
- the coefficient matrix of the function's polynomial.
-
parsePolynomialCommand
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
- Returns:
- the derivative of the polynomial.
-
getPolynomialIntegral
- Returns:
- the integral of the polynomial.
-
main
-