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 Summary
FieldsModifier and TypeFieldDescriptionstatic final double
The default precision for numerical analysis.static final double
static final double
-
Method Summary
Modifier and TypeMethodDescriptionstatic int
checkSorting
(double[] array) Checks if an array is sorted.static double
computeAverage
(double[] array, int start, int num) Computes the average value of a subset of an array.static Function
constantFunction
(double c) Creates a function having a constant value.static double
Evalautes a mathematical expression without variables.static String
f2
(double d) Convert a double to a string, printing two decimal places.static String
f3
(double d) Convert a double to a string, printing three decimal places.static String
f4
(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 Function
gaussian
(double x0, double sigma) Creates a Guassian (normal) distribution function.static double[]
Gets the approximate range of a function within the given domain.static Function
linearFunction
(double m, double b) Creates a linear function with the given slope and intercept.static DecimalFormat
newDecimalFormat
(String format) static void
newSpinnerNumberModel
(JSpinner spinner, int value, int min, int max, int step) static double
relativePrecision
(double epsilon, double result) Computes the relativePrecision except near zero where the absolute precision is returned.
-
Field Details
-
SQRT2PI
public static final double SQRT2PI -
LOG10
public static final double LOG10 -
defaultNumericalPrecision
public static final double defaultNumericalPrecisionThe default precision for numerical analysis.
-
-
Method Details
-
newDecimalFormat
-
f2
Convert a double to a string, printing two decimal places.- Parameters:
d
- Input double
-
f3
Convert a double to a string, printing three decimal places.- Parameters:
d
- Input double
-
f4
Convert a double to a string, printing four decimal places.- Parameters:
d
- Input double
-
relativePrecision
public static double relativePrecision(double epsilon, double result) Computes the relativePrecision except near zero where the absolute precision is returned.- Parameters:
epsilon
- the absolute errorresult
- the result- Returns:
- the relative error
-
checkSorting
public 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
-
getRange
Gets 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
- Functiona
- doubleb
- doublen
- int- Returns:
- double[]
-
functionFill
Fills the given double[2][n] array with x and f(x) values on interval [start, stop].- Parameters:
f
- Functionstart
- doublestop
- doubledata
- double[][]- Returns:
- double[][]
-
functionFill
Fills the given double[n] array with f(x) on the interval [start, stop].- Parameters:
f
- Functionstart
- double starting value of xstop
- double stopping value of xdata
- double[]- Returns:
- double[]
-
computeAverage
public 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 averagedstart
- the index of the first point to be averagednum
- the total number of points to be averaged- Returns:
-
constantFunction
Creates a function having a constant value.- Parameters:
c
-- Returns:
-
linearFunction
Creates a linear function with the given slope and intercept.- Parameters:
m
- double slopeb
- double intercept- Returns:
- Function
-
gaussian
Creates 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 distributionsigma
- double width of the distributuon- Returns:
- Function
-
evalMath
Evalautes a mathematical expression without variables.- Parameters:
str
- String- Returns:
- double
-
newSpinnerNumberModel
-