Package math.numericalmethods
Class NumericalIntegral
java.lang.Object
math.numericalmethods.NumericalIntegral
public class NumericalIntegral
extends java.lang.Object
Objects of this class are able
to perform numerical integration
of a curve within a given range
given that the function is continuous
throughout that range.
- Author:
- JIBOYE Oluwagbemiro Olaoluwa
-
Field Summary
Fields Modifier and Type Field Description static intFUNCTIONAL_INTEGRATIONUse this to integrate without using the integral symbol.static intSYMBOLIC_INTEGRATIONUse this to integrate using the integral symbol. -
Constructor Summary
Constructors Constructor Description NumericalIntegral(double xLower, double xUpper, int iterations, java.lang.String function)NumericalIntegral(java.lang.String expression, int chooseExpressionType) -
Method Summary
Modifier and Type Method Description static voidextractFunctionStringFromExpression(java.util.List<java.lang.String> list)Analyzes the list and extracts the Function string from it.doublefindAdvancedPolynomialIntegral()Algorithm that combines a variant of the Simpson rule and the polynomial rule to produce higher accuracy integrals.doublefindGaussianQuadrature()doublefindHighRangeIntegral()Determines the integral in a given range by splitting the range into sub-ranges of width that are at most 0.1 units along x, and finding the polynomial curve for each sub-range.doublefindHighRangeIntegralWithAdvancedPolynomial()Determines the integral in a given range by splitting the range into sub-ranges of width that are at most 0.1 units along x, and finding the polynomial curve for each sub-range.doublefindPolynomialIntegral()java.lang.StringfindSimpsonIntegral()java.lang.StringfindSimpsonIntegral(double h)java.lang.StringfindTrapezoidalIntegral()java.lang.StringfindTrapezoidalIntegral(double h)FunctiongetFunction()intgetIterations()java.lang.StringgetVariable()doublegetxLower()doublegetxUpper()static voidmain(java.lang.String[] args)voidsetFunction(Function function)voidsetIterations(int iterations)Set the number of iterations and ensure that it is even.voidsetxLower(double xLower)voidsetxUpper(double xUpper)
-
Field Details
-
SYMBOLIC_INTEGRATION
public static final int SYMBOLIC_INTEGRATIONUse this to integrate using the integral symbol.- See Also:
- Constant Field Values
-
FUNCTIONAL_INTEGRATION
public static final int FUNCTIONAL_INTEGRATIONUse this to integrate without using the integral symbol. Here, the intg() command containing the function and the bounds are specified.- See Also:
- Constant Field Values
-
-
Constructor Details
-
NumericalIntegral
public NumericalIntegral(double xLower, double xUpper, int iterations, java.lang.String function)- Parameters:
xLower- The lower limit of xxUpper- The upper limit of xiterations- The number of iterationsfunction- The name of a Function that has been defined before in the WorkSpace or an anonymous Function just specified.
-
NumericalIntegral
public NumericalIntegral(java.lang.String expression, int chooseExpressionType)- Parameters:
expression- An expression containing information about the function whose integral is to be evaluated and the limits of integration. For example: function,2,4....means integrate function between horizontal coordinates 2 and 3. Direct examples would be: sin(x+1),3,4 cos(sinh(x-2/tan9x)),4,4.32 and so on.chooseExpressionType- Determines if the expression to integrate contains the integral symbol or not. F(x) = sin(x)/2x; intg(F(x),0,2,iterations)
-
-
Method Details
-
setIterations
public void setIterations(int iterations)Set the number of iterations and ensure that it is even.- Parameters:
iterations-
-
getIterations
public int getIterations()- Returns:
- the number of iterations.
-
getFunction
-
setFunction
-
getxLower
public double getxLower() -
setxLower
public void setxLower(double xLower) -
getxUpper
public double getxUpper() -
setxUpper
public void setxUpper(double xUpper) -
findSimpsonIntegral
public java.lang.String findSimpsonIntegral()- Returns:
- the Simpson integral of the function Simpson's rule requires an even number of rectangular strips and so an odd number of ordinates(y-coordinates) The x distances must also be equal. h= (xUpper-xLower)/(2*m)
-
findSimpsonIntegral
public java.lang.String findSimpsonIntegral(double h)- Returns:
- the Simpson integral of the function Simpson's rule requires an even number of rectangular strips and so an odd number of ordinates(y-coordinates) The x distances must also be equal. h= (xUpper-xLower)/(2*m)
-
findTrapezoidalIntegral
public java.lang.String findTrapezoidalIntegral()- Returns:
- the integral of the function using the trapezoidal rule.
-
findTrapezoidalIntegral
public java.lang.String findTrapezoidalIntegral(double h)- Returns:
- the integral of the function using the trapezoidal rule.
-
findPolynomialIntegral
public double findPolynomialIntegral()- Returns:
- the integral of the function using the polynomial rule.
-
findHighRangeIntegralWithAdvancedPolynomial
public double findHighRangeIntegralWithAdvancedPolynomial()Determines the integral in a given range by splitting the range into sub-ranges of width that are at most 0.1 units along x, and finding the polynomial curve for each sub-range.- Returns:
- the integral of the function using the trapezoidal rule.
-
findHighRangeIntegral
public double findHighRangeIntegral()Determines the integral in a given range by splitting the range into sub-ranges of width that are at most 0.1 units along x, and finding the polynomial curve for each sub-range.- Returns:
- the integral of the function using the trapezoidal rule.
-
findGaussianQuadrature
public double findGaussianQuadrature()- Returns:
- The Gaussian Quadrature Version.
-
findAdvancedPolynomialIntegral
public double findAdvancedPolynomialIntegral()Algorithm that combines a variant of the Simpson rule and the polynomial rule to produce higher accuracy integrals. -
extractFunctionStringFromExpression
public static void extractFunctionStringFromExpression(java.util.List<java.lang.String> list)Analyzes the list and extracts the Function string from it.- Parameters:
list- The list to be analyzed. Direct examples would be: intg(@sin(x+1),4,7) intg(F,4,7) where F is a function that has been defined before in the workspace.. and so on. Simplifies the list to the form intg(funcName,x1,x2) or intg(funcName,x1,x2,iterations)
-
getVariable
public java.lang.String getVariable() -
main
public static void main(java.lang.String[] args)
-