本文整理汇总了Java中org.apache.commons.math.util.FastMath.sqrt方法的典型用法代码示例。如果您正苦于以下问题:Java FastMath.sqrt方法的具体用法?Java FastMath.sqrt怎么用?Java FastMath.sqrt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.math.util.FastMath
的用法示例。
在下文中一共展示了FastMath.sqrt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateJacobian
import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/**
* Update the jacobian matrix.
*
* @throws DimensionMismatchException if the Jacobian dimension does not
* match problem dimension.
* @throws org.apache.commons.math.exception.MathUserException if the jacobian
* function throws one.
*/
protected void updateJacobian() {
++jacobianEvaluations;
weightedResidualJacobian = jF.value(point);
if (weightedResidualJacobian.length != rows) {
throw new DimensionMismatchException(weightedResidualJacobian.length, rows);
}
final double[] residualsWeights = getWeightRef();
for (int i = 0; i < rows; i++) {
final double[] ji = weightedResidualJacobian[i];
double wi = FastMath.sqrt(residualsWeights[i]);
for (int j = 0; j < cols; ++j) {
//ji[j] *= -1.0;
weightedResidualJacobian[i][j] = -ji[j]*wi;
}
}
}
示例2: estimateError
import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
protected double estimateError(final double[][] yDotK,
final double[] y0, final double[] y1,
final double h) {
double error = 0;
for (int j = 0; j < mainSetDimension; ++j) {
double errSum = STATIC_E[0] * yDotK[0][j];
for (int l = 1; l < STATIC_E.length; ++l) {
errSum += STATIC_E[l] * yDotK[l][j];
}
final double yScale = FastMath.max(FastMath.abs(y0[j]), FastMath.abs(y1[j]));
final double tol = (vecAbsoluteTolerance == null) ?
(scalAbsoluteTolerance + scalRelativeTolerance * yScale) :
(vecAbsoluteTolerance[j] + vecRelativeTolerance[j] * yScale);
final double ratio = h * errSum / tol;
error += ratio * ratio;
}
return FastMath.sqrt(error / mainSetDimension);
}
示例3: trialDivision
import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/**
* Factorization by trial division.
*
* @param n the number to factor
* @return the list of prime factors of n
*/
public static List<Integer> trialDivision(int n) {
final List<Integer> factors = new ArrayList<Integer>(32);
n = smallTrialDivision(n, factors);
if (1 == n) {
return factors;
}
// here we are sure that n is either a prime or a semi prime
final int bound = (int) FastMath.sqrt(n);
boundedTrialDivision(n, bound, factors);
return factors;
}
示例4: testAxisAngle
import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
@Test
public void testAxisAngle() {
Rotation r = new Rotation(new Vector3D(10, 10, 10), 2 * FastMath.PI / 3);
checkVector(r.applyTo(Vector3D.PLUS_I), Vector3D.PLUS_J);
checkVector(r.applyTo(Vector3D.PLUS_J), Vector3D.PLUS_K);
checkVector(r.applyTo(Vector3D.PLUS_K), Vector3D.PLUS_I);
double s = 1 / FastMath.sqrt(3);
checkVector(r.getAxis(), new Vector3D(s, s, s));
checkAngle(r.getAngle(), 2 * FastMath.PI / 3);
try {
new Rotation(new Vector3D(0, 0, 0), 2 * FastMath.PI / 3);
Assert.fail("an exception should have been thrown");
} catch (ArithmeticException e) {
}
r = new Rotation(Vector3D.PLUS_K, 1.5 * FastMath.PI);
checkVector(r.getAxis(), new Vector3D(0, 0, -1));
checkAngle(r.getAngle(), 0.5 * FastMath.PI);
r = new Rotation(Vector3D.PLUS_J, FastMath.PI);
checkVector(r.getAxis(), Vector3D.PLUS_J);
checkAngle(r.getAngle(), FastMath.PI);
checkVector(Rotation.IDENTITY.getAxis(), Vector3D.PLUS_I);
}
示例5: getFrobeniusNorm
import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
public double getFrobeniusNorm() {
double sum2 = 0;
for (int blockIndex = 0; blockIndex < blocks.length; ++blockIndex) {
for (final double entry : blocks[blockIndex]) {
sum2 += entry * entry;
}
}
return FastMath.sqrt(sum2);
}
示例6: distance
import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/** {@inheritDoc} */
public double distance(Vector<Euclidean3D> v) {
final Vector3D v3 = (Vector3D) v;
final double dx = v3.x - x;
final double dy = v3.y - y;
final double dz = v3.z - z;
return FastMath.sqrt(dx * dx + dy * dy + dz * dz);
}
示例7: getDistance
import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
public double getDistance(double[] v) {
checkVectorDimensions(v.length);
double sum = 0;
for (int i = 0; i < data.length; ++i) {
final double delta = data[i] - v[i];
sum += delta * delta;
}
return FastMath.sqrt(sum);
}
示例8: getNorm
import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
public double getNorm() {
double sum = 0;
for (double a : data) {
sum += a * a;
}
return FastMath.sqrt(sum);
}
示例9: computeTheoreticalState
import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
@Override
public double[] computeTheoreticalState(double t) {
// solve Kepler's equation
double E = t;
double d = 0;
double corr = 999.0;
for (int i = 0; (i < 50) && (FastMath.abs(corr) > 1.0e-12); ++i) {
double f2 = e * FastMath.sin(E);
double f0 = d - f2;
double f1 = 1 - e * FastMath.cos(E);
double f12 = f1 + f1;
corr = f0 * f12 / (f1 * f12 - f0 * f2);
d -= corr;
E = t + d;
}
double cosE = FastMath.cos(E);
double sinE = FastMath.sin(E);
y[0] = cosE - e;
y[1] = FastMath.sqrt(1 - e * e) * sinE;
y[2] = -sinE / (1 - e * cosE);
y[3] = FastMath.sqrt(1 - e * e) * cosE / (1 - e * cosE);
return y;
}
示例10: getDistance
import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
public double getDistance(RealVector v) {
if (v instanceof ArrayRealVector) {
return getDistance((ArrayRealVector) v);
} else {
checkVectorDimensions(v);
double sum = 0;
for (int i = 0; i < data.length; ++i) {
final double delta = data[i] - v.getEntry(i);
sum += delta * delta;
}
return FastMath.sqrt(sum);
}
}
示例11: initializeStep
import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/** Initialize the integration step.
* @param equations differential equations set
* @param forward forward integration indicator
* @param order order of the method
* @param scale scaling vector for the state vector (can be shorter than state vector)
* @param t0 start time
* @param y0 state vector at t0
* @param yDot0 first time derivative of y0
* @param y1 work array for a state vector
* @param yDot1 work array for the first time derivative of y1
* @return first integration step
* @exception MathUserException this exception is propagated to
* the caller if the underlying user function triggers one
*/
public double initializeStep(final FirstOrderDifferentialEquations equations,
final boolean forward, final int order, final double[] scale,
final double t0, final double[] y0, final double[] yDot0,
final double[] y1, final double[] yDot1)
throws MathUserException {
if (initialStep > 0) {
// use the user provided value
return forward ? initialStep : -initialStep;
}
// very rough first guess : h = 0.01 * ||y/scale|| / ||y'/scale||
// this guess will be used to perform an Euler step
double ratio;
double yOnScale2 = 0;
double yDotOnScale2 = 0;
for (int j = 0; j < scale.length; ++j) {
ratio = y0[j] / scale[j];
yOnScale2 += ratio * ratio;
ratio = yDot0[j] / scale[j];
yDotOnScale2 += ratio * ratio;
}
double h = ((yOnScale2 < 1.0e-10) || (yDotOnScale2 < 1.0e-10)) ?
1.0e-6 : (0.01 * FastMath.sqrt(yOnScale2 / yDotOnScale2));
if (! forward) {
h = -h;
}
// perform an Euler step using the preceding rough guess
for (int j = 0; j < y0.length; ++j) {
y1[j] = y0[j] + h * yDot0[j];
}
computeDerivatives(t0 + h, y1, yDot1);
// estimate the second derivative of the solution
double yDDotOnScale = 0;
for (int j = 0; j < scale.length; ++j) {
ratio = (yDot1[j] - yDot0[j]) / scale[j];
yDDotOnScale += ratio * ratio;
}
yDDotOnScale = FastMath.sqrt(yDDotOnScale) / h;
// step size is computed such that
// h^order * max (||y'/tol||, ||y''/tol||) = 0.01
final double maxInv2 = FastMath.max(FastMath.sqrt(yDotOnScale2), yDDotOnScale);
final double h1 = (maxInv2 < 1.0e-15) ?
FastMath.max(1.0e-6, 0.001 * FastMath.abs(h)) :
FastMath.pow(0.01 / maxInv2, 1.0 / order);
h = FastMath.min(100.0 * FastMath.abs(h), h1);
h = FastMath.max(h, 1.0e-12 * FastMath.abs(t0)); // avoids cancellation when computing t1 - t0
if (h < getMinStep()) {
h = getMinStep();
}
if (h > getMaxStep()) {
h = getMaxStep();
}
if (! forward) {
h = -h;
}
return h;
}
示例12: inversetransform2
import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/**
* Inversely transform the given real function, sampled on the given interval.
* <p>
* The formula is $x_k = (1/\sqrt{N}) \Sigma_{n=0}^{N-1} e^{2 \pi i nk/N} y_n$
* </p>
*
* @param f the function to be sampled and inversely transformed
* @param min the lower bound for the interval
* @param max the upper bound for the interval
* @param n the number of sample points
* @return the complex inversely transformed array
* @throws MathUserException if function cannot be evaluated
* at some point
* @throws IllegalArgumentException if any parameters are invalid
*/
public Complex[] inversetransform2(UnivariateRealFunction f,
double min, double max, int n)
throws MathUserException, IllegalArgumentException {
double data[] = sample(f, min, max, n);
double scaling_coefficient = 1.0 / FastMath.sqrt(n);
return scaleArray(fft(data, true), scaling_coefficient);
}
示例13: transform2
import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/**
* Transform the given real function, sampled on the given interval.
* <p>
* The formula is F<sub>n</sub> = √(1/2N) [f<sub>0</sub> + (-1)<sup>n</sup> f<sub>N</sub>] +
* √(2/N) ∑<sub>k=1</sub><sup>N-1</sup> f<sub>k</sub> cos(π nk/N)
*
* </p>
*
* @param f the function to be sampled and transformed
* @param min the lower bound for the interval
* @param max the upper bound for the interval
* @param n the number of sample points
* @return the real transformed array
* @throws MathUserException if function cannot be evaluated
* at some point
* @throws IllegalArgumentException if any parameters are invalid
*/
public double[] transform2(UnivariateRealFunction f,
double min, double max, int n)
throws MathUserException, IllegalArgumentException {
double data[] = FastFourierTransformer.sample(f, min, max, n);
double scaling_coefficient = FastMath.sqrt(2.0 / (n-1));
return FastFourierTransformer.scaleArray(fct(data), scaling_coefficient);
}
示例14: transform2
import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/**
* Transform the given real data set.
* <p>
* The formula is $y_n = (1/\sqrt{N}) \Sigma_{k=0}^{N-1} e^{-2 \pi i nk/N} x_k$
* </p>
*
* @param f the real data array to be transformed
* @return the complex transformed array
* @throws IllegalArgumentException if any parameters are invalid
*/
public Complex[] transform2(double f[])
throws IllegalArgumentException {
double scaling_coefficient = 1.0 / FastMath.sqrt(f.length);
return scaleArray(fft(f, false), scaling_coefficient);
}
示例15: distance
import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/** Compute the distance between two vectors according to the L<sub>2</sub> norm.
* <p>Calling this method is equivalent to calling:
* <code>v1.subtract(v2).getNorm()</code> except that no intermediate
* vector is built</p>
* @param v1 first vector
* @param v2 second vector
* @return the distance between v1 and v2 according to the L<sub>2</sub> norm
*/
public static double distance(Vector3D v1, Vector3D v2) {
final double dx = v2.x - v1.x;
final double dy = v2.y - v1.y;
final double dz = v2.z - v1.z;
return FastMath.sqrt(dx * dx + dy * dy + dz * dz);
}