Exemplo n.º 1
0
 /**
  * Get a hashCode for the complex number. Any {@code Double.NaN} value in real or imaginary part
  * produces the same hash code {@code 7}.
  *
  * @return a hash code value for this object.
  */
 @Override
 public int hashCode() {
   if (isNaN) {
     return 7;
   }
   return 37 * (17 * MathUtils.hash(imaginary) + MathUtils.hash(real));
 }
Exemplo n.º 2
0
 /**
  * Copies source to dest.
  *
  * <p>Neither source nor dest can be null.
  *
  * @param source Product to copy
  * @param dest Product to copy to
  * @throws NullArgumentException if either source or dest is null
  */
 public static void copy(Product source, Product dest) throws NullArgumentException {
   MathUtils.checkNotNull(source);
   MathUtils.checkNotNull(dest);
   dest.setData(source.getDataRef());
   dest.n = source.n;
   dest.value = source.value;
 }
Exemplo n.º 3
0
 /**
  * Copies source to dest.
  *
  * <p>Neither source nor dest can be null.
  *
  * @param source Mean to copy
  * @param dest Mean to copy to
  * @throws NullArgumentException if either source or dest is null
  */
 public static void copy(Mean source, Mean dest) throws NullArgumentException {
   MathUtils.checkNotNull(source);
   MathUtils.checkNotNull(dest);
   dest.setData(source.getDataRef());
   dest.incMoment = source.incMoment;
   dest.moment = source.moment.copy();
 }
Exemplo n.º 4
0
 /**
  * Copies source to dest.
  *
  * <p>Neither source nor dest can be null.
  *
  * @param source Percentile to copy
  * @param dest Percentile to copy to
  * @throws NullArgumentException if either source or dest is null
  */
 public static void copy(Percentile source, Percentile dest) throws NullArgumentException {
   MathUtils.checkNotNull(source);
   MathUtils.checkNotNull(dest);
   dest.setData(source.getDataRef());
   if (source.cachedPivots != null) {
     System.arraycopy(source.cachedPivots, 0, dest.cachedPivots, 0, source.cachedPivots.length);
   }
   dest.quantile = source.quantile;
 }
Exemplo n.º 5
0
 /* 116:    */
 /* 117:    */ public static void copy(Kurtosis source, Kurtosis dest)
     /* 118:    */ throws NullArgumentException
       /* 119:    */ {
   /* 120:218 */ MathUtils.checkNotNull(source);
   /* 121:219 */ MathUtils.checkNotNull(dest);
   /* 122:220 */ dest.setData(source.getDataRef());
   /* 123:221 */ dest.moment = source.moment.copy();
   /* 124:222 */ dest.incMoment = source.incMoment;
   /* 125:    */ }
 /**
  * Performs all dimension checks on the parameters of {@link #solve(RealLinearOperator,
  * RealVector, RealVector) solve} and {@link #solveInPlace(RealLinearOperator, RealVector,
  * RealVector) solveInPlace}, and throws an exception if one of the checks fails.
  *
  * @param a the linear operator A of the system
  * @param b the right-hand side vector
  * @param x0 the initial guess of the solution
  * @throws NullArgumentException if one of the parameters is {@code null}
  * @throws NonSquareOperatorException if {@code a} is not square
  * @throws DimensionMismatchException if {@code b} or {@code x0} have dimensions inconsistent with
  *     {@code a}
  */
 protected static void checkParameters(
     final RealLinearOperator a, final RealVector b, final RealVector x0)
     throws NullArgumentException, NonSquareOperatorException, DimensionMismatchException {
   MathUtils.checkNotNull(a);
   MathUtils.checkNotNull(b);
   MathUtils.checkNotNull(x0);
   if (a.getRowDimension() != a.getColumnDimension()) {
     throw new NonSquareOperatorException(a.getRowDimension(), a.getColumnDimension());
   }
   if (b.getDimension() != a.getRowDimension()) {
     throw new DimensionMismatchException(b.getDimension(), a.getRowDimension());
   }
   if (x0.getDimension() != a.getColumnDimension()) {
     throw new DimensionMismatchException(x0.getDimension(), a.getColumnDimension());
   }
 }
  /** {@inheritDoc} */
  public void setSubMatrix(final double[][] subMatrix, final int row, final int column)
      throws NoDataException, OutOfRangeException, DimensionMismatchException,
          NullArgumentException {
    MathUtils.checkNotNull(subMatrix);
    final int nRows = subMatrix.length;
    if (nRows == 0) {
      throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_ROW);
    }

    final int nCols = subMatrix[0].length;
    if (nCols == 0) {
      throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_COLUMN);
    }

    for (int r = 1; r < nRows; ++r) {
      if (subMatrix[r].length != nCols) {
        throw new DimensionMismatchException(nCols, subMatrix[r].length);
      }
    }

    MatrixUtils.checkRowIndex(this, row);
    MatrixUtils.checkColumnIndex(this, column);
    MatrixUtils.checkRowIndex(this, nRows + row - 1);
    MatrixUtils.checkColumnIndex(this, nCols + column - 1);

    for (int i = 0; i < nRows; ++i) {
      for (int j = 0; j < nCols; ++j) {
        setEntry(row + i, column + j, subMatrix[i][j]);
      }
    }
  }
Exemplo n.º 8
0
  /**
   * Returns a {@code Complex} whose value is {@code (this / divisor)}. Implements the definitional
   * formula
   *
   * <pre>
   *  <code>
   *    a + bi          ac + bd + (bc - ad)i
   *    ----------- = -------------------------
   *    c + di         c<sup>2</sup> + d<sup>2</sup>
   *  </code>
   * </pre>
   *
   * but uses <a href="http://doi.acm.org/10.1145/1039813.1039814">prescaling of operands</a> to
   * limit the effects of overflows and underflows in the computation. <br>
   * {@code Infinite} and {@code NaN} values are handled according to the following rules, applied
   * in the order presented:
   *
   * <ul>
   *   <li>If either {@code this} or {@code divisor} has a {@code NaN} value in either part, {@link
   *       #NaN} is returned.
   *   <li>If {@code divisor} equals {@link #ZERO}, {@link #NaN} is returned.
   *   <li>If {@code this} and {@code divisor} are both infinite, {@link #NaN} is returned.
   *   <li>If {@code this} is finite (i.e., has no {@code Infinite} or {@code NaN} parts) and {@code
   *       divisor} is infinite (one or both parts infinite), {@link #ZERO} is returned.
   *   <li>If {@code this} is infinite and {@code divisor} is finite, {@code NaN} values are
   *       returned in the parts of the result if the {@link java.lang.Double} rules applied to the
   *       definitional formula force {@code NaN} results.
   * </ul>
   *
   * @param divisor Value by which this {@code Complex} is to be divided.
   * @return {@code this / divisor}.
   * @throws NullArgumentException if {@code divisor} is {@code null}.
   */
  public Complex divide(Complex divisor) throws NullArgumentException {
    MathUtils.checkNotNull(divisor);
    if (isNaN || divisor.isNaN) {
      return NaN;
    }

    final double c = divisor.getReal();
    final double d = divisor.getImaginary();
    if (c == 0.0 && d == 0.0) {
      return NaN;
    }

    if (divisor.isInfinite() && !isInfinite()) {
      return ZERO;
    }

    if (FastMath.abs(c) < FastMath.abs(d)) {
      double q = c / d;
      double denominator = c * q + d;
      return createComplex(
          (real * q + imaginary) / denominator, (imaginary * q - real) / denominator);
    } else {
      double q = d / c;
      double denominator = d * q + c;
      return createComplex(
          (imaginary * q + real) / denominator, (imaginary - real * q) / denominator);
    }
  }
Exemplo n.º 9
0
  /** {@inheritDoc} */
  @Override
  public void setSubMatrix(final double[][] subMatrix, final int row, final int column)
      throws NoDataException, OutOfRangeException, DimensionMismatchException,
          NullArgumentException {
    if (data == null) {
      if (row > 0) {
        throw new MathIllegalStateException(LocalizedFormats.FIRST_ROWS_NOT_INITIALIZED_YET, row);
      }
      if (column > 0) {
        throw new MathIllegalStateException(
            LocalizedFormats.FIRST_COLUMNS_NOT_INITIALIZED_YET, column);
      }
      MathUtils.checkNotNull(subMatrix);
      final int nRows = subMatrix.length;
      if (nRows == 0) {
        throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_ROW);
      }

      final int nCols = subMatrix[0].length;
      if (nCols == 0) {
        throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_COLUMN);
      }
      data = new double[subMatrix.length][nCols];
      for (int i = 0; i < data.length; ++i) {
        if (subMatrix[i].length != nCols) {
          throw new DimensionMismatchException(subMatrix[i].length, nCols);
        }
        System.arraycopy(subMatrix[i], 0, data[i + row], column, nCols);
      }
    } else {
      super.setSubMatrix(subMatrix, row, column);
    }
  }
 /**
  * Returns an estimate of the solution to the linear system A &middot; x = b.
  *
  * @param a the linear operator A of the system
  * @param b the right-hand side vector
  * @return a new vector containing the solution
  * @throws NullArgumentException if one of the parameters is {@code null}
  * @throws NonSquareOperatorException if {@code a} is not square
  * @throws DimensionMismatchException if {@code b} has dimensions inconsistent with {@code a}
  * @throws MaxCountExceededException at exhaustion of the iteration count, unless a custom {@link
  *     org.apache.commons.math3.util.Incrementor.MaxCountExceededCallback callback} has been set
  *     at construction of the {@link IterationManager}
  */
 public RealVector solve(final RealLinearOperator a, final RealVector b)
     throws NullArgumentException, NonSquareOperatorException, DimensionMismatchException,
         MaxCountExceededException {
   MathUtils.checkNotNull(a);
   final RealVector x = new ArrayRealVector(a.getColumnDimension());
   x.set(0.);
   return solveInPlace(a, b, x);
 }
Exemplo n.º 11
0
  /**
   * Returns a {@code Complex} whose value is {@code (this - subtrahend)}. Uses the definitional
   * formula
   *
   * <pre>
   *  <code>
   *   (a + bi) - (c + di) = (a-c) + (b-d)i
   *  </code>
   * </pre>
   *
   * If either {@code this} or {@code subtrahend} has a {@code NaN]} value in either part, {@link
   * #NaN} is returned; otherwise infinite and {@code NaN} values are returned in the parts of the
   * result according to the rules for {@link java.lang.Double} arithmetic.
   *
   * @param subtrahend value to be subtracted from this {@code Complex}.
   * @return {@code this - subtrahend}.
   * @throws NullArgumentException if {@code subtrahend} is {@code null}.
   */
  public Complex subtract(Complex subtrahend) throws NullArgumentException {
    MathUtils.checkNotNull(subtrahend);
    if (isNaN || subtrahend.isNaN) {
      return NaN;
    }

    return createComplex(real - subtrahend.getReal(), imaginary - subtrahend.getImaginary());
  }
Exemplo n.º 12
0
  /**
   * Returns a {@code Complex} whose value is {@code (this + addend)}. Uses the definitional formula
   *
   * <pre>
   *  <code>
   *   (a + bi) + (c + di) = (a+c) + (b+d)i
   *  </code>
   * </pre>
   *
   * <br>
   * If either {@code this} or {@code addend} has a {@code NaN} value in either part, {@link #NaN}
   * is returned; otherwise {@code Infinite} and {@code NaN} values are returned in the parts of the
   * result according to the rules for {@link java.lang.Double} arithmetic.
   *
   * @param addend Value to be added to this {@code Complex}.
   * @return {@code this + addend}.
   * @throws NullArgumentException if {@code addend} is {@code null}.
   */
  public Complex add(Complex addend) throws NullArgumentException {
    MathUtils.checkNotNull(addend);
    if (isNaN || addend.isNaN) {
      return NaN;
    }

    return createComplex(real + addend.getReal(), imaginary + addend.getImaginary());
  }
Exemplo n.º 13
0
    /**
     * Compute mean state from osculating state.
     *
     * <p>Compute in a DSST sense the mean state corresponding to the input osculating state.
     *
     * <p>The computing is done through a fixed-point iteration process.
     *
     * @param osculating initial osculating state
     * @return mean state
     * @throws OrekitException if the underlying computation of short periodic variation fails
     */
    private Orbit computeMeanOrbit(final SpacecraftState osculating) throws OrekitException {

      // rough initialization of the mean parameters
      EquinoctialOrbit meanOrbit = new EquinoctialOrbit(osculating.getOrbit());

      // threshold for each parameter
      final double epsilon = 1.0e-13;
      final double thresholdA = epsilon * (1 + FastMath.abs(meanOrbit.getA()));
      final double thresholdE = epsilon * (1 + meanOrbit.getE());
      final double thresholdAngles = epsilon * FastMath.PI;

      int i = 0;
      while (i++ < 200) {

        final SpacecraftState meanState =
            new SpacecraftState(meanOrbit, osculating.getAttitude(), osculating.getMass());
        // recompute the osculating parameters from the current mean parameters
        final EquinoctialOrbit rebuilt = (EquinoctialOrbit) computeOsculatingOrbit(meanState);

        // adapted parameters residuals
        final double deltaA = osculating.getA() - rebuilt.getA();
        final double deltaEx = osculating.getEquinoctialEx() - rebuilt.getEquinoctialEx();
        final double deltaEy = osculating.getEquinoctialEy() - rebuilt.getEquinoctialEy();
        final double deltaHx = osculating.getHx() - rebuilt.getHx();
        final double deltaHy = osculating.getHy() - rebuilt.getHy();
        final double deltaLm = MathUtils.normalizeAngle(osculating.getLM() - rebuilt.getLM(), 0.0);

        // check convergence
        if ((FastMath.abs(deltaA) < thresholdA)
            && (FastMath.abs(deltaEx) < thresholdE)
            && (FastMath.abs(deltaEy) < thresholdE)
            && (FastMath.abs(deltaLm) < thresholdAngles)) {
          return meanOrbit;
        }

        // update mean parameters
        meanOrbit =
            new EquinoctialOrbit(
                meanOrbit.getA() + deltaA,
                meanOrbit.getEquinoctialEx() + deltaEx,
                meanOrbit.getEquinoctialEy() + deltaEy,
                meanOrbit.getHx() + deltaHx,
                meanOrbit.getHy() + deltaHy,
                meanOrbit.getLM() + deltaLm,
                PositionAngle.MEAN,
                meanOrbit.getFrame(),
                meanOrbit.getDate(),
                meanOrbit.getMu());
      }

      throw new PropagationException(OrekitMessages.UNABLE_TO_COMPUTE_DSST_MEAN_PARAMETERS, i);
    }
 /**
  * Computes a hashcode for the matrix.
  *
  * @return hashcode for matrix
  */
 @Override
 public int hashCode() {
   int ret = 7;
   final int nRows = getRowDimension();
   final int nCols = getColumnDimension();
   ret = ret * 31 + nRows;
   ret = ret * 31 + nCols;
   for (int row = 0; row < nRows; ++row) {
     for (int col = 0; col < nCols; ++col) {
       ret = ret * 31 + (11 * (row + 1) + 17 * (col + 1)) * MathUtils.hash(getEntry(row, col));
     }
   }
   return ret;
 }
Exemplo n.º 15
0
 /**
  * Returns a {@code Complex} whose value is {@code this * factor}. Implements preliminary checks
  * for {@code NaN} and infinity followed by the definitional formula:
  *
  * <pre>
  *  <code>
  *   (a + bi)(c + di) = (ac - bd) + (ad + bc)i
  *  </code>
  * </pre>
  *
  * Returns {@link #NaN} if either {@code this} or {@code factor} has one or more {@code NaN}
  * parts. <br>
  * Returns {@link #INF} if neither {@code this} nor {@code factor} has one or more {@code NaN}
  * parts and if either {@code this} or {@code factor} has one or more infinite parts (same result
  * is returned regardless of the sign of the components). <br>
  * Returns finite values in components of the result per the definitional formula in all remaining
  * cases.
  *
  * @param factor value to be multiplied by this {@code Complex}.
  * @return {@code this * factor}.
  * @throws NullArgumentException if {@code factor} is {@code null}.
  */
 public Complex multiply(Complex factor) throws NullArgumentException {
   MathUtils.checkNotNull(factor);
   if (isNaN || factor.isNaN) {
     return NaN;
   }
   if (Double.isInfinite(real)
       || Double.isInfinite(imaginary)
       || Double.isInfinite(factor.real)
       || Double.isInfinite(factor.imaginary)) {
     // we don't use isInfinite() to avoid testing for NaN again
     return INF;
   }
   return createComplex(
       real * factor.real - imaginary * factor.imaginary,
       real * factor.imaginary + imaginary * factor.real);
 }
Exemplo n.º 16
0
  private void checkCartesianToEllipsoidic(
      double ae,
      double f,
      double x,
      double y,
      double z,
      double longitude,
      double latitude,
      double altitude)
      throws OrekitException {

    AbsoluteDate date = AbsoluteDate.J2000_EPOCH;
    Frame frame = FramesFactory.getITRF(IERSConventions.IERS_2010, true);
    OneAxisEllipsoid model = new OneAxisEllipsoid(ae, f, frame);
    GeodeticPoint gp = model.transform(new Vector3D(x, y, z), frame, date);
    Assert.assertEquals(longitude, MathUtils.normalizeAngle(gp.getLongitude(), longitude), 1.0e-10);
    Assert.assertEquals(latitude, gp.getLatitude(), 1.0e-10);
    Assert.assertEquals(altitude, gp.getAltitude(), 1.0e-10 * FastMath.abs(ae));
    Vector3D rebuiltNadir = Vector3D.crossProduct(gp.getSouth(), gp.getWest());
    Assert.assertEquals(0, rebuiltNadir.subtract(gp.getNadir()).getNorm(), 1.0e-15);
  }
 /**
  * Create a new {@code FieldMatrix<T>} using the input array as the underlying data array.
  *
  * <p>If an array is built specially in order to be embedded in a {@code FieldMatrix<T>} and not
  * used directly, the {@code copyArray} may be set to {@code false}. This will prevent the copying
  * and improve performance as no new array will be built and no data will be copied.
  *
  * @param field Field to which the elements belong.
  * @param d Data for the new matrix.
  * @param copyArray Whether to copy or reference the input array.
  * @throws DimensionMismatchException if {@code d} is not rectangular.
  * @throws NoDataException if there are not at least one row and one column.
  * @throws NullArgumentException if {@code d} is {@code null}.
  * @see #Array2DRowFieldMatrix(FieldElement[][])
  */
 public Array2DRowFieldMatrix(final Field<T> field, final T[][] d, final boolean copyArray)
     throws DimensionMismatchException, NoDataException, NullArgumentException {
   super(field);
   if (copyArray) {
     copyIn(d);
   } else {
     MathUtils.checkNotNull(d);
     final int nRows = d.length;
     if (nRows == 0) {
       throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_ROW);
     }
     final int nCols = d[0].length;
     if (nCols == 0) {
       throw new NoDataException(LocalizedFormats.AT_LEAST_ONE_COLUMN);
     }
     for (int r = 1; r < nRows; r++) {
       if (d[r].length != nCols) {
         throw new DimensionMismatchException(nCols, d[r].length);
       }
     }
     data = d;
   }
 }
Exemplo n.º 18
0
 /**
  * Check that all elements of an array are finite real numbers.
  *
  * @param values Values array.
  * @throws org.apache.commons.math3.exception.NotFiniteNumberException if one of the values is not
  *     a finite real number.
  */
 private static void checkAllFiniteReal(final double[] values) {
   for (int i = 0; i < values.length; i++) {
     MathUtils.checkFinite(values[i]);
   }
 }
 /**
  * Returns an estimate of the solution to the linear system A &middot; x = b.
  *
  * @param a the linear operator A of the system
  * @param b the right-hand side vector
  * @param x0 the initial guess of the solution
  * @return a new vector containing the solution
  * @throws NullArgumentException if one of the parameters is {@code null}
  * @throws NonSquareOperatorException if {@code a} is not square
  * @throws DimensionMismatchException if {@code b} or {@code x0} have dimensions inconsistent with
  *     {@code a}
  * @throws MaxCountExceededException at exhaustion of the iteration count, unless a custom {@link
  *     org.apache.commons.math3.util.Incrementor.MaxCountExceededCallback callback} has been set
  *     at construction of the {@link IterationManager}
  */
 public RealVector solve(RealLinearOperator a, RealVector b, RealVector x0)
     throws NullArgumentException, NonSquareOperatorException, DimensionMismatchException,
         MaxCountExceededException {
   MathUtils.checkNotNull(x0);
   return solveInPlace(a, b, x0.copy());
 }
Exemplo n.º 20
0
 /**
  * Returns of value of this complex number raised to the power of {@code x}. Implements the
  * formula:
  *
  * <pre>
  *  <code>
  *   y<sup>x</sup> = exp(x&middot;log(y))
  *  </code>
  * </pre>
  *
  * where {@code exp} and {@code log} are {@link #exp} and {@link #log}, respectively. <br>
  * Returns {@link Complex#NaN} if either real or imaginary part of the input argument is {@code
  * NaN} or infinite, or if {@code y} equals {@link Complex#ZERO}.
  *
  * @param x exponent to which this {@code Complex} is to be raised.
  * @return <code> this<sup>{@code x}</sup></code>.
  * @throws NullArgumentException if x is {@code null}.
  * @since 1.2
  */
 public Complex pow(Complex x) throws NullArgumentException {
   MathUtils.checkNotNull(x);
   return this.log().multiply(x).exp();
 }
 /**
  * Creates a new instance of this class, with custom iteration manager.
  *
  * @param manager the custom iteration manager
  * @throws NullArgumentException if {@code manager} is {@code null}
  */
 public IterativeLinearSolver(final IterationManager manager) throws NullArgumentException {
   MathUtils.checkNotNull(manager);
   this.manager = manager;
 }