本文整理汇总了Java中org.apache.commons.math.util.FastMath.cos方法的典型用法代码示例。如果您正苦于以下问题:Java FastMath.cos方法的具体用法?Java FastMath.cos怎么用?Java FastMath.cos使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.math.util.FastMath
的用法示例。
在下文中一共展示了FastMath.cos方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testParametricGradient
import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
@Test
public void testParametricGradient() {
final double amplitude = 2;
final double omega = 3;
final double phase = 4;
final HarmonicOscillator.Parametric f = new HarmonicOscillator.Parametric();
final double x = 1;
final double[] grad = f.gradient(1, new double[] {amplitude, omega, phase});
final double xTimesOmegaPlusPhase = omega * x + phase;
final double a = FastMath.cos(xTimesOmegaPlusPhase);
Assert.assertEquals(a, grad[0], EPS);
final double w = -amplitude * x * FastMath.sin(xTimesOmegaPlusPhase);
Assert.assertEquals(w, grad[1], EPS);
final double p = -amplitude * FastMath.sin(xTimesOmegaPlusPhase);
Assert.assertEquals(p, grad[2], EPS);
}
示例2: computeOmega
import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/** Computes the n<sup>th</sup> roots of unity.
* <p>The computed omega[] = { 1, w, w<sup>2</sup>, ... w<sup>(n-1)</sup> } where
* w = exp(-2 π i / n), i = &sqrt;(-1).</p>
* <p>Note that n is positive for
* forward transform and negative for inverse transform.</p>
* @param n number of roots of unity to compute,
* positive for forward transform, negative for inverse transform
* @throws IllegalArgumentException if n = 0
*/
public synchronized void computeOmega(int n) throws IllegalArgumentException {
if (n == 0) {
throw MathRuntimeException.createIllegalArgumentException(
LocalizedFormats.CANNOT_COMPUTE_0TH_ROOT_OF_UNITY);
}
isForward = n > 0;
// avoid repetitive calculations
final int absN = FastMath.abs(n);
if (absN == omegaCount) {
return;
}
// calculate everything from scratch, for both forward and inverse versions
final double t = 2.0 * FastMath.PI / absN;
final double cosT = FastMath.cos(t);
final double sinT = FastMath.sin(t);
omegaReal = new double[absN];
omegaImaginaryForward = new double[absN];
omegaImaginaryInverse = new double[absN];
omegaReal[0] = 1.0;
omegaImaginaryForward[0] = 0.0;
omegaImaginaryInverse[0] = 0.0;
for (int i = 1; i < absN; i++) {
omegaReal[i] =
omegaReal[i-1] * cosT + omegaImaginaryForward[i-1] * sinT;
omegaImaginaryForward[i] =
omegaImaginaryForward[i-1] * cosT - omegaReal[i-1] * sinT;
omegaImaginaryInverse[i] = -omegaImaginaryForward[i];
}
omegaCount = absN;
}
示例3: integrateWithSpecifiedStep
import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
private double integrateWithSpecifiedStep(double omega,
double t0, double t,
double step)
throws MathUserException, IntegratorException {
double[] y0 = new double[2];
y0[0] = FastMath.sin(omega * t0);
y0[1] = omega * FastMath.cos(omega * t0);
ClassicalRungeKuttaIntegrator i = new ClassicalRungeKuttaIntegrator(step);
double[] y = new double[2];
i.integrate(new FirstOrderConverter(new Equations(1, omega)), t0, y0, t, y);
return y[0];
}
示例4: TestProblem4
import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/** Simple constructor. */
public TestProblem4() {
super();
a = 1.2;
double[] y0 = { FastMath.sin(a), FastMath.cos(a) };
setInitialConditions(0.0, y0);
setFinalConditions(15);
double[] errorScale = { 1.0, 0.0 };
setErrorScale(errorScale);
y = new double[y0.length];
}
示例5: call
import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
public static TypeFloat call(TypeInt x) {
BigInteger val = x.getValue();
// Check for overflow
if (DOUBLE_MAX.compareTo(val) < 0 || DOUBLE_MIN.compareTo(val) > 0)
throw new ExpressionFault.ValueError("overflow");
Double ret = FastMath.cos(val.doubleValue());
return new TypeFloat(ret);
}
示例6: value
import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
@Override
public double[] value(double[] variables) {
double x1 = variables[0];
double x2 = variables[1];
double x3 = variables[2];
double x4 = variables[3];
double[] f = new double[m];
for (int i = 0; i < m; ++i) {
double temp = (i + 1) / 5.0;
double tmp1 = x1 + temp * x2 - FastMath.exp(temp);
double tmp2 = x3 + FastMath.sin(temp) * x4 - FastMath.cos(temp);
f[i] = tmp1 * tmp1 + tmp2 * tmp2;
}
return f;
}
示例7: derivative
import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
public UnivariateRealFunction derivative() {
return new UnivariateRealFunction() {
public double value(double x) {
return FastMath.cos(x);
}
};
}
示例8: fct
import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/**
* Perform the FCT algorithm (including inverse).
*
* @param f the real data array to be transformed
* @return the real transformed array
* @throws IllegalArgumentException if any parameters are invalid
*/
protected double[] fct(double f[])
throws IllegalArgumentException {
final double transformed[] = new double[f.length];
final int n = f.length - 1;
if (!FastFourierTransformer.isPowerOf2(n)) {
throw MathRuntimeException.createIllegalArgumentException(
LocalizedFormats.NOT_POWER_OF_TWO_PLUS_ONE,
f.length);
}
if (n == 1) { // trivial case
transformed[0] = 0.5 * (f[0] + f[1]);
transformed[1] = 0.5 * (f[0] - f[1]);
return transformed;
}
// construct a new array and perform FFT on it
final double[] x = new double[n];
x[0] = 0.5 * (f[0] + f[n]);
x[n >> 1] = f[n >> 1];
double t1 = 0.5 * (f[0] - f[n]); // temporary variable for transformed[1]
for (int i = 1; i < (n >> 1); i++) {
final double a = 0.5 * (f[i] + f[n-i]);
final double b = FastMath.sin(i * FastMath.PI / n) * (f[i] - f[n-i]);
final double c = FastMath.cos(i * FastMath.PI / n) * (f[i] - f[n-i]);
x[i] = a - b;
x[n-i] = a + b;
t1 += c;
}
FastFourierTransformer transformer = new FastFourierTransformer();
Complex y[] = transformer.transform(x);
// reconstruct the FCT result for the original array
transformed[0] = y[0].getReal();
transformed[1] = t1;
for (int i = 1; i < (n >> 1); i++) {
transformed[2 * i] = y[i].getReal();
transformed[2 * i + 1] = transformed[2 * i - 1] - y[i].getImaginary();
}
transformed[n] = y[n >> 1].getReal();
return transformed;
}
示例9: Rotation
import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/** Build a rotation from an axis and an angle.
* <p>We use the convention that angles are oriented according to
* the effect of the rotation on vectors around the axis. That means
* that if (i, j, k) is a direct frame and if we first provide +k as
* the axis and π/2 as the angle to this constructor, and then
* {@link #applyTo(Vector3D) apply} the instance to +i, we will get
* +j.</p>
* <p>Another way to represent our convention is to say that a rotation
* of angle θ about the unit vector (x, y, z) is the same as the
* rotation build from quaternion components { cos(-θ/2),
* x * sin(-θ/2), y * sin(-θ/2), z * sin(-θ/2) }.
* Note the minus sign on the angle!</p>
* <p>On the one hand this convention is consistent with a vectorial
* perspective (moving vectors in fixed frames), on the other hand it
* is different from conventions with a frame perspective (fixed vectors
* viewed from different frames) like the ones used for example in spacecraft
* attitude community or in the graphics community.</p>
* @param axis axis around which to rotate
* @param angle rotation angle.
* @exception ArithmeticException if the axis norm is zero
*/
public Rotation(Vector3D axis, double angle) {
double norm = axis.getNorm();
if (norm == 0) {
throw MathRuntimeException.createArithmeticException(LocalizedFormats.ZERO_NORM_FOR_ROTATION_AXIS);
}
double halfAngle = -0.5 * angle;
double coeff = FastMath.sin(halfAngle) / norm;
q0 = FastMath.cos (halfAngle);
q1 = coeff * axis.getX();
q2 = coeff * axis.getY();
q3 = coeff * axis.getZ();
}
示例10: value
import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/** {@inheritDoc} */
public double value(double x) {
return FastMath.cos(x);
}
示例11: calculatePower
import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/**
* Use the (hitx,hity) point and given angle to calculate the power needed.
*
* @param angle
* @param hitx
* @param hity
* @return
*/
public static final int calculatePower(int angle, int hitx, int hity, int wind) {
//Caculate the running time
//0.055
//double K = GameDataManager.getInstance().getGameDataAsDouble(GameDataKey.BATTLE_ATTACK_K, 0.059081);
//double F = GameDataManager.getInstance().getGameDataAsDouble(GameDataKey.BATTLE_ATTACK_F, 0.075);
//int g = GameDataManager.getInstance().getGameDataAsInt(GameDataKey.BATTLE_ATTACK_G, 760);
double rad = angle/180.0*Math.PI;
double sin = FastMath.sin(rad);
double cos = FastMath.cos(rad);
double tx = hitx/3;
int ty = 0;
double a = sin;
double b = -ty;
double c = 0;
double d = Math.abs(tx*tx / (2*cos));
int power = (int)MathUtil.solveCubicEquation(a, b, c, d);
logger.debug("a:{},b:{},c:{},d:{},wind:{},power:{}", new Object[]{a, b, c, d,wind, power});
if ( power < 0 ) {
power = -power;
}
if ( power > 100 ) {
power = 100;
}
/**
* wind < 0 风向向右侧
* wind > 0 风向向左侧
*/
if ( wind < 0 && angle > 90 ) {
power += -wind * 2 + 5;
} else if ( wind < 0 && angle < 90 ) {
/**
* 村口小桥顺风情况下计算的力度偏小,所以
* 这里去掉了风力的数值
* 2013-01-14
*/
//power -= -wind * 2 - 5;
} else if ( wind > 0 && angle < 90 ) {
power += wind * 2 + 5;
} else if ( wind > 0 && angle > 90 ) {
power -= wind * 2 - 5;
}
return (int)power;
}
示例12: Vector3D
import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/** Simple constructor.
* Build a vector from its azimuthal coordinates
* @param alpha azimuth (α) around Z
* (0 is +X, π/2 is +Y, π is -X and 3π/2 is -Y)
* @param delta elevation (δ) above (XY) plane, from -π/2 to +π/2
* @see #getAlpha()
* @see #getDelta()
*/
public Vector3D(double alpha, double delta) {
double cosDelta = FastMath.cos(delta);
this.x = FastMath.cos(alpha) * cosDelta;
this.y = FastMath.sin(alpha) * cosDelta;
this.z = FastMath.sin(delta);
}
示例13: tan
import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/**
* Compute the
* <a href="http://mathworld.wolfram.com/Tangent.html" TARGET="_top">
* tangent</a> of this complex number.
* Implements the formula:
* <pre>
* <code>
* tan(a + bi) = sin(2a)/(cos(2a)+cosh(2b)) + [sinh(2b)/(cos(2a)+cosh(2b))]i
* </code>
* </pre>
* where the (real) functions on the right-hand side are
* {@link java.lang.Math#sin}, {@link java.lang.Math#cos},
* {@link MathUtils#cosh} and {@link MathUtils#sinh}.
* <br/>
* Returns {@link Complex#NaN} if either real or imaginary part of the
* input argument is {@code NaN}.
* <br/>
* Infinite (or critical) values in real or imaginary parts of the input may
* result in infinite or NaN values returned in parts of the result.
* <pre>
* Examples:
* <code>
* tan(1 ± INFINITY i) = 0 + NaN i
* tan(±INFINITY + i) = NaN + NaN i
* tan(±INFINITY ± INFINITY i) = NaN + NaN i
* tan(±π/2 + 0 i) = ±INFINITY + NaN i
* </code>
* </pre>
*
* @return the tangent of {@code this}.
* @since 1.2
*/
public Complex tan() {
if (isNaN) {
return NaN;
}
double real2 = 2.0 * real;
double imaginary2 = 2.0 * imaginary;
double d = FastMath.cos(real2) + MathUtils.cosh(imaginary2);
return createComplex(FastMath.sin(real2) / d,
MathUtils.sinh(imaginary2) / d);
}
示例14: tan
import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/**
* Compute the
* <a href="http://mathworld.wolfram.com/Tangent.html" TARGET="_top">
* tangent</a> of this complex number.
* <p>
* Implements the formula: <pre>
* <code>tan(a + bi) = sin(2a)/(cos(2a)+cosh(2b)) + [sinh(2b)/(cos(2a)+cosh(2b))]i</code></pre>
* where the (real) functions on the right-hand side are
* {@link java.lang.Math#sin}, {@link java.lang.Math#cos},
* {@link MathUtils#cosh} and {@link MathUtils#sinh}.</p>
* <p>
* Returns {@link Complex#NaN} if either real or imaginary part of the
* input argument is <code>NaN</code>.</p>
* <p>
* Infinite (or critical) values in real or imaginary parts of the input may
* result in infinite or NaN values returned in parts of the result.<pre>
* Examples:
* <code>
* tan(1 ± INFINITY i) = 0 + NaN i
* tan(±INFINITY + i) = NaN + NaN i
* tan(±INFINITY ± INFINITY i) = NaN + NaN i
* tan(±π/2 + 0 i) = ±INFINITY + NaN i</code></pre></p>
*
* @return the tangent of this complex number
* @since 1.2
*/
public Complex tan() {
if (isNaN()) {
return Complex.NaN;
}
double real2 = 2.0 * real;
double imaginary2 = 2.0 * imaginary;
double d = FastMath.cos(real2) + MathUtils.cosh(imaginary2);
return createComplex(FastMath.sin(real2) / d, MathUtils.sinh(imaginary2) / d);
}
示例15: tanh
import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/**
* Compute the
* <a href="http://mathworld.wolfram.com/HyperbolicTangent.html" TARGET="_top">
* hyperbolic tangent</a> of this complex number.
* <p>
* Implements the formula: <pre>
* <code>tan(a + bi) = sinh(2a)/(cosh(2a)+cos(2b)) + [sin(2b)/(cosh(2a)+cos(2b))]i</code></pre>
* where the (real) functions on the right-hand side are
* {@link java.lang.Math#sin}, {@link java.lang.Math#cos},
* {@link MathUtils#cosh} and {@link MathUtils#sinh}.</p>
* <p>
* Returns {@link Complex#NaN} if either real or imaginary part of the
* input argument is <code>NaN</code>.</p>
* <p>
* Infinite values in real or imaginary parts of the input may result in
* infinite or NaN values returned in parts of the result.<pre>
* Examples:
* <code>
* tanh(1 ± INFINITY i) = NaN + NaN i
* tanh(±INFINITY + i) = NaN + 0 i
* tanh(±INFINITY ± INFINITY i) = NaN + NaN i
* tanh(0 + (π/2)i) = NaN + INFINITY i</code></pre></p>
*
* @return the hyperbolic tangent of this complex number
* @since 1.2
*/
public Complex tanh() {
if (isNaN()) {
return Complex.NaN;
}
double real2 = 2.0 * real;
double imaginary2 = 2.0 * imaginary;
double d = MathUtils.cosh(real2) + FastMath.cos(imaginary2);
return createComplex(MathUtils.sinh(real2) / d, FastMath.sin(imaginary2) / d);
}