Package org.opensourcephysics.numerics
Class Util
java.lang.Object
org.opensourcephysics.numerics.Util
A utility class for numerical analysis.
 This class cannot be subclassed or instantiated because all methods are static.
- Version:
- 1.0
- Author:
- Wolfgang Christian
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final doubleThe default precision for numerical analysis.static final doublestatic final double
- 
Method SummaryModifier and TypeMethodDescriptionstatic intcheckSorting(double[] array) Checks if an array is sorted.static doublecomputeAverage(double[] array, int start, int num) Computes the average value of a subset of an array.static FunctionconstantFunction(double c) Creates a function having a constant value.static doubleEvalautes a mathematical expression without variables.static Stringf2(double d) Convert a double to a string, printing two decimal places.static Stringf3(double d) Convert a double to a string, printing three decimal places.static Stringf4(double d) Convert a double to a string, printing four decimal places.static double[]functionFill(Function f, double start, double stop, double[] data) Fills the given double[n] array with f(x) on the interval [start, stop].static double[][]functionFill(Function f, double start, double stop, double[][] data) Fills the given double[2][n] array with x and f(x) values on interval [start, stop].static Functiongaussian(double x0, double sigma) Creates a Guassian (normal) distribution function.static double[]Gets the approximate range of a function within the given domain.static FunctionlinearFunction(double m, double b) Creates a linear function with the given slope and intercept.static DecimalFormatnewDecimalFormat(String format) static voidnewSpinnerNumberModel(JSpinner spinner, int value, int min, int max, int step) static doublerelativePrecision(double epsilon, double result) Computes the relativePrecision except near zero where the absolute precision is returned.
- 
Field Details- 
SQRT2PIpublic static final double SQRT2PI
- 
LOG10public static final double LOG10
- 
defaultNumericalPrecisionpublic static final double defaultNumericalPrecisionThe default precision for numerical analysis.
 
- 
- 
Method Details- 
newDecimalFormat
- 
f2Convert a double to a string, printing two decimal places.- Parameters:
- d- Input double
 
- 
f3Convert a double to a string, printing three decimal places.- Parameters:
- d- Input double
 
- 
f4Convert a double to a string, printing four decimal places.- Parameters:
- d- Input double
 
- 
relativePrecisionpublic static double relativePrecision(double epsilon, double result) Computes the relativePrecision except near zero where the absolute precision is returned.- Parameters:
- epsilon- the absolute error
- result- the result
- Returns:
- the relative error
 
- 
checkSortingpublic static int checkSorting(double[] array) Checks if an array is sorted. Returns: Positive integer if array is sorted in increasing value. Negative integer if array is sorted in decreasing value. Zero if array is not sorted.- Parameters:
- array- double[]
- Returns:
- int 1,0,-1 based on sorting
 
- 
getRangeGets the approximate range of a function within the given domain. The range is deterermiend by evaluating the function at n points and finding the minimum and maximum values.- Parameters:
- f- Function
- a- double
- b- double
- n- int
- Returns:
- double[]
 
- 
functionFillFills the given double[2][n] array with x and f(x) values on interval [start, stop].- Parameters:
- f- Function
- start- double
- stop- double
- data- double[][]
- Returns:
- double[][]
 
- 
functionFillFills the given double[n] array with f(x) on the interval [start, stop].- Parameters:
- f- Function
- start- double starting value of x
- stop- double stopping value of x
- data- double[]
- Returns:
- double[]
 
- 
computeAveragepublic static double computeAverage(double[] array, int start, int num) Computes the average value of a subset of an array.- Parameters:
- array- the data to be averaged
- start- the index of the first point to be averaged
- num- the total number of points to be averaged
- Returns:
 
- 
constantFunctionCreates a function having a constant value.- Parameters:
- c-
- Returns:
 
- 
linearFunctionCreates a linear function with the given slope and intercept.- Parameters:
- m- double slope
- b- double intercept
- Returns:
- Function
 
- 
gaussianCreates a Guassian (normal) distribution function. The distribution is normalized. The full width at half maximum is 2*sigma*Math.sqrt(2 Math.log(2)) ~ 2.3548*sigma- Parameters:
- x0- double center of the distribution
- sigma- double width of the distributuon
- Returns:
- Function
 
- 
evalMathEvalautes a mathematical expression without variables.- Parameters:
- str- String
- Returns:
- double
 
- 
newSpinnerNumberModel
 
-