|
SSJ V. 2.0. |
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectumontreal.iro.lecuyer.functions.MathFunctionUtil
public class MathFunctionUtil
Provides utility methods for computing derivatives and integrals of functions.
| Field Summary | |
|---|---|
static double |
H
|
static int |
NUMINTERVALS
|
| Method Summary | |
|---|---|
static double |
derivative(MathFunction func,
double x)
Returns the first derivative of the function func evaluated at x. |
static double |
derivative(MathFunction func,
double x,
int n)
Returns the nth derivative of function func evaluated at x. |
static double |
finiteCenteredDifferenceDerivative(MathFunction func,
double x,
double h)
Returns (f (x + h) - f (x - h))/(2h), an estimate of the first derivative of f (x) using centered differences. |
static double |
finiteCenteredDifferenceDerivative(MathFunction func,
double x,
int n,
double h)
Computes and returns an estimate of the nth derivative of the function f (x) using finite centered differences. |
static double |
finiteDifferenceDerivative(MathFunction func,
double x,
int n,
double h)
Computes and returns an estimate of the nth derivative of the function f (x). |
static double |
integral(MathFunction func,
double a,
double b)
Returns the integral of the function func over [a, b]. |
static double[][] |
removeNaNs(double[] x,
double[] y)
Removes any point (NaN, y) or (x, NaN) from x and y, and returns a 2D array containing the filtered points. |
static double |
simpsonIntegral(MathFunction func,
double a,
double b,
int numIntervals)
Computes and returns an approximation of the integral of func over [a, b], using the Simpsons 1/3 method with numIntervals intervals. |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static double H
public static int NUMINTERVALS
| Method Detail |
|---|
public static double derivative(MathFunction func,
double x)
MathFunctionWithFirstDerivative, this method calls
MathFunctionWithFirstDerivative.derivative (double).
Otherwise, if the function implements MathFunctionWithDerivative,
this method calls
MathFunctionWithDerivative.derivative (double, int).
If the function does not implement any of these two interfaces, the method
uses finiteCenteredDifferenceDerivative (MathFunction,
double, double) to obtain an estimate of the derivative.
func - the function to derivate.x - the evaluation point.
public static double derivative(MathFunction func,
double x,
int n)
derivative (MathFunction, double)
and returns the resulting first derivative.
Otherwise,
if the function implements
MathFunctionWithDerivative,
this method calls
MathFunctionWithDerivative.derivative (double, int).
If the function does not implement this
interface,
the method uses
finiteCenteredDifferenceDerivative (MathFunction, double, int, double)
if n is even, or
finiteDifferenceDerivative (MathFunction, double, int, double)
if n is odd,
to obtain a numerical approximation of the derivative.
func - the function to derivate.x - the evaluation point.n - the order of the derivative.
public static double finiteDifferenceDerivative(MathFunction func,
double x,
int n,
double h)
,
func - the function to derivate.x - the evaluation point.n - the order of the derivative.h - the error.
public static double finiteCenteredDifferenceDerivative(MathFunction func,
double x,
double h)
func - the function to derivate.x - the evaluation point.h - the error.
public static double finiteCenteredDifferenceDerivative(MathFunction func,
double x,
int n,
double h)
finiteDifferenceDerivative (func, x - ε*n/2, n, h), with
h = εn.
func - the function to derivate.x - the evaluation point.n - the order of the derivative.h - the error.
public static double[][] removeNaNs(double[] x,
double[] y)
x - the X coordinates.y - the Y coordinates.
public static double integral(MathFunction func,
double a,
double b)
MathFunctionWithIntegral,
this returns
MathFunctionWithIntegral.integral (double, double).
Otherwise, this calls
simpsonIntegral (MathFunction, double, double, int)
with NUMINTERVALS intervals.
func - the function to integrate.a - the lower bound.b - the upper bound.
public static double simpsonIntegral(MathFunction func,
double a,
double b,
int numIntervals)
(f (a) + 4f (a + h) + 2f (a + 2h) + 4f (a + 3h) + ... + f (b))
func - the function being integrated.a - the left boundb - the right bound.numIntervals - the number of intervals.
|
SSJ V. 2.0. |
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||