Package org.opensourcephysics.numerics
Class Integral
java.lang.Object
org.opensourcephysics.numerics.Integral
Class Integral defines various integration algorithms.
This class cannot be subclassed or instantiated because all methods are static.
- Author:
- Wolfgang Christian
-
Method Summary
Modifier and TypeMethodDescriptionstatic double[][]Fills the given data array with the intgral of the given function.static double[][]Fills a data array with the integral of the given function.static doubleComputes the integral of the function using an ODE solver.static doubleIntegrates the function using Romberg's algorithm based on Richardson's deferred approach.static doublesimpson(double[] f, double h) Uses Simpson's rule to find the area of an array representing a function that's been evaluated at N intervals of size h, where N is an odd integer.static doubleNumerical integration using Simpson's rule.static doubleNumerical integration using Simpson's rule.static doubletrapezoidal(Function f, double start, double stop, int n, double tol) Integrates the function using the trapezoidal method.
-
Method Details
-
trapezoidal
Integrates the function using the trapezoidal method.- Parameters:
f- the functionstart- the first ordinate.stop- the last ordinate.n- the number of partitionstol- relative tolerance- Returns:
- the integral
-
simpson
public static double simpson(Function f, double start, double stop, int n) throws IllegalArgumentException Numerical integration using Simpson's rule.- Parameters:
f- a function.start- the first ordinate.stop- the last ordinate.n- the number of partitions- Returns:
- the integral
- Throws:
IllegalArgumentException
-
simpson
Numerical integration using Simpson's rule.- Parameters:
f- the functionstart- the first ordinate.stop- the last ordinate.n- minimum number of partitionstol- relative tolerance- Returns:
- the integral
-
romberg
Integrates the function using Romberg's algorithm based on Richardson's deferred approach.- Parameters:
f- the functiona-b-n-tol- tolerance- Returns:
- the integral
-
simpson
public static double simpson(double[] f, double h) Uses Simpson's rule to find the area of an array representing a function that's been evaluated at N intervals of size h, where N is an odd integer. Example of usage: int N=27; x=new double[N]; f=new double[N]; double a=0, b=5, h=(b-a)/(N-1); for (int i=0; i< N;i++){ x[i]=a+i*h; f[i]=x[i]*Math.exp(x[i]); } double sum=Simp.Simp(f,h); Results: sum=594.6615858178942 -
ode
Computes the integral of the function using an ODE solver.- Parameters:
f- the functionstart-stop-tol- relative tolerance- Returns:
- the integral
-
fillArray
Fills a data array with the integral of the given function.- Parameters:
f- Function to be integratedstart- double start of integralstop- double end of integraltol- double computation tolerancen- int number of data points- Returns:
- double[][]
-
fillArray
public static double[][] fillArray(Function f, double start, double stop, double tol, double[][] data) Fills the given data array with the intgral of the given function.- Parameters:
f- Function to be integratedstart- double start of integralstop- double end of integraltol- double computation tolerancedata- double[][]- Returns:
- double[][]
-