Merged (final) src changes from MATH_1_1 release branch r321516-358399
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/math/trunk@358631 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
87a3ee1f19
commit
c5768f0660
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!--build.xml generated by maven from project.xml version 1.1-RC2
|
||||
on date August 8 2005, time 2359-->
|
||||
<!--build.xml generated by maven from project.xml version 1.2-SNAPSHOT
|
||||
on date December 22 2005, time 1344-->
|
||||
|
||||
<project default="jar" name="commons-math" basedir=".">
|
||||
<!--Load local and user build preferences-->
|
||||
|
@ -26,7 +26,7 @@
|
|||
</property>
|
||||
<property name="javadocdir" value="${basedir}/dist/docs/api">
|
||||
</property>
|
||||
<property name="final.name" value="commons-math-1.1-RC2">
|
||||
<property name="final.name" value="commons-math-1.2-SNAPSHOT">
|
||||
</property>
|
||||
<property name="proxy.host" value="">
|
||||
</property>
|
||||
|
@ -176,7 +176,7 @@
|
|||
</tstamp>
|
||||
<property name="copyright" value="Copyright &copy; The Apache Software Foundation. All Rights Reserved.">
|
||||
</property>
|
||||
<property name="title" value="Math 1.1-RC2 API">
|
||||
<property name="title" value="Math 1.2-SNAPSHOT API">
|
||||
</property>
|
||||
<javadoc use="true" private="true" destdir="${javadocdir}" author="true" version="true" sourcepath="${basedir}/src/java" packagenames="org.apache.commons.math.*">
|
||||
<classpath>
|
||||
|
|
|
@ -105,6 +105,11 @@
|
|||
<name>1.1</name>
|
||||
<tag>MATH_1_1</tag>
|
||||
</version>
|
||||
<version>
|
||||
<id>1.2-SNAPSHOT</id>
|
||||
<name>1.1</name>
|
||||
<tag>trunk</tag>
|
||||
</version>
|
||||
</versions>
|
||||
<developers>
|
||||
<developer>
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
Extension-Name: org.apache.commons.math
|
||||
Specification-Title: Jakarta Commons Math
|
||||
Specification-Vendor: Apache Software Foundation
|
||||
Specification-Version: 0.1
|
||||
Implementation-Title: org.apache.commons.math
|
||||
Implementation-Vendor: Apache Software Foundation
|
||||
Implementation-Version: 0.1
|
|
@ -0,0 +1,3 @@
|
|||
Build-Jdk: 1.3.1_16
|
||||
Specification-Version: 1.1
|
||||
Implementation-Vendor-Id: org.apache
|
|
@ -26,7 +26,7 @@ import java.io.Serializable;
|
|||
public class ConvergenceException extends MathException implements Serializable{
|
||||
|
||||
/** Serializable version identifier */
|
||||
static final long serialVersionUID = -3657394299929217890L;
|
||||
private static final long serialVersionUID = -3657394299929217890L;
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
|
|
|
@ -26,7 +26,7 @@ package org.apache.commons.math;
|
|||
public class FunctionEvaluationException extends MathException {
|
||||
|
||||
/** Serializable version identifier */
|
||||
static final long serialVersionUID = -317289374378977972L;
|
||||
private static final long serialVersionUID = -317289374378977972L;
|
||||
|
||||
/** Argument causing function evaluation failure */
|
||||
private double argument = Double.NaN;
|
||||
|
|
|
@ -24,7 +24,7 @@ import java.io.Serializable;
|
|||
public class MathConfigurationException extends MathException implements Serializable {
|
||||
|
||||
/** Serializable version identifier */
|
||||
static final long serialVersionUID = -7958299004965931723L;
|
||||
private static final long serialVersionUID = -7958299004965931723L;
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
|
|
|
@ -31,7 +31,7 @@ import java.io.PrintWriter;
|
|||
public class MathException extends Exception {
|
||||
|
||||
/** Serializable version identifier */
|
||||
static final long serialVersionUID = -8594613561393443827L;
|
||||
private static final long serialVersionUID = -8594613561393443827L;
|
||||
|
||||
/**
|
||||
* Does JDK support nested exceptions?
|
||||
|
|
|
@ -29,7 +29,7 @@ import org.apache.commons.math.ConvergenceException;
|
|||
public class BisectionSolver extends UnivariateRealSolverImpl {
|
||||
|
||||
/** Serializable version identifier */
|
||||
static final long serialVersionUID = 7137520585963699578L;
|
||||
private static final long serialVersionUID = 7137520585963699578L;
|
||||
|
||||
/**
|
||||
* Construct a solver for the given function.
|
||||
|
|
|
@ -30,7 +30,7 @@ import org.apache.commons.math.FunctionEvaluationException;
|
|||
public class BrentSolver extends UnivariateRealSolverImpl {
|
||||
|
||||
/** Serializable version identifier */
|
||||
static final long serialVersionUID = 3350616277306882875L;
|
||||
private static final long serialVersionUID = 3350616277306882875L;
|
||||
|
||||
/**
|
||||
* Construct a solver for the given function.
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package org.apache.commons.math.analysis;
|
||||
|
||||
import java.io.IOException;
|
||||
import org.apache.commons.math.ConvergenceException;
|
||||
import org.apache.commons.math.FunctionEvaluationException;
|
||||
|
||||
|
@ -30,10 +31,10 @@ import org.apache.commons.math.FunctionEvaluationException;
|
|||
public class NewtonSolver extends UnivariateRealSolverImpl {
|
||||
|
||||
/** Serializable version identifier */
|
||||
static final long serialVersionUID = 2606474895443431607L;
|
||||
private static final long serialVersionUID = 2606474895443431607L;
|
||||
|
||||
/** The first derivative of the target function. */
|
||||
private UnivariateRealFunction derivative;
|
||||
private transient UnivariateRealFunction derivative;
|
||||
|
||||
/**
|
||||
* Construct a solver for the given function.
|
||||
|
@ -98,4 +99,16 @@ public class NewtonSolver extends UnivariateRealSolverImpl {
|
|||
("Maximum number of iterations exceeded " + i);
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom deserialization to initialize transient deriviate field.
|
||||
*
|
||||
* @param in serialized object input stream
|
||||
* @throws IOException if IO error occurs
|
||||
* @throws ClassNotFoundException if instantiation error occurs
|
||||
*/
|
||||
private void readObject(java.io.ObjectInputStream in)
|
||||
throws IOException, ClassNotFoundException {
|
||||
in.defaultReadObject();
|
||||
derivative = ((DifferentiableUnivariateRealFunction) f).derivative();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ import java.io.Serializable;
|
|||
public class PolynomialFunction implements DifferentiableUnivariateRealFunction, Serializable {
|
||||
|
||||
/** Serializable version identifier */
|
||||
static final long serialVersionUID = 3322454535052136809L;
|
||||
private static final long serialVersionUID = 3322454535052136809L;
|
||||
|
||||
/**
|
||||
* The coefficients of the polynomial, ordered by degree -- i.e.,
|
||||
|
|
|
@ -52,10 +52,11 @@ import org.apache.commons.math.FunctionEvaluationException;
|
|||
*
|
||||
* @version $Revision$ $Date$
|
||||
*/
|
||||
public class PolynomialSplineFunction implements UnivariateRealFunction, Serializable {
|
||||
public class PolynomialSplineFunction
|
||||
implements DifferentiableUnivariateRealFunction, Serializable {
|
||||
|
||||
/** Serializable version identifier */
|
||||
static final long serialVersionUID = 7011031166416885789L;
|
||||
private static final long serialVersionUID = 7011031166416885789L;
|
||||
|
||||
/** Spline segment interval delimiters (knots). Size is n+1 for n segments. */
|
||||
private double knots[];
|
||||
|
|
|
@ -40,7 +40,7 @@ import org.apache.commons.math.FunctionEvaluationException;
|
|||
public class SecantSolver extends UnivariateRealSolverImpl implements Serializable {
|
||||
|
||||
/** Serializable version identifier */
|
||||
static final long serialVersionUID = 1984971194738974867L;
|
||||
private static final long serialVersionUID = 1984971194738974867L;
|
||||
|
||||
/**
|
||||
* Construct a solver for the given function.
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
package org.apache.commons.math.analysis;
|
||||
|
||||
/**
|
||||
* Computes a natural (a.k.a. "free", "unclamped") cubic spline interpolation for the data set.
|
||||
* Computes a natural (also known as "free", "unclamped") cubic spline interpolation for the data set.
|
||||
* <p>
|
||||
* The {@link #interpolate(double[], double[])} method returns a {@link PolynomialSplineFunction}
|
||||
* consisting of n cubic polynomials, defined over the subintervals determined by the x values,
|
||||
|
|
|
@ -30,7 +30,7 @@ public abstract class UnivariateRealSolverImpl implements UnivariateRealSolver,
|
|||
Serializable {
|
||||
|
||||
/** Serializable version identifier */
|
||||
static final long serialVersionUID = 1112491292565386596L;
|
||||
private static final long serialVersionUID = 1112491292565386596L;
|
||||
|
||||
/** Maximum absolute error. */
|
||||
protected double absoluteAccuracy;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2003-2004 The Apache Software Foundation.
|
||||
* Copyright 2003-2005 The Apache Software Foundation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -22,6 +22,16 @@ import org.apache.commons.math.util.MathUtils;
|
|||
/**
|
||||
* Representation of a Complex number - a number which has both a
|
||||
* real and imaginary part.
|
||||
* <p>
|
||||
* Implementations of arithmetic operations handle <code>NaN</code> and
|
||||
* infinite values according to the rules for {@link java.lang.Double}
|
||||
* arithmetic, applying definitional formulas and returning <code>NaN</code> or
|
||||
* infinite values in real or imaginary parts as these arise in computation.
|
||||
* See individual method javadocs for details.
|
||||
* <p>
|
||||
* {@link #equals} identifies all values with <code>NaN</code> in either real
|
||||
* or imaginary part - e.g., <pre>
|
||||
* <code>1 + NaNi == NaN + i == NaN + NaNi.</code></pre>
|
||||
*
|
||||
* @author Apache Software Foundation
|
||||
* @version $Revision$ $Date$
|
||||
|
@ -29,28 +39,31 @@ import org.apache.commons.math.util.MathUtils;
|
|||
public class Complex implements Serializable {
|
||||
|
||||
/** Serializable version identifier */
|
||||
static final long serialVersionUID = -6530173849413811929L;
|
||||
private static final long serialVersionUID = -6530173849413811929L;
|
||||
|
||||
/** The square root of -1. A number representing "0.0 + 1.0i".*/
|
||||
/** The square root of -1. A number representing "0.0 + 1.0i" */
|
||||
public static final Complex I = new Complex(0.0, 1.0);
|
||||
|
||||
/** A complex number analogous to {@link java.lang.Double#NaN} */
|
||||
/** A complex number representing "NaN + NaNi" */
|
||||
public static final Complex NaN = new Complex(Double.NaN, Double.NaN);
|
||||
|
||||
/** A complex number representing "1.0 + 0.0i" */
|
||||
public static final Complex ONE = new Complex(1.0, 0.0);
|
||||
|
||||
/** The imaginary part. */
|
||||
/** A complex number representing "0.0 + 0.0i" */
|
||||
public static final Complex ZERO = new Complex(0.0, 0.0);
|
||||
|
||||
/** The imaginary part */
|
||||
protected double imaginary;
|
||||
|
||||
/** The real part. */
|
||||
/** The real part */
|
||||
protected double real;
|
||||
|
||||
/**
|
||||
* Create a complex number given the real and imaginary parts.
|
||||
*
|
||||
* @param real the real part.
|
||||
* @param imaginary the imaginary part.
|
||||
* @param real the real part
|
||||
* @param imaginary the imaginary part
|
||||
*/
|
||||
public Complex(double real, double imaginary) {
|
||||
super();
|
||||
|
@ -60,13 +73,23 @@ public class Complex implements Serializable {
|
|||
|
||||
/**
|
||||
* Return the absolute value of this complex number.
|
||||
* <p>
|
||||
* Returns <code>NaN</code> if either real or imaginary part is
|
||||
* <code>NaN</code> and <code>Double.POSITIVE_INFINITY</code> if
|
||||
* neither part is <code>NaN</code>, but at least one part takes an infinite
|
||||
* value.
|
||||
*
|
||||
* @return the absolute value.
|
||||
* @return the absolute value
|
||||
*/
|
||||
public double abs() {
|
||||
if (isNaN()) {
|
||||
return Double.NaN;
|
||||
}
|
||||
|
||||
if (isInfinite()) {
|
||||
return Double.POSITIVE_INFINITY;
|
||||
}
|
||||
|
||||
if (Math.abs(real) < Math.abs(imaginary)) {
|
||||
if (imaginary == 0.0) {
|
||||
return Math.abs(real);
|
||||
|
@ -84,23 +107,37 @@ public class Complex implements Serializable {
|
|||
|
||||
/**
|
||||
* Return the sum of this complex number and the given complex number.
|
||||
* <p>
|
||||
* Uses the definitional formula
|
||||
* <pre>
|
||||
* (a + bi) + (c + di) = (a+c) + (b+d)i
|
||||
* </pre>
|
||||
* <p>
|
||||
* If either this or <code>rhs</code> has a NaN value in either part,
|
||||
* {@link #NaN} is returned; otherwise Inifinite and NaN values are
|
||||
* returned in the parts of the result according to the rules for
|
||||
* {@link java.lang.Double} arithmetic.
|
||||
*
|
||||
* @param rhs the other complex number.
|
||||
* @return the complex number sum.
|
||||
* @param rhs the other complex number
|
||||
* @return the complex number sum
|
||||
* @throws NullPointerException if <code>rhs</code> is null
|
||||
*/
|
||||
public Complex add(Complex rhs) {
|
||||
if (isNaN() || rhs.isNaN()) {
|
||||
return NaN;
|
||||
}
|
||||
|
||||
return new Complex(real + rhs.getReal(),
|
||||
imaginary + rhs.getImaginary());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the conjugate of this complex number. The conjugate of
|
||||
* "A + Bi" is "A - Bi". Complex.NaN is returned if either the real or imaginary part of
|
||||
* this Complex number equals Double.NaN.
|
||||
* "A + Bi" is "A - Bi".
|
||||
* <p>
|
||||
* {@link #NaN} is returned if either the real or imaginary
|
||||
* part of this Complex number equals <code>Double.NaN</code>.
|
||||
* <p>
|
||||
* If the imaginary part is infinite, and the real part is not NaN,
|
||||
* the returned value has infinite imaginary part of the opposite
|
||||
* sign - e.g. the conjugate of <code>1 + POSITIVE_INFINITY i</code>
|
||||
* is <code>1 - NEGATIVE_INFINITY i</code>
|
||||
*
|
||||
* @return the conjugate of this Complex object
|
||||
*/
|
||||
|
@ -108,14 +145,43 @@ public class Complex implements Serializable {
|
|||
if (isNaN()) {
|
||||
return NaN;
|
||||
}
|
||||
|
||||
return new Complex(real, -imaginary);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the quotient of this complex number and the given complex number.
|
||||
* @param rhs the other complex number.
|
||||
* @return the complex number quotient.
|
||||
* <p>
|
||||
* 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.
|
||||
* <p>
|
||||
* Infinite and NaN values are handled / returned according to the
|
||||
* following rules, applied in the order presented:
|
||||
* <ul>
|
||||
* <li>If either this or <code>rhs</code> has a NaN value in either part,
|
||||
* {@link #NaN} is returned.</li>
|
||||
* <li>If <code>rhs</code> equals {@link #ZERO}, {@link #NaN} is returned.
|
||||
* </li>
|
||||
* <li>If this and <code>rhs</code> are both infinite,
|
||||
* {@link #NaN} is returned.</li>
|
||||
* <li>If this is finite (i.e., has no infinite or NaN parts) and
|
||||
* <code>rhs</code> is infinite (one or both parts infinite),
|
||||
* {@link #ZERO} is returned.</li>
|
||||
* <li>If this is infinite and <code>rhs</code> is finite, NaN values are
|
||||
* returned in the parts of the result if the {@link java.lang.Double}
|
||||
* rules applied to the definitional formula force NaN results.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param rhs the other complex number
|
||||
* @return the complex number quotient
|
||||
* @throws NullPointerException if <code>rhs</code> is null
|
||||
*/
|
||||
public Complex divide(Complex rhs) {
|
||||
if (isNaN() || rhs.isNaN()) {
|
||||
|
@ -125,7 +191,11 @@ public class Complex implements Serializable {
|
|||
double c = rhs.getReal();
|
||||
double d = rhs.getImaginary();
|
||||
if (c == 0.0 && d == 0.0) {
|
||||
throw new ArithmeticException("Error: division by zero.");
|
||||
return NaN;
|
||||
}
|
||||
|
||||
if (rhs.isInfinite() && !isInfinite()) {
|
||||
return ZERO;
|
||||
}
|
||||
|
||||
if (Math.abs(c) < Math.abs(d)) {
|
||||
|
@ -156,13 +226,13 @@ public class Complex implements Serializable {
|
|||
* <p>
|
||||
* All <code>NaN</code> values are considered to be equal - i.e, if either
|
||||
* (or both) real and imaginary parts of the complex number are equal
|
||||
* to Double.NaN, the complex number is equal to
|
||||
* to <code>Double.NaN</code>, the complex number is equal to
|
||||
* <code>Complex.NaN</code>.
|
||||
*
|
||||
* @param other Object to test for equality to this
|
||||
* @return true if two Complex objects are equal, false if
|
||||
* object is null, not an instance of Complex, or
|
||||
* not equal to this Complex instance.
|
||||
* not equal to this Complex instance
|
||||
*
|
||||
*/
|
||||
public boolean equals(Object other) {
|
||||
|
@ -210,7 +280,7 @@ public class Complex implements Serializable {
|
|||
/**
|
||||
* Access the imaginary part.
|
||||
*
|
||||
* @return the imaginary part.
|
||||
* @return the imaginary part
|
||||
*/
|
||||
public double getImaginary() {
|
||||
return imaginary;
|
||||
|
@ -219,44 +289,76 @@ public class Complex implements Serializable {
|
|||
/**
|
||||
* Access the real part.
|
||||
*
|
||||
* @return the real part.
|
||||
* @return the real part
|
||||
*/
|
||||
public double getReal() {
|
||||
return real;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this complex number is the special Not-a-Number (NaN)
|
||||
* value.
|
||||
* Returns true if either or both parts of this complex number is NaN;
|
||||
* false otherwise
|
||||
*
|
||||
* @return true if the value represented by this object is NaN; false
|
||||
* otherwise.
|
||||
* @return true if either or both parts of this complex number is NaN;
|
||||
* false otherwise
|
||||
*/
|
||||
public boolean isNaN() {
|
||||
return Double.isNaN(real) || Double.isNaN(imaginary);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the product of this complex number and the given complex number.
|
||||
* Returns true if either the real or imaginary part of this complex number
|
||||
* takes an infinite value (either <code>Double.POSITIVE_INFINITY</code> or
|
||||
* <code>Double.NEGATIVE_INFINITY</code>) and neither part
|
||||
* is <code>NaN</code>.
|
||||
*
|
||||
* @param rhs the other complex number.
|
||||
* @return the complex number product.
|
||||
* @return true if one or both parts of this complex number are infinite
|
||||
* and neither part is <code>NaN</code>
|
||||
*/
|
||||
public boolean isInfinite() {
|
||||
return !isNaN() &&
|
||||
(Double.isInfinite(real) || Double.isInfinite(imaginary));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the product of this complex number and the given complex number.
|
||||
* <p>
|
||||
* Implements the definitional formula:
|
||||
* <pre><code>
|
||||
* (a + bi)(c + di) = (ac - bd) + (ad + bc)i
|
||||
* </code></pre>
|
||||
* <p>
|
||||
* Returns {@link #NaN} if either this or <code>rhs</code> has one or more
|
||||
* NaN parts.
|
||||
* <p>
|
||||
* Returns NaN or infinite values in components of the result per the
|
||||
* definitional formula and and the rules for {@link java.lang.Double}
|
||||
* arithmetic. Examples:
|
||||
* <pre><code>
|
||||
* (1 + i) (INF + i) = INF + INFi
|
||||
* (1 + INFi) (1 - INFi) = INF + NaNi
|
||||
* (-INF + -INFi)(1 + NaNi) = NaN + NaNi
|
||||
* </code></pre>
|
||||
*
|
||||
* @param rhs the other complex number
|
||||
* @return the complex number product
|
||||
* @throws NullPointerException if <code>rhs</code> is null
|
||||
*/
|
||||
public Complex multiply(Complex rhs) {
|
||||
if (isNaN() || rhs.isNaN()) {
|
||||
return NaN;
|
||||
}
|
||||
|
||||
double p = (real + imaginary) * (rhs.getReal() + rhs.getImaginary());
|
||||
double ac = real * rhs.getReal();
|
||||
double bd = imaginary * rhs.getImaginary();
|
||||
return new Complex(ac - bd, p - ac - bd);
|
||||
return new Complex(real * rhs.real - imaginary * rhs.imaginary,
|
||||
real * rhs.imaginary + imaginary * rhs.real);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the additive inverse of this complex number.
|
||||
* <p>
|
||||
* Returns <code>Complex.NaN</code> if either real or imaginary
|
||||
* part of this Complex number equals <code>Double.NaN</code>.
|
||||
*
|
||||
* @return the negation of this complex number.
|
||||
* @return the negation of this complex number
|
||||
*/
|
||||
public Complex negate() {
|
||||
if (isNaN()) {
|
||||
|
@ -269,9 +371,20 @@ public class Complex implements Serializable {
|
|||
/**
|
||||
* Return the difference between this complex number and the given complex
|
||||
* number.
|
||||
* <p>
|
||||
* Uses the definitional formula
|
||||
* <pre>
|
||||
* (a + bi) - (c + di) = (a-c) + (b-d)i
|
||||
* </pre>
|
||||
* <p>
|
||||
* If either this or <code>rhs</code> has a NaN value in either part,
|
||||
* {@link #NaN} is returned; otherwise inifinite and NaN values are
|
||||
* returned in the parts of the result according to the rules for
|
||||
* {@link java.lang.Double} arithmetic.
|
||||
*
|
||||
* @param rhs the other complex number.
|
||||
* @return the complex number difference.
|
||||
* @param rhs the other complex number
|
||||
* @return the complex number difference
|
||||
* @throws NullPointerException if <code>rhs</code> is null
|
||||
*/
|
||||
public Complex subtract(Complex rhs) {
|
||||
if (isNaN() || rhs.isNaN()) {
|
||||
|
|
|
@ -35,7 +35,7 @@ import java.util.Locale;
|
|||
public class ComplexFormat extends Format implements Serializable {
|
||||
|
||||
/** Serializable version identifier */
|
||||
static final long serialVersionUID = -6337346779577272306L;
|
||||
private static final long serialVersionUID = -6337346779577272306L;
|
||||
|
||||
/** The default imaginary character. */
|
||||
private static final String DEFAULT_IMAGINARY_CHARACTER = "i";
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2003-2004 The Apache Software Foundation.
|
||||
* Copyright 2003-2005 The Apache Software Foundation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -19,14 +19,20 @@ package org.apache.commons.math.complex;
|
|||
import org.apache.commons.math.util.MathUtils;
|
||||
|
||||
/**
|
||||
* Implementations of various transcendental functions for
|
||||
* {@link org.apache.commons.math.complex.Complex} arguments.
|
||||
*
|
||||
* Static implementations of common
|
||||
* {@link org.apache.commons.math.complex.Complex}-valued functions. Included
|
||||
* are trigonometric, exponential, log, power and square root functions.
|
||||
*<p>
|
||||
* Reference:
|
||||
* <ul>
|
||||
* <li><a href="http://myweb.lmu.edu/dmsmith/ZMLIB.pdf">
|
||||
* Multiple Precision Complex Arithmetic and Functions</a></li>
|
||||
* </ul>
|
||||
* See individual method javadocs for the computational formulas used.
|
||||
* In general, NaN values in either real or imaginary parts of input arguments
|
||||
* result in {@link Complex#NaN} returned. Otherwise, infinite or NaN values
|
||||
* are returned as they arise in computing the real functions specified in the
|
||||
* computational formulas. Null arguments result in NullPointerExceptions.
|
||||
*
|
||||
* @version $Revision$ $Date$
|
||||
*/
|
||||
|
@ -40,10 +46,19 @@ public class ComplexUtils {
|
|||
}
|
||||
|
||||
/**
|
||||
* Compute the <a href="http://mathworld.wolfram.com/InverseCosine.html">
|
||||
* Compute the
|
||||
* <a href="http://mathworld.wolfram.com/InverseCosine.html" TARGET="_top">
|
||||
* inverse cosine</a> for the given complex argument.
|
||||
* @param z the value whose inverse cosine is to be returned.
|
||||
* @return the inverse cosine of <code>z</code>.
|
||||
* <p>
|
||||
* Implements the formula: <pre>
|
||||
* <code> acos(z) = -i (log(z + i (sqrt(1 - z<sup>2</sup>))))</code></pre>
|
||||
* <p>
|
||||
* Returns {@link Complex#NaN} if either real or imaginary part of the
|
||||
* input argument is <code>NaN</code> or infinite.
|
||||
*
|
||||
* @param z the value whose inverse cosine is to be returned
|
||||
* @return the inverse cosine of <code>z</code>
|
||||
* @throws NullPointerException if <code>z</code> is null
|
||||
*/
|
||||
public static Complex acos(Complex z) {
|
||||
if (z.isNaN()) {
|
||||
|
@ -55,10 +70,19 @@ public class ComplexUtils {
|
|||
}
|
||||
|
||||
/**
|
||||
* Compute the <a href="http://mathworld.wolfram.com/InverseSine.html">
|
||||
* Compute the
|
||||
* <a href="http://mathworld.wolfram.com/InverseSine.html" TARGET="_top">
|
||||
* inverse sine</a> for the given complex argument.
|
||||
* <p>
|
||||
* Implements the formula: <pre>
|
||||
* <code> asin(z) = -i (log(sqrt(1 - z<sup>2</sup>) + iz)) </code></pre>
|
||||
* <p>
|
||||
* Returns {@link Complex#NaN} if either real or imaginary part of the
|
||||
* input argument is <code>NaN</code> or infinite.
|
||||
*
|
||||
* @param z the value whose inverse sine is to be returned.
|
||||
* @return the inverse sine of <code>z</code>.
|
||||
* @throws NullPointerException if <code>z</code> is null
|
||||
*/
|
||||
public static Complex asin(Complex z) {
|
||||
if (z.isNaN()) {
|
||||
|
@ -70,27 +94,56 @@ public class ComplexUtils {
|
|||
}
|
||||
|
||||
/**
|
||||
* Compute the <a href="http://mathworld.wolfram.com/InverseTangent.html">
|
||||
* Compute the
|
||||
* <a href="http://mathworld.wolfram.com/InverseTangent.html" TARGET="_top">
|
||||
* inverse tangent</a> for the given complex argument.
|
||||
* @param z the value whose inverse tangent is to be returned.
|
||||
* @return the inverse tangent of <code>z</code>.
|
||||
* <p>
|
||||
* Implements the formula: <pre>
|
||||
* <code> atan(z) = (i/2) log((i + z)/(i - z)) </code></pre>
|
||||
* <p>
|
||||
* Returns {@link Complex#NaN} if either real or imaginary part of the
|
||||
* input argument is <code>NaN</code> or infinite.
|
||||
*
|
||||
* @param z the value whose inverse tangent is to be returned
|
||||
* @return the inverse tangent of <code>z</code>
|
||||
* @throws NullPointerException if <code>z</code> is null
|
||||
*/
|
||||
public static Complex atan(Complex z) {
|
||||
if (z.isNaN()) {
|
||||
return Complex.NaN;
|
||||
}
|
||||
|
||||
|
||||
return Complex.I.multiply(
|
||||
log(Complex.I.add(z).divide(Complex.I.subtract(z))))
|
||||
.divide(new Complex(2.0, 0.0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute the <a href="http://mathworld.wolfram.com/Cosine.html">cosine</a>
|
||||
* Compute the
|
||||
* <a href="http://mathworld.wolfram.com/Cosine.html" TARGET="_top">
|
||||
* cosine</a>
|
||||
* for the given complex argument.
|
||||
* @param z the value whose cosine is to be returned.
|
||||
* @return the cosine of <code>z</code>.
|
||||
* <p>
|
||||
* Implements the formula: <pre>
|
||||
* <code> cos(a + bi) = cos(a)cosh(b) - sin(a)sinh(b)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>
|
||||
* Returns {@link Complex#NaN} if either real or imaginary part of the
|
||||
* input argument is <code>NaN</code>.
|
||||
* <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>
|
||||
* cos(1 ± INFINITY i) = 1 ∓ INFINITY i
|
||||
* cos(±INFINITY + i) = NaN + NaN i
|
||||
* cos(±INFINITY ± INFINITY i) = NaN + NaN i</code></pre>
|
||||
*
|
||||
* @param z the value whose cosine is to be returned
|
||||
* @return the cosine of <code>z</code>
|
||||
* @throws NullPointerException if <code>z</code> is null
|
||||
*/
|
||||
public static Complex cos(Complex z) {
|
||||
if (z.isNaN()) {
|
||||
|
@ -105,8 +158,29 @@ public class ComplexUtils {
|
|||
}
|
||||
|
||||
/**
|
||||
* Compute the <a href="http://mathworld.wolfram.com/HyperbolicCosine.html">
|
||||
* Compute the
|
||||
* <a href="http://mathworld.wolfram.com/HyperbolicCosine.html" TARGET="_top">
|
||||
* hyperbolic cosine</a> for the given complex argument.
|
||||
* <p>
|
||||
* Implements the formula: <pre>
|
||||
* <code> cosh(a + bi) = cosh(a)cos(b) + sinh(a)sin(b)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>
|
||||
* Returns {@link Complex#NaN} if either real or imaginary part of the
|
||||
* input argument is <code>NaN</code>.
|
||||
* <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>
|
||||
* cosh(1 ± INFINITY i) = NaN + NaN i
|
||||
* cosh(±INFINITY + i) = INFINITY ± INFINITY i
|
||||
* cosh(±INFINITY ± INFINITY i) = NaN + NaN i</code></pre>
|
||||
* <p>
|
||||
* Throws <code>NullPointerException</code> if z is null.
|
||||
*
|
||||
* @param z the value whose hyperbolic cosine is to be returned.
|
||||
* @return the hyperbolic cosine of <code>z</code>.
|
||||
*/
|
||||
|
@ -124,10 +198,31 @@ public class ComplexUtils {
|
|||
|
||||
/**
|
||||
* Compute the
|
||||
* <a href="http://mathworld.wolfram.com/ExponentialFunction.html">
|
||||
* <a href="http://mathworld.wolfram.com/ExponentialFunction.html" TARGET="_top">
|
||||
* exponential function</a> for the given complex argument.
|
||||
* @param z the value.
|
||||
* @return <i>e</i><sup><code>z</code></sup>.
|
||||
* <p>
|
||||
* Implements the formula: <pre>
|
||||
* <code> exp(a + bi) = exp(a)cos(b) + exp(a)sin(b)i</code></pre>
|
||||
* where the (real) functions on the right-hand side are
|
||||
* {@link java.lang.Math#exp}, {@link java.lang.Math#cos}, and
|
||||
* {@link java.lang.Math#sin}.
|
||||
* <p>
|
||||
* Returns {@link Complex#NaN} if either real or imaginary part of the
|
||||
* input argument is <code>NaN</code>.
|
||||
* <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>
|
||||
* exp(1 ± INFINITY i) = NaN + NaN i
|
||||
* exp(INFINITY + i) = INFINITY + INFINITY i
|
||||
* exp(-INFINITY + i) = 0 + 0i
|
||||
* exp(±INFINITY ± INFINITY i) = NaN + NaN i</code></pre>
|
||||
* <p>
|
||||
* Throws <code>NullPointerException</code> if z is null.
|
||||
*
|
||||
* @param z the value
|
||||
* @return <i>e</i><sup><code>z</code></sup>
|
||||
*/
|
||||
public static Complex exp(Complex z) {
|
||||
if (z.isNaN()) {
|
||||
|
@ -136,14 +231,36 @@ public class ComplexUtils {
|
|||
|
||||
double b = z.getImaginary();
|
||||
double expA = Math.exp(z.getReal());
|
||||
double sinB = Math.sin(b);
|
||||
double cosB = Math.cos(b);
|
||||
return new Complex(expA * cosB, expA * sinB);
|
||||
return new Complex(expA * Math.cos(b), expA * Math.sin(b));
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute the <a href="http://mathworld.wolfram.com/NaturalLogarithm.html">
|
||||
* Compute the
|
||||
* <a href="http://mathworld.wolfram.com/NaturalLogarithm.html" TARGET="_top">
|
||||
* natural logarithm</a> for the given complex argument.
|
||||
* <p>
|
||||
* Implements the formula: <pre>
|
||||
* <code> log(a + bi) = ln(|a + bi|) + arg(a + bi)i</code></pre>
|
||||
* where ln on the right hand side is {@link java.lang.Math#log},
|
||||
* <code>|a + bi|</code> is the modulus, {@link Complex#abs}, and
|
||||
* <code>arg(a + bi) = {@link java.lang.Math#atan2}(b, a)</code>
|
||||
* <p>
|
||||
* Returns {@link Complex#NaN} if either real or imaginary part of the
|
||||
* input argument is <code>NaN</code>.
|
||||
* <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>
|
||||
* log(1 ± INFINITY i) = INFINITY ± (π/2)i
|
||||
* log(INFINITY + i) = INFINITY + 0i
|
||||
* log(-INFINITY + i) = INFINITY + πi
|
||||
* log(INFINITY ± INFINITY i) = INFINITY ± (π/4)i
|
||||
* log(-INFINITY ± INFINITY i) = INFINITY ± (3π/4)i
|
||||
* log(0 + 0i) = -INFINITY + 0i
|
||||
* </code></pre>
|
||||
* Throws <code>NullPointerException</code> if z is null.
|
||||
*
|
||||
* @param z the value.
|
||||
* @return ln <code>z</code>.
|
||||
*/
|
||||
|
@ -156,20 +273,85 @@ public class ComplexUtils {
|
|||
Math.atan2(z.getImaginary(), z.getReal()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a complex number from the given polar representation.
|
||||
* <p>
|
||||
* The value returned is <code>r·e<sup>i·theta</sup></code>,
|
||||
* computed as <code>r·cos(theta) + r·sin(theta)i</code>
|
||||
* <p>
|
||||
* If either <code>r</code> or <code>theta</code> is NaN, or
|
||||
* <code>theta</code> is infinite, {@link Complex#NaN} is returned.
|
||||
* <p>
|
||||
* If <code>r</code> is infinite and <code>theta</code> is finite,
|
||||
* infinite or NaN values may be returned in parts of the result, following
|
||||
* the rules for double arithmetic.<pre>
|
||||
* Examples:
|
||||
* <code>
|
||||
* polar2Complex(INFINITY, π/4) = INFINITY + INFINITY i
|
||||
* polar2Complex(INFINITY, 0) = INFINITY + NaN i
|
||||
* polar2Complex(INFINITY, -π/4) = INFINITY - INFINITY i
|
||||
* polar2Complex(INFINITY, 5π/4) = -INFINITY - INFINITY i </code></pre>
|
||||
*
|
||||
* @param r the modulus of the complex number to create
|
||||
* @param theta the argument of the complex number to create
|
||||
* @return <code>r·e<sup>i·theta</sup></code>
|
||||
* @throws IllegalArgumentException if r is negative
|
||||
* @since 1.1
|
||||
*/
|
||||
public static Complex polar2Complex(double r, double theta) {
|
||||
if (r < 0) {
|
||||
throw new IllegalArgumentException
|
||||
("Complex modulus must not be negative");
|
||||
}
|
||||
return new Complex(r * Math.cos(theta), r * Math.sin(theta));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns of value of <code>y</code> raised to the power of <code>x</code>.
|
||||
* <p>
|
||||
* Implements the formula: <pre>
|
||||
* <code> y<sup>x</sup> = exp(x·log(y))</code></pre>
|
||||
* where <code>exp</code> and <code>log</code> are {@link #exp} and
|
||||
* {@link #log}, respectively.
|
||||
* <p>
|
||||
* Returns {@link Complex#NaN} if either real or imaginary part of the
|
||||
* input argument is <code>NaN</code> or infinite, or if <code>y</code>
|
||||
* equals {@link Complex#ZERO}.
|
||||
*
|
||||
* @param y the base.
|
||||
* @param x the exponent.
|
||||
* @return <code>y</code><sup><code>z</code></sup>.
|
||||
* @return <code>y</code><sup><code>x</code></sup>
|
||||
* @throws NullPointerException if either x or y is null
|
||||
*/
|
||||
public static Complex pow(Complex y, Complex x) {
|
||||
return exp(x.multiply(log(y)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute the <a href="http://mathworld.wolfram.com/Sine.html">sine</a>
|
||||
* Compute the
|
||||
* <a href="http://mathworld.wolfram.com/Sine.html" TARGET="_top">
|
||||
* sine</a>
|
||||
* for the given complex argument.
|
||||
* <p>
|
||||
* Implements the formula: <pre>
|
||||
* <code> sin(a + bi) = sin(a)cosh(b) - cos(a)sinh(b)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>
|
||||
* Returns {@link Complex#NaN} if either real or imaginary part of the
|
||||
* input argument is <code>NaN</code>.
|
||||
* <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>
|
||||
* sin(1 ± INFINITY i) = 1 ± INFINITY i
|
||||
* sin(±INFINITY + i) = NaN + NaN i
|
||||
* sin(±INFINITY ± INFINITY i) = NaN + NaN i</code></pre>
|
||||
*
|
||||
* Throws <code>NullPointerException</code> if z is null.
|
||||
*
|
||||
* @param z the value whose sine is to be returned.
|
||||
* @return the sine of <code>z</code>.
|
||||
*/
|
||||
|
@ -186,10 +368,30 @@ public class ComplexUtils {
|
|||
}
|
||||
|
||||
/**
|
||||
* Compute the <a href="http://mathworld.wolfram.com/HyperbolicSine.html">
|
||||
* Compute the
|
||||
* <a href="http://mathworld.wolfram.com/HyperbolicSine.html" TARGET="_top">
|
||||
* hyperbolic sine</a> for the given complex argument.
|
||||
* @param z the value whose hyperbolic sine is to be returned.
|
||||
* @return the hyperbolic sine of <code>z</code>.
|
||||
* <p>
|
||||
* Implements the formula: <pre>
|
||||
* <code> sinh(a + bi) = sinh(a)cos(b)) + cosh(a)sin(b)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>
|
||||
* Returns {@link Complex#NaN} if either real or imaginary part of the
|
||||
* input argument is <code>NaN</code>.
|
||||
* <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>
|
||||
* sinh(1 ± INFINITY i) = NaN + NaN i
|
||||
* sinh(±INFINITY + i) = ± INFINITY + INFINITY i
|
||||
* sinh(±INFINITY ± INFINITY i) = NaN + NaN i</code></pre
|
||||
*
|
||||
* @param z the value whose hyperbolic sine is to be returned
|
||||
* @return the hyperbolic sine of <code>z</code>
|
||||
* @throws NullPointerException if <code>z</code> is null
|
||||
*/
|
||||
public static Complex sinh(Complex z) {
|
||||
if (z.isNaN()) {
|
||||
|
@ -204,10 +406,38 @@ public class ComplexUtils {
|
|||
}
|
||||
|
||||
/**
|
||||
* Compute the <a href="http://mathworld.wolfram.com/SquareRoot.html">squre
|
||||
* root</a> for the given complex argument.
|
||||
* @param z the value whose square root is to be returned.
|
||||
* @return the square root of <code>z</code>.
|
||||
* Compute the
|
||||
* <a href="http://mathworld.wolfram.com/SquareRoot.html" TARGET="_top">
|
||||
* square root</a> for the given complex argument.
|
||||
* <p>
|
||||
* Implements the following algorithm to compute <code>sqrt(a + bi)</code>:
|
||||
* <ol><li>Let <code>t = sqrt((|a| + |a + bi|) / 2)</code></li>
|
||||
* <li><pre>if <code> a ≥ 0</code> return <code>t + (b/2t)i</code>
|
||||
* else return <code>|b|/2t + sign(b)t i </code></pre></li>
|
||||
* </ol>
|
||||
* where <ul>
|
||||
* <li><code>|a| = {@link Math#abs}(a)</code></li>
|
||||
* <li><code>|a + bi| = {@link Complex#abs}(a + bi) </code></li>
|
||||
* <li><code>sign(b) = {@link MathUtils#indicator}(b) </code>
|
||||
* </ul>
|
||||
* <p>
|
||||
* Returns {@link Complex#NaN} if either real or imaginary part of the
|
||||
* input argument is <code>NaN</code>.
|
||||
* <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>
|
||||
* sqrt(1 ± INFINITY i) = INFINITY + NaN i
|
||||
* sqrt(INFINITY + i) = INFINITY + 0i
|
||||
* sqrt(-INFINITY + i) = 0 + INFINITY i
|
||||
* sqrt(INFINITY ± INFINITY i) = INFINITY + NaN i
|
||||
* sqrt(-INFINITY ± INFINITY i) = NaN ± INFINITY i
|
||||
* </code></pre>
|
||||
*
|
||||
* @param z the value whose square root is to be returned
|
||||
* @return the square root of <code>z</code>
|
||||
* @throws NullPointerException if <code>z</code> is null
|
||||
*/
|
||||
public static Complex sqrt(Complex z) {
|
||||
if (z.isNaN()) {
|
||||
|
@ -230,20 +460,54 @@ public class ComplexUtils {
|
|||
}
|
||||
|
||||
/**
|
||||
* Compute the <a href="http://mathworld.wolfram.com/SquareRoot.html">squre
|
||||
* root of 1 - <code>z</code><sup>2</sup> for the given complex argument.
|
||||
* @param z the value.
|
||||
* @return the square root of 1 - <code>z</code><sup>2</sup>.
|
||||
* Compute the
|
||||
* <a href="http://mathworld.wolfram.com/SquareRoot.html" TARGET="_top">
|
||||
* square root</a> of 1 - <code>z</code><sup>2</sup> for the given complex
|
||||
* argument.
|
||||
* <p>
|
||||
* Computes the result directly as
|
||||
* <code>sqrt(Complex.ONE.subtract(z.multiply(z)))</code>.
|
||||
* <p>
|
||||
* Returns {@link Complex#NaN} if either real or imaginary part of the
|
||||
* input argument is <code>NaN</code>.
|
||||
* <p>
|
||||
* Infinite values in real or imaginary parts of the input may result in
|
||||
* infinite or NaN values returned in parts of the result.
|
||||
*
|
||||
* @param z the value
|
||||
* @return the square root of 1 - <code>z</code><sup>2</sup>
|
||||
* @throws NullPointerException if <code>z</code> is null
|
||||
*/
|
||||
public static Complex sqrt1z(Complex z) {
|
||||
return sqrt(Complex.ONE.subtract(z.multiply(z)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute the <a href="http://mathworld.wolfram.com/Tangent.html">
|
||||
* Compute the
|
||||
* <a href="http://mathworld.wolfram.com/Tangent.html" TARGET="_top">
|
||||
* tangent</a> for the given complex argument.
|
||||
* @param z the value whose tangent is to be returned.
|
||||
* @return the tangent of <code>z</code>.
|
||||
* <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>
|
||||
* Returns {@link Complex#NaN} if either real or imaginary part of the
|
||||
* input argument is <code>NaN</code>.
|
||||
* <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(±&pi/2 + 0 i) = ±INFINITY + NaN i</code></pre>
|
||||
*
|
||||
* @param z the value whose tangent is to be returned
|
||||
* @return the tangent of <code>z</code>
|
||||
* @throws NullPointerException if <code>z</code> is null
|
||||
*/
|
||||
public static Complex tan(Complex z) {
|
||||
if (z.isNaN()) {
|
||||
|
@ -259,10 +523,30 @@ public class ComplexUtils {
|
|||
|
||||
/**
|
||||
* Compute the
|
||||
* <a href="http://mathworld.wolfram.com/HyperbolicTangent.html">
|
||||
* <a href="http://mathworld.wolfram.com/HyperbolicTangent.html" TARGET="_top">
|
||||
* hyperbolic tangent</a> for the given complex argument.
|
||||
* @param z the value whose hyperbolic tangent is to be returned.
|
||||
* @return the hyperbolic tangent of <code>z</code>.
|
||||
* <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>
|
||||
* Returns {@link Complex#NaN} if either real or imaginary part of the
|
||||
* input argument is <code>NaN</code>.
|
||||
* <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 + (&pi/2)i) = NaN + INFINITY i</code></pre>
|
||||
*
|
||||
* @param z the value whose hyperbolic tangent is to be returned
|
||||
* @return the hyperbolic tangent of <code>z</code>
|
||||
* @throws NullPointerException if <code>z</code> is null
|
||||
*/
|
||||
public static Complex tanh(Complex z) {
|
||||
if (z.isNaN()) {
|
||||
|
|
|
@ -35,7 +35,7 @@ public abstract class AbstractContinuousDistribution
|
|||
implements ContinuousDistribution, Serializable {
|
||||
|
||||
/** Serializable version identifier */
|
||||
static final long serialVersionUID = -38038050983108802L;
|
||||
private static final long serialVersionUID = -38038050983108802L;
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
|
|
|
@ -28,7 +28,7 @@ public abstract class AbstractDistribution
|
|||
implements Distribution, Serializable {
|
||||
|
||||
/** Serializable version identifier */
|
||||
static final long serialVersionUID = -38038050983108802L;
|
||||
private static final long serialVersionUID = -38038050983108802L;
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
|
|
|
@ -31,7 +31,7 @@ public abstract class AbstractIntegerDistribution extends AbstractDistribution
|
|||
implements IntegerDistribution, Serializable {
|
||||
|
||||
/** Serializable version identifier */
|
||||
static final long serialVersionUID = -1146319659338487221L;
|
||||
private static final long serialVersionUID = -1146319659338487221L;
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
|
|
|
@ -31,7 +31,7 @@ public class BinomialDistributionImpl
|
|||
implements BinomialDistribution, Serializable {
|
||||
|
||||
/** Serializable version identifier */
|
||||
static final long serialVersionUID = 6751309484392813623L;
|
||||
private static final long serialVersionUID = 6751309484392813623L;
|
||||
|
||||
/** The number of trials. */
|
||||
private int numberOfTrials;
|
||||
|
|
|
@ -29,7 +29,7 @@ public class CauchyDistributionImpl extends AbstractContinuousDistribution
|
|||
implements CauchyDistribution, Serializable {
|
||||
|
||||
/** Serializable version identifier */
|
||||
static final long serialVersionUID = 8589540077390120676L;
|
||||
private static final long serialVersionUID = 8589540077390120676L;
|
||||
|
||||
/** The median of this distribution. */
|
||||
private double median = 0;
|
||||
|
|
|
@ -29,7 +29,7 @@ public class ChiSquaredDistributionImpl
|
|||
implements ChiSquaredDistribution, Serializable {
|
||||
|
||||
/** Serializable version identifier */
|
||||
static final long serialVersionUID = -8352658048349159782L;
|
||||
private static final long serialVersionUID = -8352658048349159782L;
|
||||
|
||||
/** Internal Gamma distribution. */
|
||||
private GammaDistribution gamma;
|
||||
|
|
|
@ -20,7 +20,7 @@ import java.io.Serializable;
|
|||
import org.apache.commons.math.MathException;
|
||||
|
||||
/**
|
||||
* The default implementation of {@link ExponentialDistribution}
|
||||
* The default implementation of {@link ExponentialDistribution}.
|
||||
*
|
||||
* @version $Revision$ $Date$
|
||||
*/
|
||||
|
@ -28,7 +28,7 @@ public class ExponentialDistributionImpl extends AbstractContinuousDistribution
|
|||
implements ExponentialDistribution, Serializable {
|
||||
|
||||
/** Serializable version identifier */
|
||||
static final long serialVersionUID = 2401296428283614780L;
|
||||
private static final long serialVersionUID = 2401296428283614780L;
|
||||
|
||||
/** The mean of this distribution. */
|
||||
private double mean;
|
||||
|
|
|
@ -31,7 +31,7 @@ public class FDistributionImpl
|
|||
implements FDistribution, Serializable {
|
||||
|
||||
/** Serializable version identifier */
|
||||
static final long serialVersionUID = -8516354193418641566L;
|
||||
private static final long serialVersionUID = -8516354193418641566L;
|
||||
|
||||
/** The numerator degrees of freedom*/
|
||||
private double numeratorDegreesOfFreedom;
|
||||
|
|
|
@ -21,7 +21,7 @@ import org.apache.commons.math.MathException;
|
|||
import org.apache.commons.math.special.Gamma;
|
||||
|
||||
/**
|
||||
* The default implementation of {@link GammaDistribution}
|
||||
* The default implementation of {@link GammaDistribution}.
|
||||
*
|
||||
* @version $Revision$ $Date$
|
||||
*/
|
||||
|
@ -29,7 +29,7 @@ public class GammaDistributionImpl extends AbstractContinuousDistribution
|
|||
implements GammaDistribution, Serializable {
|
||||
|
||||
/** Serializable version identifier */
|
||||
static final long serialVersionUID = -3239549463135430361L;
|
||||
private static final long serialVersionUID = -3239549463135430361L;
|
||||
|
||||
/** The shape parameter. */
|
||||
private double alpha;
|
||||
|
|
|
@ -30,7 +30,7 @@ public class HypergeometricDistributionImpl extends AbstractIntegerDistribution
|
|||
{
|
||||
|
||||
/** Serializable version identifier */
|
||||
static final long serialVersionUID = -436928820673516179L;
|
||||
private static final long serialVersionUID = -436928820673516179L;
|
||||
|
||||
/** The number of successes in the population. */
|
||||
private int numberOfSuccesses;
|
||||
|
|
|
@ -31,7 +31,7 @@ public class NormalDistributionImpl extends AbstractContinuousDistribution
|
|||
implements NormalDistribution, Serializable {
|
||||
|
||||
/** Serializable version identifier */
|
||||
static final long serialVersionUID = 8589540077390120676L;
|
||||
private static final long serialVersionUID = 8589540077390120676L;
|
||||
|
||||
/** The mean of this distribution. */
|
||||
private double mean = 0;
|
||||
|
|
|
@ -22,7 +22,7 @@ import org.apache.commons.math.special.Gamma;
|
|||
import org.apache.commons.math.util.MathUtils;
|
||||
|
||||
/**
|
||||
* Implementation for the {@link PoissonDistribution}
|
||||
* Implementation for the {@link PoissonDistribution}.
|
||||
*
|
||||
* @version $Revision$ $Date$
|
||||
*/
|
||||
|
@ -30,7 +30,7 @@ public class PoissonDistributionImpl extends AbstractIntegerDistribution
|
|||
implements PoissonDistribution, Serializable {
|
||||
|
||||
/** Serializable version identifier */
|
||||
static final long serialVersionUID = -3349935121172596109L;
|
||||
private static final long serialVersionUID = -3349935121172596109L;
|
||||
|
||||
/**
|
||||
* Holds the Poisson mean for the distribution.
|
||||
|
|
|
@ -31,7 +31,7 @@ public class TDistributionImpl
|
|||
implements TDistribution, Serializable {
|
||||
|
||||
/** Serializable version identifier */
|
||||
static final long serialVersionUID = -5852615386664158222L;
|
||||
private static final long serialVersionUID = -5852615386664158222L;
|
||||
|
||||
/** The degrees of freedom*/
|
||||
private double degreesOfFreedom;
|
||||
|
|
|
@ -29,7 +29,7 @@ public class WeibullDistributionImpl extends AbstractContinuousDistribution
|
|||
implements WeibullDistribution, Serializable {
|
||||
|
||||
/** Serializable version identifier */
|
||||
static final long serialVersionUID = 8589540077390120676L;
|
||||
private static final long serialVersionUID = 8589540077390120676L;
|
||||
|
||||
/** The shape parameter. */
|
||||
private double alpha;
|
||||
|
|
|
@ -34,7 +34,7 @@ public class Fraction extends Number implements Comparable {
|
|||
public static final Fraction ZERO = new Fraction(0, 1);
|
||||
|
||||
/** Serializable version identifier */
|
||||
static final long serialVersionUID = 65382027393090L;
|
||||
private static final long serialVersionUID = 65382027393090L;
|
||||
|
||||
/** The denominator. */
|
||||
private int denominator;
|
||||
|
|
|
@ -37,7 +37,7 @@ import org.apache.commons.math.ConvergenceException;
|
|||
public class FractionFormat extends Format implements Serializable {
|
||||
|
||||
/** Serializable version identifier */
|
||||
static final long serialVersionUID = -6337346779577272306L;
|
||||
private static final long serialVersionUID = -6337346779577272306L;
|
||||
|
||||
/** The format used for the denominator. */
|
||||
private NumberFormat denominatorFormat;
|
||||
|
|
|
@ -31,7 +31,7 @@ import org.apache.commons.math.util.MathUtils;
|
|||
public class ProperFractionFormat extends FractionFormat {
|
||||
|
||||
/** Serializable version identifier */
|
||||
static final long serialVersionUID = -6337346779577272307L;
|
||||
private static final long serialVersionUID = -6337346779577272307L;
|
||||
|
||||
/** The format used for the whole number. */
|
||||
private NumberFormat wholeFormat;
|
||||
|
|
|
@ -19,7 +19,7 @@ import java.io.Serializable;
|
|||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* Implementation for {@link BigMatrix} using a BigDecimal[][] array to store entries
|
||||
* Implementation of {@link BigMatrix} using a BigDecimal[][] array to store entries
|
||||
* and <a href="http://www.math.gatech.edu/~bourbaki/math2601/Web-notes/2num.pdf">
|
||||
* LU decompostion</a> to support linear system
|
||||
* solution and inverse.
|
||||
|
@ -48,7 +48,7 @@ import java.math.BigDecimal;
|
|||
public class BigMatrixImpl implements BigMatrix, Serializable {
|
||||
|
||||
/** Serialization id */
|
||||
static final long serialVersionUID = -1011428905656140431L;
|
||||
private static final long serialVersionUID = -1011428905656140431L;
|
||||
|
||||
/** Entries of the matrix */
|
||||
private BigDecimal data[][] = null;
|
||||
|
|
|
@ -25,7 +25,7 @@ package org.apache.commons.math.linear;
|
|||
public class InvalidMatrixException extends RuntimeException {
|
||||
|
||||
/** Serializable version identifier */
|
||||
static final long serialVersionUID = 5318837237354354107L;
|
||||
private static final long serialVersionUID = 5318837237354354107L;
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
|
|
|
@ -24,7 +24,7 @@ package org.apache.commons.math.linear;
|
|||
public class MatrixIndexException extends RuntimeException {
|
||||
|
||||
/** Serializable version identifier */
|
||||
static final long serialVersionUID = -1341109412864309526L;
|
||||
private static final long serialVersionUID = -1341109412864309526L;
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
|
|
|
@ -21,7 +21,7 @@ import org.apache.commons.math.util.MathUtils;
|
|||
|
||||
|
||||
/**
|
||||
* Implementation for RealMatrix using a double[][] array to store entries and
|
||||
* Implementation of RealMatrix using a double[][] array to store entries and
|
||||
* <a href="http://www.math.gatech.edu/~bourbaki/math2601/Web-notes/2num.pdf">
|
||||
* LU decompostion</a> to support linear system
|
||||
* solution and inverse.
|
||||
|
@ -50,7 +50,7 @@ import org.apache.commons.math.util.MathUtils;
|
|||
public class RealMatrixImpl implements RealMatrix, Serializable {
|
||||
|
||||
/** Serializable version identifier */
|
||||
static final long serialVersionUID = 4237564493130426188L;
|
||||
private static final long serialVersionUID = 4237564493130426188L;
|
||||
|
||||
/** Entries of the matrix */
|
||||
private double data[][] = null;
|
||||
|
|
|
@ -59,13 +59,13 @@ import org.apache.commons.math.stat.descriptive.StatisticalSummary;
|
|||
public class EmpiricalDistributionImpl implements Serializable, EmpiricalDistribution {
|
||||
|
||||
/** Serializable version identifier */
|
||||
static final long serialVersionUID = -6773236347582113490L;
|
||||
private static final long serialVersionUID = -6773236347582113490L;
|
||||
|
||||
/** List of SummaryStatistics objects characterizing the bins */
|
||||
private ArrayList binStats = null;
|
||||
|
||||
/** Sample statistics */
|
||||
SummaryStatistics sampleStats = null;
|
||||
private SummaryStatistics sampleStats = null;
|
||||
|
||||
/** number of bins */
|
||||
private int binCount = 1000;
|
||||
|
@ -225,7 +225,7 @@ public class EmpiricalDistributionImpl implements Serializable, EmpiricalDistrib
|
|||
private class StreamDataAdapter extends DataAdapter{
|
||||
|
||||
/** Input stream providng access to the data */
|
||||
BufferedReader inputStream;
|
||||
private BufferedReader inputStream;
|
||||
|
||||
/**
|
||||
* Create a StreamDataAdapter from a BufferedReader
|
||||
|
@ -380,7 +380,7 @@ public class EmpiricalDistributionImpl implements Serializable, EmpiricalDistrib
|
|||
* @param min the minimum value
|
||||
* @param value the value whose bin we are trying to find
|
||||
* @param delta the grid size
|
||||
* @return
|
||||
* @return the index of the bin containing the value
|
||||
*/
|
||||
private int findBin(double min, double value, double delta) {
|
||||
return Math.min(
|
||||
|
@ -453,14 +453,18 @@ public class EmpiricalDistributionImpl implements Serializable, EmpiricalDistrib
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the array of upper bounds for the bins. Bins are: <br/>
|
||||
* Returns (a fresh copy of) the array of upper bounds for the bins.
|
||||
Bins are: <br/>
|
||||
* [min,upperBounds[0]],(upperBounds[0],upperBounds[1]],...,
|
||||
* (upperBounds[binCount-1],max]
|
||||
*
|
||||
* @return array of bin upper bounds
|
||||
*/
|
||||
public double[] getUpperBounds() {
|
||||
return upperBounds;
|
||||
int len = upperBounds.length;
|
||||
double[] out = new double[len];
|
||||
System.arraycopy(upperBounds, 0, out, 0, len);
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -18,7 +18,7 @@ package org.apache.commons.math.random;
|
|||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* Random data generation utilities
|
||||
* Random data generation utilities.
|
||||
* @version $Revision$ $Date$
|
||||
*/
|
||||
public interface RandomData {
|
||||
|
|
|
@ -81,7 +81,7 @@ import java.util.Collection;
|
|||
public class RandomDataImpl implements RandomData, Serializable {
|
||||
|
||||
/** Serializable version identifier */
|
||||
static final long serialVersionUID = -626730818244969716L;
|
||||
private static final long serialVersionUID = -626730818244969716L;
|
||||
|
||||
/** underlying random number generator */
|
||||
private RandomGenerator rand = null;
|
||||
|
|
|
@ -40,7 +40,7 @@ import java.util.TreeMap;
|
|||
public class Frequency implements Serializable {
|
||||
|
||||
/** Serializable version identifier */
|
||||
static final long serialVersionUID = -3845586908418844111L;
|
||||
private static final long serialVersionUID = -3845586908418844111L;
|
||||
|
||||
/** underlying collection */
|
||||
private TreeMap freqTable = null;
|
||||
|
|
|
@ -20,7 +20,7 @@ import java.io.Serializable;
|
|||
|
||||
/**
|
||||
*
|
||||
* Abstract Implementation for the {@link StorelessUnivariateStatistic} interface.
|
||||
* Abstract implementation of the {@link StorelessUnivariateStatistic} interface.
|
||||
* <p>
|
||||
* Provides default <code>evaluate()</code> and <code>incrementAll(double[])<code>
|
||||
* implementations.
|
||||
|
@ -34,7 +34,7 @@ public abstract class AbstractStorelessUnivariateStatistic
|
|||
implements StorelessUnivariateStatistic, Serializable {
|
||||
|
||||
/** Serialization UID */
|
||||
static final long serialVersionUID = -44915725420072521L;
|
||||
private static final long serialVersionUID = -44915725420072521L;
|
||||
|
||||
/**
|
||||
* This default implementation calls {@link #clear}, then invokes
|
||||
|
|
|
@ -34,7 +34,7 @@ public abstract class AbstractUnivariateStatistic
|
|||
implements UnivariateStatistic, Serializable {
|
||||
|
||||
/** Serialization UID */
|
||||
static final long serialVersionUID = -8007759382851708045L;
|
||||
private static final long serialVersionUID = -8007759382851708045L;
|
||||
|
||||
/**
|
||||
* @see org.apache.commons.math.stat.descriptive.UnivariateStatistic#evaluate(double[])
|
||||
|
|
|
@ -39,7 +39,7 @@ import org.apache.commons.math.stat.descriptive.summary.SumOfSquares;
|
|||
public abstract class DescriptiveStatistics implements StatisticalSummary, Serializable {
|
||||
|
||||
/** Serialization UID */
|
||||
static final long serialVersionUID = 5188298269533339922L;
|
||||
private static final long serialVersionUID = 5188298269533339922L;
|
||||
|
||||
/**
|
||||
* Create an instance of a <code>DescriptiveStatistics</code>
|
||||
|
|
|
@ -28,7 +28,7 @@ import org.apache.commons.math.util.ResizableDoubleArray;
|
|||
public class DescriptiveStatisticsImpl extends DescriptiveStatistics implements Serializable {
|
||||
|
||||
/** Serializable version identifier */
|
||||
static final long serialVersionUID = -1868088725461221010L;
|
||||
private static final long serialVersionUID = -1868088725461221010L;
|
||||
|
||||
/** hold the window size **/
|
||||
protected int windowSize;
|
||||
|
|
|
@ -27,7 +27,7 @@ public class StatisticalSummaryValues implements Serializable,
|
|||
StatisticalSummary {
|
||||
|
||||
/** Serialization id */
|
||||
static final long serialVersionUID = -5108854841843722536L;
|
||||
private static final long serialVersionUID = -5108854841843722536L;
|
||||
|
||||
/** The sample mean */
|
||||
private final double mean;
|
||||
|
|
|
@ -28,7 +28,7 @@ import org.apache.commons.math.util.MathUtils;
|
|||
public abstract class SummaryStatistics implements StatisticalSummary, Serializable {
|
||||
|
||||
/** Serialization UID */
|
||||
static final long serialVersionUID = -6400596334135654825L;
|
||||
private static final long serialVersionUID = -6400596334135654825L;
|
||||
|
||||
/**
|
||||
* Create an instance of a <code>SummaryStatistics</code>
|
||||
|
|
|
@ -34,7 +34,7 @@ import org.apache.commons.math.stat.descriptive.summary.SumOfSquares;
|
|||
public class SummaryStatisticsImpl extends SummaryStatistics implements Serializable {
|
||||
|
||||
/** Serializable version identifier */
|
||||
static final long serialVersionUID = 8787174276883311692L;
|
||||
private static final long serialVersionUID = 8787174276883311692L;
|
||||
|
||||
/** count of values that have been added */
|
||||
protected long n = 0;
|
||||
|
|
|
@ -48,7 +48,7 @@ public class FirstMoment extends AbstractStorelessUnivariateStatistic
|
|||
implements Serializable {
|
||||
|
||||
/** Serializable version identifier */
|
||||
static final long serialVersionUID = -803343206421984070L;
|
||||
private static final long serialVersionUID = -803343206421984070L;
|
||||
|
||||
/** Count of values that have been added */
|
||||
protected long n;
|
||||
|
|
|
@ -52,7 +52,7 @@ import java.io.Serializable;
|
|||
public class FourthMoment extends ThirdMoment implements Serializable{
|
||||
|
||||
/** Serializable version identifier */
|
||||
static final long serialVersionUID = 4763990447117157611L;
|
||||
private static final long serialVersionUID = 4763990447117157611L;
|
||||
|
||||
/** fourth moment of values that have been added */
|
||||
protected double m4;
|
||||
|
|
|
@ -45,7 +45,7 @@ import org.apache.commons.math.stat.descriptive.summary.SumOfLogs;
|
|||
public class GeometricMean extends AbstractStorelessUnivariateStatistic {
|
||||
|
||||
/** Serializable version identifier */
|
||||
static final long serialVersionUID = -8178734905303459453L;
|
||||
private static final long serialVersionUID = -8178734905303459453L;
|
||||
|
||||
/** Wrapped SumOfLogs instance */
|
||||
private SumOfLogs sumOfLogs;
|
||||
|
|
|
@ -40,7 +40,7 @@ import org.apache.commons.math.stat.descriptive.AbstractStorelessUnivariateStati
|
|||
public class Kurtosis extends AbstractStorelessUnivariateStatistic {
|
||||
|
||||
/** Serializable version identifier */
|
||||
static final long serialVersionUID = 2784465764798260919L;
|
||||
private static final long serialVersionUID = 2784465764798260919L;
|
||||
|
||||
/**Fourth Moment on which this statistic is based */
|
||||
protected FourthMoment moment;
|
||||
|
|
|
@ -50,7 +50,7 @@ public class Mean extends AbstractStorelessUnivariateStatistic
|
|||
implements Serializable {
|
||||
|
||||
/** Serializable version identifier */
|
||||
static final long serialVersionUID = -1296043746617791564L;
|
||||
private static final long serialVersionUID = -1296043746617791564L;
|
||||
|
||||
/** First moment on which this statistic is based. */
|
||||
protected FirstMoment moment;
|
||||
|
|
|
@ -44,7 +44,7 @@ import java.io.Serializable;
|
|||
public class SecondMoment extends FirstMoment implements Serializable {
|
||||
|
||||
/** Serializable version identifier */
|
||||
static final long serialVersionUID = 3942403127395076445L;
|
||||
private static final long serialVersionUID = 3942403127395076445L;
|
||||
|
||||
/** second moment of values that have been added */
|
||||
protected double m2;
|
||||
|
|
|
@ -39,7 +39,7 @@ import org.apache.commons.math.stat.descriptive.AbstractStorelessUnivariateStati
|
|||
public class Skewness extends AbstractStorelessUnivariateStatistic implements Serializable {
|
||||
|
||||
/** Serializable version identifier */
|
||||
static final long serialVersionUID = 7101857578996691352L;
|
||||
private static final long serialVersionUID = 7101857578996691352L;
|
||||
|
||||
/** Third moment on which this statistic is based */
|
||||
protected ThirdMoment moment = null;
|
||||
|
|
|
@ -40,7 +40,7 @@ public class StandardDeviation extends AbstractStorelessUnivariateStatistic
|
|||
implements Serializable {
|
||||
|
||||
/** Serializable version identifier */
|
||||
static final long serialVersionUID = 5728716329662425188L;
|
||||
private static final long serialVersionUID = 5728716329662425188L;
|
||||
|
||||
/** Wrapped Variance instance */
|
||||
private Variance variance = null;
|
||||
|
|
|
@ -45,7 +45,7 @@ import java.io.Serializable;
|
|||
public class ThirdMoment extends SecondMoment implements Serializable {
|
||||
|
||||
/** Serializable version identifier */
|
||||
static final long serialVersionUID = -7818711964045118679L;
|
||||
private static final long serialVersionUID = -7818711964045118679L;
|
||||
|
||||
/** third moment of values that have been added */
|
||||
protected double m3;
|
||||
|
|
|
@ -50,7 +50,7 @@ import org.apache.commons.math.stat.descriptive.AbstractStorelessUnivariateStati
|
|||
public class Variance extends AbstractStorelessUnivariateStatistic implements Serializable {
|
||||
|
||||
/** Serializable version identifier */
|
||||
static final long serialVersionUID = -9111962718267217978L;
|
||||
private static final long serialVersionUID = -9111962718267217978L;
|
||||
|
||||
/** SecondMoment is used in incremental calculation of Variance*/
|
||||
protected SecondMoment moment = null;
|
||||
|
|
|
@ -37,7 +37,7 @@ import org.apache.commons.math.stat.descriptive.AbstractStorelessUnivariateStati
|
|||
public class Max extends AbstractStorelessUnivariateStatistic {
|
||||
|
||||
/** Serializable version identifier */
|
||||
static final long serialVersionUID = -5593383832225844641L;
|
||||
private static final long serialVersionUID = -5593383832225844641L;
|
||||
|
||||
/** Number of values that have been added */
|
||||
private long n;
|
||||
|
|
|
@ -32,7 +32,7 @@ import java.io.Serializable;
|
|||
public class Median extends Percentile implements Serializable {
|
||||
|
||||
/** Serializable version identifier */
|
||||
static final long serialVersionUID = -3961477041290915687L;
|
||||
private static final long serialVersionUID = -3961477041290915687L;
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
|
|
|
@ -39,7 +39,7 @@ import org.apache.commons.math.stat.descriptive.AbstractStorelessUnivariateStati
|
|||
public class Min extends AbstractStorelessUnivariateStatistic implements Serializable {
|
||||
|
||||
/** Serializable version identifier */
|
||||
static final long serialVersionUID = -2941995784909003131L;
|
||||
private static final long serialVersionUID = -2941995784909003131L;
|
||||
|
||||
/**Number of values that have been added */
|
||||
private long n;
|
||||
|
|
|
@ -65,7 +65,7 @@ import org.apache.commons.math.stat.descriptive.AbstractUnivariateStatistic;
|
|||
public class Percentile extends AbstractUnivariateStatistic implements Serializable {
|
||||
|
||||
/** Serializable version identifier */
|
||||
static final long serialVersionUID = -8091216485095130416L;
|
||||
private static final long serialVersionUID = -8091216485095130416L;
|
||||
|
||||
/** Determines what percentile is computed when evaluate() is activated
|
||||
* with no quantile argument */
|
||||
|
|
|
@ -35,7 +35,7 @@ import org.apache.commons.math.stat.descriptive.AbstractStorelessUnivariateStati
|
|||
public class Product extends AbstractStorelessUnivariateStatistic implements Serializable {
|
||||
|
||||
/** Serializable version identifier */
|
||||
static final long serialVersionUID = 2824226005990582538L;
|
||||
private static final long serialVersionUID = 2824226005990582538L;
|
||||
|
||||
/**The number of values that have been added */
|
||||
private long n;
|
||||
|
|
|
@ -35,7 +35,7 @@ import org.apache.commons.math.stat.descriptive.AbstractStorelessUnivariateStati
|
|||
public class Sum extends AbstractStorelessUnivariateStatistic implements Serializable {
|
||||
|
||||
/** Serializable version identifier */
|
||||
static final long serialVersionUID = -8231831954703408316L;
|
||||
private static final long serialVersionUID = -8231831954703408316L;
|
||||
|
||||
/** */
|
||||
private long n;
|
||||
|
|
|
@ -43,7 +43,7 @@ import org.apache.commons.math.stat.descriptive.AbstractStorelessUnivariateStati
|
|||
public class SumOfLogs extends AbstractStorelessUnivariateStatistic implements Serializable {
|
||||
|
||||
/** Serializable version identifier */
|
||||
static final long serialVersionUID = -370076995648386763L;
|
||||
private static final long serialVersionUID = -370076995648386763L;
|
||||
|
||||
/**Number of values that have been added */
|
||||
private int n;
|
||||
|
|
|
@ -35,7 +35,7 @@ import org.apache.commons.math.stat.descriptive.AbstractStorelessUnivariateStati
|
|||
public class SumOfSquares extends AbstractStorelessUnivariateStatistic implements Serializable {
|
||||
|
||||
/** Serializable version identifier */
|
||||
static final long serialVersionUID = 1460986908574398008L;
|
||||
private static final long serialVersionUID = 1460986908574398008L;
|
||||
|
||||
/** */
|
||||
private long n;
|
||||
|
|
|
@ -54,7 +54,7 @@ import org.apache.commons.math.distribution.TDistribution;
|
|||
public class SimpleRegression implements Serializable {
|
||||
|
||||
/** Serializable version identifier */
|
||||
static final long serialVersionUID = -3004689053607543335L;
|
||||
private static final long serialVersionUID = -3004689053607543335L;
|
||||
|
||||
/** sum of x values */
|
||||
private double sumX = 0d;
|
||||
|
|
|
@ -37,7 +37,7 @@ import org.apache.commons.math.MathException;
|
|||
public abstract class ContinuedFraction implements Serializable {
|
||||
|
||||
/** Serialization UID */
|
||||
static final long serialVersionUID = 1768555336266158242L;
|
||||
private static final long serialVersionUID = 1768555336266158242L;
|
||||
|
||||
/** Maximum allowed numerical error. */
|
||||
private static final double DEFAULT_EPSILON = 10e-9;
|
||||
|
|
|
@ -31,7 +31,7 @@ import org.apache.commons.math.MathException;
|
|||
public class DefaultTransformer implements NumberTransformer, Serializable {
|
||||
|
||||
/** Serializable version identifier */
|
||||
static final long serialVersionUID = 4019938025047800455L;
|
||||
private static final long serialVersionUID = 4019938025047800455L;
|
||||
|
||||
/**
|
||||
* @param o the object that gets transformed.
|
||||
|
|
|
@ -71,7 +71,7 @@ import java.io.Serializable;
|
|||
public class ResizableDoubleArray implements DoubleArray, Serializable {
|
||||
|
||||
/** Serializable version identifier */
|
||||
static final long serialVersionUID = -3485529955529426875L;
|
||||
private static final long serialVersionUID = -3485529955529426875L;
|
||||
|
||||
/** additive expansion mode */
|
||||
public static final int ADDITIVE_MODE = 1;
|
||||
|
|
|
@ -33,7 +33,7 @@ import org.apache.commons.math.MathException;
|
|||
public class TransformerMap implements NumberTransformer, Serializable {
|
||||
|
||||
/** Serializable version identifier */
|
||||
static final long serialVersionUID = -942772950698439883L;
|
||||
private static final long serialVersionUID = -942772950698439883L;
|
||||
|
||||
/**
|
||||
* A default Number Transformer for Numbers and numeric Strings.
|
||||
|
|
|
@ -15,5 +15,5 @@
|
|||
limitations under the License.
|
||||
-->
|
||||
<!-- $Revision$ $Date$ -->
|
||||
<body>Convience routines and common data structure used throughout the commons-math library.</body>
|
||||
<body>Convenience routines and common data structures used throughout the commons-math library.</body>
|
||||
</html>
|
||||
|
|
|
@ -42,6 +42,10 @@ public class TestUtils {
|
|||
assertEquals(null, expected, actual, delta);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that expected and actual are within delta, or are both NaN or
|
||||
* infinities of the same sign.
|
||||
*/
|
||||
public static void assertEquals(String msg, double expected, double actual, double delta) {
|
||||
// check for NaN
|
||||
if(Double.isNaN(expected)){
|
||||
|
@ -52,8 +56,26 @@ public class TestUtils {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Verifies that the two arguments are exactly the same, either
|
||||
* both NaN or infinities of same sign, or identical floating point values.
|
||||
*/
|
||||
public static void assertSame(double expected, double actual) {
|
||||
assertEquals(expected, actual, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Verifies that real and imaginary parts of the two complex arguments
|
||||
* are exactly the same. Also ensures that NaN / infinite components match.
|
||||
*/
|
||||
public static void assertSame(Complex expected, Complex actual) {
|
||||
assertSame(expected.getReal(), actual.getReal());
|
||||
assertSame(expected.getImaginary(), actual.getImaginary());
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that real and imaginary parts of the two complex arguments
|
||||
* differ by at most delta. Also ensures that NaN / infinite components match.
|
||||
*/
|
||||
public static void assertEquals(Complex expected, Complex actual, double delta) {
|
||||
assertEquals(expected.getReal(), actual.getReal(), delta);
|
||||
|
|
|
@ -131,17 +131,17 @@ public final class LaguerreSolverTest extends TestCase {
|
|||
expected = new Complex(0.5, 0.5 * Math.sqrt(3.0));
|
||||
tolerance = Math.max(solver.getAbsoluteAccuracy(),
|
||||
Math.abs(expected.abs() * solver.getRelativeAccuracy()));
|
||||
assertEquals(0.0, (expected.subtract(result[2])).abs(), tolerance);
|
||||
assertEquals(0.0, (expected.subtract(result[3])).abs(), tolerance);
|
||||
|
||||
expected = new Complex(-1.0, 0.0);
|
||||
tolerance = Math.max(solver.getAbsoluteAccuracy(),
|
||||
Math.abs(expected.abs() * solver.getRelativeAccuracy()));
|
||||
assertEquals(0.0, (expected.subtract(result[3])).abs(), tolerance);
|
||||
assertEquals(0.0, (expected.subtract(result[4])).abs(), tolerance);
|
||||
|
||||
expected = new Complex(0.5, -0.5 * Math.sqrt(3.0));
|
||||
tolerance = Math.max(solver.getAbsoluteAccuracy(),
|
||||
Math.abs(expected.abs() * solver.getRelativeAccuracy()));
|
||||
assertEquals(0.0, (expected.subtract(result[4])).abs(), tolerance);
|
||||
assertEquals(0.0, (expected.subtract(result[2])).abs(), tolerance);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
package org.apache.commons.math.analysis;
|
||||
|
||||
import org.apache.commons.math.MathException;
|
||||
import org.apache.commons.math.TestUtils;
|
||||
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
|
@ -85,4 +87,79 @@ public final class NewtonSolverTest extends TestCase {
|
|||
result = solver.solve(0.85, 5);
|
||||
assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Serialization and Recovery
|
||||
*/
|
||||
public void testSerialization() throws MathException {
|
||||
DifferentiableUnivariateRealFunction f = new QuinticFunction();
|
||||
double result;
|
||||
|
||||
NewtonSolver solver = new NewtonSolver(f);
|
||||
NewtonSolver solver2 = (NewtonSolver)TestUtils.serializeAndRecover(solver);
|
||||
|
||||
result = solver.solve(-0.2, 0.2);
|
||||
assertEquals(result, 0, solver.getAbsoluteAccuracy());
|
||||
assertEquals(solver2.solve(-0.2, 0.2), result, solver2.getAbsoluteAccuracy());
|
||||
|
||||
result = solver.solve(-0.1, 0.3);
|
||||
assertEquals(result, 0, solver.getAbsoluteAccuracy());
|
||||
assertEquals(solver2.solve(-0.1, 0.3), result, solver2.getAbsoluteAccuracy());
|
||||
|
||||
result = solver.solve(-0.3, 0.45);
|
||||
assertEquals(result, 0, solver.getAbsoluteAccuracy());
|
||||
assertEquals(solver2.solve(-0.3, 0.45), result, solver2.getAbsoluteAccuracy());
|
||||
|
||||
result = solver.solve(0.3, 0.7);
|
||||
assertEquals(result, 0.5, solver.getAbsoluteAccuracy());
|
||||
assertEquals(solver2.solve(0.3, 0.7), result, solver2.getAbsoluteAccuracy());
|
||||
|
||||
result = solver.solve(0.2, 0.6);
|
||||
assertEquals(result, 0.5, solver.getAbsoluteAccuracy());
|
||||
assertEquals(solver2.solve(0.2, 0.6), result, solver2.getAbsoluteAccuracy());
|
||||
|
||||
result = solver.solve(0.05, 0.95);
|
||||
assertEquals(result, 0.5, solver.getAbsoluteAccuracy());
|
||||
assertEquals(solver2.solve(0.05, 0.95), result, solver2.getAbsoluteAccuracy());
|
||||
|
||||
result = solver.solve(0.85, 1.25);
|
||||
assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
|
||||
assertEquals(solver2.solve(0.85, 1.25), result, solver2.getAbsoluteAccuracy());
|
||||
|
||||
result = solver.solve(0.8, 1.2);
|
||||
assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
|
||||
assertEquals(solver2.solve(0.8, 1.2), result, solver2.getAbsoluteAccuracy());
|
||||
|
||||
result = solver.solve(0.85, 1.75);
|
||||
assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
|
||||
assertEquals(solver2.solve(0.85, 1.75), result, solver2.getAbsoluteAccuracy());
|
||||
|
||||
result = solver.solve(0.55, 1.45);
|
||||
assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
|
||||
assertEquals(solver2.solve(0.55, 1.45), result, solver2.getAbsoluteAccuracy());
|
||||
|
||||
result = solver.solve(0.85, 5);
|
||||
assertEquals(result, 1.0, solver.getAbsoluteAccuracy());
|
||||
assertEquals(solver2.solve(0.85, 5), result, solver2.getAbsoluteAccuracy());
|
||||
|
||||
/* Test Reset */
|
||||
double newValue = 1.0e-2;
|
||||
f = new QuinticFunction();
|
||||
solver = new NewtonSolver(f);
|
||||
|
||||
double oldValue = solver.getRelativeAccuracy();
|
||||
solver.setRelativeAccuracy(newValue);
|
||||
solver.resetRelativeAccuracy();
|
||||
assertEquals(oldValue, solver.getRelativeAccuracy(), 1.0e-2);
|
||||
|
||||
solver2 = (NewtonSolver)TestUtils.serializeAndRecover(solver);
|
||||
|
||||
assertEquals(oldValue, solver2.getRelativeAccuracy(), 1.0e-2);
|
||||
|
||||
solver2.setRelativeAccuracy(newValue);
|
||||
solver2.resetRelativeAccuracy();
|
||||
|
||||
assertEquals(oldValue, solver2.getRelativeAccuracy(), 1.0e-2);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ import org.apache.commons.math.FunctionEvaluationException;
|
|||
*/
|
||||
public class QuinticFunction implements DifferentiableUnivariateRealFunction, Serializable {
|
||||
|
||||
static final long serialVersionUID = -8866263034920607152L;
|
||||
private static final long serialVersionUID = -8866263034920607152L;
|
||||
|
||||
/* Evaluate quintic.
|
||||
* @see org.apache.commons.math.UnivariateRealFunction#value(double)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2003-2004 The Apache Software Foundation.
|
||||
* Copyright 2003-2005 The Apache Software Foundation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -23,6 +23,16 @@ import junit.framework.TestCase;
|
|||
*/
|
||||
public class ComplexTest extends TestCase {
|
||||
|
||||
private double inf = Double.POSITIVE_INFINITY;
|
||||
private double neginf = Double.NEGATIVE_INFINITY;
|
||||
private double nan = Double.NaN;
|
||||
private Complex oneInf = new Complex(1, inf);
|
||||
private Complex oneNegInf = new Complex(1, neginf);
|
||||
private Complex infOne = new Complex(inf, 1);
|
||||
private Complex negInfInf = new Complex(neginf, inf);
|
||||
private Complex negInfNegInf = new Complex(neginf, neginf);
|
||||
private Complex oneNaN = new Complex(1, nan);
|
||||
|
||||
public void testConstructor() {
|
||||
Complex z = new Complex(3.0, 4.0);
|
||||
assertEquals(3.0, z.getReal(), 1.0e-5);
|
||||
|
@ -33,7 +43,7 @@ public class ComplexTest extends TestCase {
|
|||
Complex z = new Complex(3.0, Double.NaN);
|
||||
assertTrue(z.isNaN());
|
||||
|
||||
z = new Complex(Double.NaN, 4.0);
|
||||
z = new Complex(nan, 4.0);
|
||||
assertTrue(z.isNaN());
|
||||
|
||||
z = new Complex(3.0, 4.0);
|
||||
|
@ -47,6 +57,17 @@ public class ComplexTest extends TestCase {
|
|||
|
||||
public void testAbsNaN() {
|
||||
assertTrue(Double.isNaN(Complex.NaN.abs()));
|
||||
Complex z = new Complex(inf, nan);
|
||||
assertTrue(Double.isNaN(z.abs()));
|
||||
}
|
||||
|
||||
public void testAbsInfinite() {
|
||||
Complex z = new Complex(inf, 0);
|
||||
assertEquals(inf, z.abs(), 0);
|
||||
z = new Complex(0, neginf);
|
||||
assertEquals(inf, z.abs(), 0);
|
||||
z = new Complex(inf, neginf);
|
||||
assertEquals(inf, z.abs(), 0);
|
||||
}
|
||||
|
||||
public void testAdd() {
|
||||
|
@ -61,6 +82,21 @@ public class ComplexTest extends TestCase {
|
|||
Complex x = new Complex(3.0, 4.0);
|
||||
Complex z = x.add(Complex.NaN);
|
||||
assertTrue(z.isNaN());
|
||||
z = new Complex(1, nan);
|
||||
Complex w = x.add(z);
|
||||
assertEquals(w.real, 4.0, 0);
|
||||
assertTrue(Double.isNaN(w.imaginary));
|
||||
}
|
||||
|
||||
public void testAddInfinite() {
|
||||
Complex x = new Complex(1, 1);
|
||||
Complex z = new Complex(inf, 0);
|
||||
Complex w = x.add(z);
|
||||
assertEquals(w.imaginary, 1, 0);
|
||||
assertEquals(inf, w.real, 0);
|
||||
|
||||
x = new Complex(neginf, 0);
|
||||
assertTrue(Double.isNaN(x.add(z).real));
|
||||
}
|
||||
|
||||
public void testConjugate() {
|
||||
|
@ -75,6 +111,13 @@ public class ComplexTest extends TestCase {
|
|||
assertTrue(z.isNaN());
|
||||
}
|
||||
|
||||
public void testConjugateInfiinite() {
|
||||
Complex z = new Complex(0, inf);
|
||||
assertEquals(neginf, z.conjugate().imaginary, 0);
|
||||
z = new Complex(0, neginf);
|
||||
assertEquals(inf, z.conjugate().imaginary, 0);
|
||||
}
|
||||
|
||||
public void testDivide() {
|
||||
Complex x = new Complex(3.0, 4.0);
|
||||
Complex y = new Complex(5.0, 6.0);
|
||||
|
@ -83,12 +126,46 @@ public class ComplexTest extends TestCase {
|
|||
assertEquals(2.0 / 61.0, z.getImaginary(), 1.0e-5);
|
||||
}
|
||||
|
||||
public void testDivideInfinite() {
|
||||
Complex x = new Complex(3, 4);
|
||||
Complex w = new Complex(neginf, inf);
|
||||
assertTrue(x.divide(w).equals(Complex.ZERO));
|
||||
|
||||
Complex z = w.divide(x);
|
||||
assertTrue(Double.isNaN(z.real));
|
||||
assertEquals(inf, z.imaginary, 0);
|
||||
|
||||
w = new Complex(inf, inf);
|
||||
z = w.divide(x);
|
||||
assertTrue(Double.isNaN(z.imaginary));
|
||||
assertEquals(inf, z.real, 0);
|
||||
|
||||
w = new Complex(1, inf);
|
||||
z = w.divide(w);
|
||||
assertTrue(Double.isNaN(z.real));
|
||||
assertTrue(Double.isNaN(z.imaginary));
|
||||
}
|
||||
|
||||
public void testDivideNaN() {
|
||||
Complex x = new Complex(3.0, 4.0);
|
||||
Complex z = x.divide(Complex.NaN);
|
||||
assertTrue(z.isNaN());
|
||||
}
|
||||
|
||||
public void testDivideNaNInf() {
|
||||
Complex z = oneInf.divide(Complex.ONE);
|
||||
assertTrue(Double.isNaN(z.real));
|
||||
assertEquals(inf, z.imaginary, 0);
|
||||
|
||||
z = negInfNegInf.divide(oneNaN);
|
||||
assertTrue(Double.isNaN(z.real));
|
||||
assertTrue(Double.isNaN(z.imaginary));
|
||||
|
||||
z = negInfInf.divide(Complex.ONE);
|
||||
assertTrue(Double.isNaN(z.real));
|
||||
assertTrue(Double.isNaN(z.imaginary));
|
||||
}
|
||||
|
||||
public void testMultiply() {
|
||||
Complex x = new Complex(3.0, 4.0);
|
||||
Complex y = new Complex(5.0, 6.0);
|
||||
|
@ -103,6 +180,21 @@ public class ComplexTest extends TestCase {
|
|||
assertTrue(z.isNaN());
|
||||
}
|
||||
|
||||
public void testMultiplyNaNInf() {
|
||||
Complex z = new Complex(1,1);
|
||||
Complex w = z.multiply(infOne);
|
||||
assertEquals(w.real, inf, 0);
|
||||
assertEquals(w.imaginary, inf, 0);
|
||||
|
||||
w = oneInf.multiply(oneNegInf);
|
||||
assertEquals(w.real, inf, 0);
|
||||
assertTrue(Double.isNaN(w.imaginary));
|
||||
|
||||
w = negInfNegInf.multiply(oneNaN);
|
||||
assertTrue(Double.isNaN(w.real));
|
||||
assertTrue(Double.isNaN(w.imaginary));
|
||||
}
|
||||
|
||||
public void testNegate() {
|
||||
Complex x = new Complex(3.0, 4.0);
|
||||
Complex z = x.negate();
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2003-2004 The Apache Software Foundation.
|
||||
* Copyright 2003-2005 The Apache Software Foundation.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -25,16 +25,65 @@ import junit.framework.TestCase;
|
|||
*/
|
||||
public class ComplexUtilsTest extends TestCase {
|
||||
|
||||
private double inf = Double.POSITIVE_INFINITY;
|
||||
private double negInf = Double.NEGATIVE_INFINITY;
|
||||
private double nan = Double.NaN;
|
||||
private double pi = Math.PI;
|
||||
|
||||
private Complex oneInf = new Complex(1, inf);
|
||||
private Complex oneNegInf = new Complex(1, negInf);
|
||||
private Complex infOne = new Complex(inf, 1);
|
||||
private Complex negInfOne = new Complex(negInf, 1);
|
||||
private Complex negInfInf = new Complex(negInf, inf);
|
||||
private Complex infNegInf = new Complex(inf, negInf);
|
||||
private Complex infInf = new Complex(inf, inf);
|
||||
private Complex negInfNegInf = new Complex(negInf, negInf);
|
||||
private Complex oneNaN = new Complex(1, nan);
|
||||
private Complex infNaN = new Complex(inf, nan);
|
||||
private Complex negInfNaN = new Complex(negInf, nan);
|
||||
private Complex nanInf = new Complex(nan, inf);
|
||||
private Complex nanNegInf = new Complex(nan, negInf);
|
||||
private Complex zeroNaN = new Complex(0, nan);
|
||||
private Complex nanZero = new Complex(nan, 0);
|
||||
private Complex infZero = new Complex(inf, 0);
|
||||
private Complex zeroInf = new Complex(0, inf);
|
||||
private Complex zeroNegInf = new Complex(0, negInf);
|
||||
private Complex negInfZero = new Complex(negInf, 0);
|
||||
|
||||
private ComplexFormat fmt = new ComplexFormat();
|
||||
|
||||
public void testAcos() {
|
||||
Complex z = new Complex(3, 4);
|
||||
Complex expected = new Complex(0.936812, -2.30551);
|
||||
TestUtils.assertEquals(expected, ComplexUtils.acos(z), 1.0e-5);
|
||||
TestUtils.assertEquals(new Complex(Math.acos(0), 0),
|
||||
ComplexUtils.acos(Complex.ZERO), 1.0e-12);
|
||||
}
|
||||
|
||||
public void testAcosInf() {
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.acos(oneInf));
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.acos(oneNegInf));
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.acos(infOne));
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.acos(negInfOne));
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.acos(infInf));
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.acos(infNegInf));
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.acos(negInfInf));
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.acos(negInfNegInf));
|
||||
}
|
||||
|
||||
public void testAcosNaN() {
|
||||
assertTrue(ComplexUtils.acos(Complex.NaN).isNaN());
|
||||
}
|
||||
|
||||
public void testAcosNull() {
|
||||
try {
|
||||
Complex z = ComplexUtils.acos(null);
|
||||
fail("Expecting NullPointerException");
|
||||
} catch (NullPointerException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testAsin() {
|
||||
Complex z = new Complex(3, 4);
|
||||
Complex expected = new Complex(0.633984, 2.30551);
|
||||
|
@ -45,14 +94,55 @@ public class ComplexUtilsTest extends TestCase {
|
|||
assertTrue(ComplexUtils.asin(Complex.NaN).isNaN());
|
||||
}
|
||||
|
||||
public void testAsinInf() {
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.asin(oneInf));
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.asin(oneNegInf));
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.asin(infOne));
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.asin(negInfOne));
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.asin(infInf));
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.asin(infNegInf));
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.asin(negInfInf));
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.asin(negInfNegInf));
|
||||
}
|
||||
|
||||
public void testAsinNull() {
|
||||
try {
|
||||
Complex z = ComplexUtils.asin(null);
|
||||
fail("Expecting NullPointerException");
|
||||
} catch (NullPointerException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testAtan() {
|
||||
Complex z = new Complex(3, 4);
|
||||
Complex expected = new Complex(1.44831, 0.158997);
|
||||
TestUtils.assertEquals(expected, ComplexUtils.atan(z), 1.0e-5);
|
||||
}
|
||||
|
||||
public void testAtanInf() {
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.atan(oneInf));
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.atan(oneNegInf));
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.atan(infOne));
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.atan(negInfOne));
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.atan(infInf));
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.atan(infNegInf));
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.atan(negInfInf));
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.atan(negInfNegInf));
|
||||
}
|
||||
|
||||
public void testAtanNaN() {
|
||||
assertTrue(ComplexUtils.atan(Complex.NaN).isNaN());
|
||||
assertTrue(ComplexUtils.atan(Complex.I).isNaN());
|
||||
}
|
||||
|
||||
public void testAtanNull() {
|
||||
try {
|
||||
Complex z = ComplexUtils.atan(null);
|
||||
fail("Expecting NullPointerException");
|
||||
} catch (NullPointerException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testCos() {
|
||||
|
@ -61,6 +151,30 @@ public class ComplexUtilsTest extends TestCase {
|
|||
TestUtils.assertEquals(expected, ComplexUtils.cos(z), 1.0e-5);
|
||||
}
|
||||
|
||||
public void testCosNaN() {
|
||||
assertTrue(ComplexUtils.cos(Complex.NaN).isNaN());
|
||||
}
|
||||
|
||||
public void testCosInf() {
|
||||
TestUtils.assertSame(infNegInf, ComplexUtils.cos(oneInf));
|
||||
TestUtils.assertSame(infInf, ComplexUtils.cos(oneNegInf));
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.cos(infOne));
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.cos(negInfOne));
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.cos(infInf));
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.cos(infNegInf));
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.cos(negInfInf));
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.cos(negInfNegInf));
|
||||
}
|
||||
|
||||
public void testCosNull() {
|
||||
try {
|
||||
Complex z = ComplexUtils.cos(null);
|
||||
fail("Expecting NullPointerException");
|
||||
} catch (NullPointerException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testCosh() {
|
||||
Complex z = new Complex(3, 4);
|
||||
Complex expected = new Complex(-6.58066, -7.58155);
|
||||
|
@ -71,20 +185,61 @@ public class ComplexUtilsTest extends TestCase {
|
|||
assertTrue(ComplexUtils.cosh(Complex.NaN).isNaN());
|
||||
}
|
||||
|
||||
public void testCosNaN() {
|
||||
assertTrue(ComplexUtils.cos(Complex.NaN).isNaN());
|
||||
public void testCoshInf() {
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.cosh(oneInf));
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.cosh(oneNegInf));
|
||||
TestUtils.assertSame(infInf, ComplexUtils.cosh(infOne));
|
||||
TestUtils.assertSame(infNegInf, ComplexUtils.cosh(negInfOne));
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.cosh(infInf));
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.cosh(infNegInf));
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.cosh(negInfInf));
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.cosh(negInfNegInf));
|
||||
}
|
||||
|
||||
public void testCoshNull() {
|
||||
try {
|
||||
Complex z = ComplexUtils.cosh(null);
|
||||
fail("Expecting NullPointerException");
|
||||
} catch (NullPointerException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testExp() {
|
||||
Complex z = new Complex(3, 4);
|
||||
Complex expected = new Complex(-13.12878, -15.20078);
|
||||
TestUtils.assertEquals(expected, ComplexUtils.exp(z), 1.0e-5);
|
||||
TestUtils.assertEquals(Complex.ONE,
|
||||
ComplexUtils.exp(Complex.ZERO), 10e-12);
|
||||
Complex iPi = Complex.I.multiply(new Complex(pi,0));
|
||||
TestUtils.assertEquals(Complex.ONE.negate(),
|
||||
ComplexUtils.exp(iPi), 10e-12);
|
||||
}
|
||||
|
||||
public void testExpNaN() {
|
||||
assertTrue(ComplexUtils.exp(Complex.NaN).isNaN());
|
||||
}
|
||||
|
||||
public void testExpInf() {
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.exp(oneInf));
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.exp(oneNegInf));
|
||||
TestUtils.assertSame(infInf, ComplexUtils.exp(infOne));
|
||||
TestUtils.assertSame(Complex.ZERO, ComplexUtils.exp(negInfOne));
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.exp(infInf));
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.exp(infNegInf));
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.exp(negInfInf));
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.exp(negInfNegInf));
|
||||
}
|
||||
|
||||
public void testExpNull() {
|
||||
try {
|
||||
Complex z = ComplexUtils.exp(null);
|
||||
fail("Expecting NullPointerException");
|
||||
} catch (NullPointerException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testLog() {
|
||||
Complex z = new Complex(3, 4);
|
||||
Complex expected = new Complex(1.60944, 0.927295);
|
||||
|
@ -95,6 +250,101 @@ public class ComplexUtilsTest extends TestCase {
|
|||
assertTrue(ComplexUtils.log(Complex.NaN).isNaN());
|
||||
}
|
||||
|
||||
public void testLogInf() {
|
||||
TestUtils.assertEquals(new Complex(inf, pi / 2),
|
||||
ComplexUtils.log(oneInf), 10e-12);
|
||||
TestUtils.assertEquals(new Complex(inf, -pi / 2),
|
||||
ComplexUtils.log(oneNegInf), 10e-12);
|
||||
TestUtils.assertEquals(infZero, ComplexUtils.log(infOne), 10e-12);
|
||||
TestUtils.assertEquals(new Complex(inf, pi),
|
||||
ComplexUtils.log(negInfOne), 10e-12);
|
||||
TestUtils.assertEquals(new Complex(inf, pi / 4),
|
||||
ComplexUtils.log(infInf), 10e-12);
|
||||
TestUtils.assertEquals(new Complex(inf, -pi / 4),
|
||||
ComplexUtils.log(infNegInf), 10e-12);
|
||||
TestUtils.assertEquals(new Complex(inf, 3d * pi / 4),
|
||||
ComplexUtils.log(negInfInf), 10e-12);
|
||||
TestUtils.assertEquals(new Complex(inf, - 3d * pi / 4),
|
||||
ComplexUtils.log(negInfNegInf), 10e-12);
|
||||
}
|
||||
|
||||
public void testLogZero() {
|
||||
TestUtils.assertSame(negInfZero, ComplexUtils.log(Complex.ZERO));
|
||||
}
|
||||
|
||||
public void testlogNull() {
|
||||
try {
|
||||
Complex z = ComplexUtils.log(null);
|
||||
fail("Expecting NullPointerException");
|
||||
} catch (NullPointerException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testPolar2Complex() {
|
||||
TestUtils.assertEquals(Complex.ONE,
|
||||
ComplexUtils.polar2Complex(1, 0), 10e-12);
|
||||
TestUtils.assertEquals(Complex.ZERO,
|
||||
ComplexUtils.polar2Complex(0, 1), 10e-12);
|
||||
TestUtils.assertEquals(Complex.ZERO,
|
||||
ComplexUtils.polar2Complex(0, -1), 10e-12);
|
||||
TestUtils.assertEquals(Complex.I,
|
||||
ComplexUtils.polar2Complex(1, pi/2), 10e-12);
|
||||
TestUtils.assertEquals(Complex.I.negate(),
|
||||
ComplexUtils.polar2Complex(1, -pi/2), 10e-12);
|
||||
double r = 0;
|
||||
for (int i = 0; i < 5; i++) {
|
||||
r += i;
|
||||
double theta = 0;
|
||||
for (int j =0; j < 20; j++) {
|
||||
theta += pi / 6;
|
||||
TestUtils.assertEquals(altPolar(r, theta),
|
||||
ComplexUtils.polar2Complex(r, theta), 10e-12);
|
||||
}
|
||||
theta = -2 * pi;
|
||||
for (int j =0; j < 20; j++) {
|
||||
theta -= pi / 6;
|
||||
TestUtils.assertEquals(altPolar(r, theta),
|
||||
ComplexUtils.polar2Complex(r, theta), 10e-12);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected Complex altPolar(double r, double theta) {
|
||||
return ComplexUtils.exp(Complex.I.multiply
|
||||
(new Complex(theta, 0))).multiply(new Complex(r, 0));
|
||||
}
|
||||
|
||||
public void testPolar2ComplexIllegalModulus() {
|
||||
try {
|
||||
Complex z = ComplexUtils.polar2Complex(-1, 0);
|
||||
fail("Expecting IllegalArgumentException");
|
||||
} catch (IllegalArgumentException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testPolar2ComplexNaN() {
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.polar2Complex(nan, 1));
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.polar2Complex(1, nan));
|
||||
TestUtils.assertSame(Complex.NaN,
|
||||
ComplexUtils.polar2Complex(nan, nan));
|
||||
}
|
||||
|
||||
public void testPolar2ComplexInf() {
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.polar2Complex(1, inf));
|
||||
TestUtils.assertSame(Complex.NaN,
|
||||
ComplexUtils.polar2Complex(1, negInf));
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.polar2Complex(inf, inf));
|
||||
TestUtils.assertSame(Complex.NaN,
|
||||
ComplexUtils.polar2Complex(inf, negInf));
|
||||
TestUtils.assertSame(infInf, ComplexUtils.polar2Complex(inf, pi/4));
|
||||
TestUtils.assertSame(infNaN, ComplexUtils.polar2Complex(inf, 0));
|
||||
TestUtils.assertSame(infNegInf, ComplexUtils.polar2Complex(inf, -pi/4));
|
||||
TestUtils.assertSame(negInfInf, ComplexUtils.polar2Complex(inf, 3*pi/4));
|
||||
TestUtils.assertSame(negInfNegInf, ComplexUtils.polar2Complex(inf, 5*pi/4));
|
||||
}
|
||||
|
||||
public void testPow() {
|
||||
Complex x = new Complex(3, 4);
|
||||
Complex y = new Complex(5, 6);
|
||||
|
@ -112,12 +362,91 @@ public class ComplexUtilsTest extends TestCase {
|
|||
assertTrue(ComplexUtils.pow(x, Complex.NaN).isNaN());
|
||||
}
|
||||
|
||||
public void testPowInf() {
|
||||
TestUtils.assertSame(Complex.NaN,ComplexUtils.pow(Complex.ONE, oneInf));
|
||||
TestUtils.assertSame(Complex.NaN,ComplexUtils.pow(Complex.ONE, oneNegInf));
|
||||
TestUtils.assertSame(Complex.NaN,ComplexUtils.pow(Complex.ONE, infOne));
|
||||
TestUtils.assertSame(Complex.NaN,ComplexUtils.pow(Complex.ONE, infInf));
|
||||
TestUtils.assertSame(Complex.NaN,ComplexUtils.pow(Complex.ONE, infNegInf));
|
||||
TestUtils.assertSame(Complex.NaN,ComplexUtils.pow(Complex.ONE, negInfInf));
|
||||
TestUtils.assertSame(Complex.NaN,ComplexUtils.pow(Complex.ONE, negInfNegInf));
|
||||
TestUtils.assertSame(Complex.NaN,ComplexUtils.pow(infOne, Complex.ONE));
|
||||
TestUtils.assertSame(Complex.NaN,ComplexUtils.pow(negInfOne, Complex.ONE));
|
||||
TestUtils.assertSame(Complex.NaN,ComplexUtils.pow(infInf, Complex.ONE));
|
||||
TestUtils.assertSame(Complex.NaN,ComplexUtils.pow(infNegInf, Complex.ONE));
|
||||
TestUtils.assertSame(Complex.NaN,ComplexUtils.pow(negInfInf, Complex.ONE));
|
||||
TestUtils.assertSame(Complex.NaN,ComplexUtils.pow(negInfNegInf, Complex.ONE));
|
||||
TestUtils.assertSame(Complex.NaN,ComplexUtils.pow(negInfNegInf, infNegInf));
|
||||
TestUtils.assertSame(Complex.NaN,ComplexUtils.pow(negInfNegInf, negInfNegInf));
|
||||
TestUtils.assertSame(Complex.NaN,ComplexUtils.pow(negInfNegInf, infInf));
|
||||
TestUtils.assertSame(Complex.NaN,ComplexUtils.pow(infInf, infNegInf));
|
||||
TestUtils.assertSame(Complex.NaN,ComplexUtils.pow(infInf, negInfNegInf));
|
||||
TestUtils.assertSame(Complex.NaN,ComplexUtils.pow(infInf, infInf));
|
||||
TestUtils.assertSame(Complex.NaN,ComplexUtils.pow(infNegInf, infNegInf));
|
||||
TestUtils.assertSame(Complex.NaN,ComplexUtils.pow(infNegInf, negInfNegInf));
|
||||
TestUtils.assertSame(Complex.NaN,ComplexUtils.pow(infNegInf, infInf));
|
||||
}
|
||||
|
||||
public void testPowZero() {
|
||||
TestUtils.assertSame(Complex.NaN,
|
||||
ComplexUtils.pow(Complex.ZERO, Complex.ONE));
|
||||
TestUtils.assertSame(Complex.NaN,
|
||||
ComplexUtils.pow(Complex.ZERO, Complex.ZERO));
|
||||
TestUtils.assertSame(Complex.NaN,
|
||||
ComplexUtils.pow(Complex.ZERO, Complex.I));
|
||||
TestUtils.assertEquals(Complex.ONE,
|
||||
ComplexUtils.pow(Complex.ONE, Complex.ZERO), 10e-12);
|
||||
TestUtils.assertEquals(Complex.ONE,
|
||||
ComplexUtils.pow(Complex.I, Complex.ZERO), 10e-12);
|
||||
TestUtils.assertEquals(Complex.ONE,
|
||||
ComplexUtils.pow(new Complex(-1, 3), Complex.ZERO), 10e-12);
|
||||
}
|
||||
|
||||
public void testpowNull() {
|
||||
try {
|
||||
Complex z = ComplexUtils.pow(null, Complex.ONE);
|
||||
fail("Expecting NullPointerException");
|
||||
} catch (NullPointerException ex) {
|
||||
// expected
|
||||
}
|
||||
try {
|
||||
Complex z = ComplexUtils.pow(Complex.ONE, null);
|
||||
fail("Expecting NullPointerException");
|
||||
} catch (NullPointerException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testSin() {
|
||||
Complex z = new Complex(3, 4);
|
||||
Complex expected = new Complex(3.853738, -27.01681);
|
||||
TestUtils.assertEquals(expected, ComplexUtils.sin(z), 1.0e-5);
|
||||
}
|
||||
|
||||
public void testSinInf() {
|
||||
TestUtils.assertSame(infInf, ComplexUtils.sin(oneInf));
|
||||
TestUtils.assertSame(infNegInf, ComplexUtils.sin(oneNegInf));
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.sin(infOne));
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.sin(negInfOne));
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.sin(infInf));
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.sin(infNegInf));
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.sin(negInfInf));
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.sin(negInfNegInf));
|
||||
}
|
||||
|
||||
public void testSinNaN() {
|
||||
assertTrue(ComplexUtils.sin(Complex.NaN).isNaN());
|
||||
}
|
||||
|
||||
public void testSinNull() {
|
||||
try {
|
||||
Complex z = ComplexUtils.sin(null);
|
||||
fail("Expecting NullPointerException");
|
||||
} catch (NullPointerException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testSinh() {
|
||||
Complex z = new Complex(3, 4);
|
||||
Complex expected = new Complex(-6.54812, -7.61923);
|
||||
|
@ -128,8 +457,24 @@ public class ComplexUtilsTest extends TestCase {
|
|||
assertTrue(ComplexUtils.sinh(Complex.NaN).isNaN());
|
||||
}
|
||||
|
||||
public void testSinNaN() {
|
||||
assertTrue(ComplexUtils.sin(Complex.NaN).isNaN());
|
||||
public void testSinhInf() {
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.sinh(oneInf));
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.sinh(oneNegInf));
|
||||
TestUtils.assertSame(infInf, ComplexUtils.sinh(infOne));
|
||||
TestUtils.assertSame(negInfInf, ComplexUtils.sinh(negInfOne));
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.sinh(infInf));
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.sinh(infNegInf));
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.sinh(negInfInf));
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.sinh(negInfNegInf));
|
||||
}
|
||||
|
||||
public void testsinhNull() {
|
||||
try {
|
||||
Complex z = ComplexUtils.sinh(null);
|
||||
fail("Expecting NullPointerException");
|
||||
} catch (NullPointerException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testSqrtRealPositive() {
|
||||
|
@ -162,6 +507,44 @@ public class ComplexUtilsTest extends TestCase {
|
|||
TestUtils.assertEquals(expected, ComplexUtils.sqrt(z), 1.0e-5);
|
||||
}
|
||||
|
||||
public void testSqrtPolar() {
|
||||
double r = 1;
|
||||
for (int i = 0; i < 5; i++) {
|
||||
r += i;
|
||||
double theta = 0;
|
||||
for (int j =0; j < 11; j++) {
|
||||
theta += pi /12;
|
||||
Complex z = ComplexUtils.polar2Complex(r, theta);
|
||||
Complex sqrtz = ComplexUtils.polar2Complex(Math.sqrt(r), theta / 2);
|
||||
TestUtils.assertEquals(sqrtz, ComplexUtils.sqrt(z), 10e-12);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void testSqrtNaN() {
|
||||
assertTrue(ComplexUtils.sqrt(Complex.NaN).isNaN());
|
||||
}
|
||||
|
||||
public void testSqrtInf() {
|
||||
TestUtils.assertSame(infNaN, ComplexUtils.sqrt(oneInf));
|
||||
TestUtils.assertSame(infNaN, ComplexUtils.sqrt(oneNegInf));
|
||||
TestUtils.assertSame(infZero, ComplexUtils.sqrt(infOne));
|
||||
TestUtils.assertSame(zeroInf, ComplexUtils.sqrt(negInfOne));
|
||||
TestUtils.assertSame(infNaN, ComplexUtils.sqrt(infInf));
|
||||
TestUtils.assertSame(infNaN, ComplexUtils.sqrt(infNegInf));
|
||||
TestUtils.assertSame(nanInf, ComplexUtils.sqrt(negInfInf));
|
||||
TestUtils.assertSame(nanNegInf, ComplexUtils.sqrt(negInfNegInf));
|
||||
}
|
||||
|
||||
public void testSqrtNull() {
|
||||
try {
|
||||
Complex z = ComplexUtils.sqrt(null);
|
||||
fail("Expecting NullPointerException");
|
||||
} catch (NullPointerException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testSqrt1z() {
|
||||
Complex z = new Complex(3, 4);
|
||||
Complex expected = new Complex(4.08033, -2.94094);
|
||||
|
@ -172,8 +555,13 @@ public class ComplexUtilsTest extends TestCase {
|
|||
assertTrue(ComplexUtils.sqrt1z(Complex.NaN).isNaN());
|
||||
}
|
||||
|
||||
public void testSqrtNaN() {
|
||||
assertTrue(ComplexUtils.sqrt(Complex.NaN).isNaN());
|
||||
public void testSqrt1zNull() {
|
||||
try {
|
||||
Complex z = ComplexUtils.sqrt1z(null);
|
||||
fail("Expecting NullPointerException");
|
||||
} catch (NullPointerException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testTan() {
|
||||
|
@ -182,6 +570,35 @@ public class ComplexUtilsTest extends TestCase {
|
|||
TestUtils.assertEquals(expected, ComplexUtils.tan(z), 1.0e-5);
|
||||
}
|
||||
|
||||
public void testTanNaN() {
|
||||
assertTrue(ComplexUtils.tan(Complex.NaN).isNaN());
|
||||
}
|
||||
|
||||
public void testTanInf() {
|
||||
TestUtils.assertSame(zeroNaN, ComplexUtils.tan(oneInf));
|
||||
TestUtils.assertSame(zeroNaN, ComplexUtils.tan(oneNegInf));
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.tan(infOne));
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.tan(negInfOne));
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.tan(infInf));
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.tan(infNegInf));
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.tan(negInfInf));
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.tan(negInfNegInf));
|
||||
}
|
||||
|
||||
public void testTanCritical() {
|
||||
TestUtils.assertSame(infNaN, ComplexUtils.tan(new Complex(pi/2, 0)));
|
||||
TestUtils.assertSame(negInfNaN, ComplexUtils.tan(new Complex(-pi/2, 0)));
|
||||
}
|
||||
|
||||
public void testTanNull() {
|
||||
try {
|
||||
Complex z = ComplexUtils.tan(null);
|
||||
fail("Expecting NullPointerException");
|
||||
} catch (NullPointerException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testTanh() {
|
||||
Complex z = new Complex(3, 4);
|
||||
Complex expected = new Complex(1.00071, 0.00490826);
|
||||
|
@ -192,7 +609,27 @@ public class ComplexUtilsTest extends TestCase {
|
|||
assertTrue(ComplexUtils.tanh(Complex.NaN).isNaN());
|
||||
}
|
||||
|
||||
public void testTanNaN() {
|
||||
assertTrue(ComplexUtils.tan(Complex.NaN).isNaN());
|
||||
public void testTanhInf() {
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.tanh(oneInf));
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.tanh(oneNegInf));
|
||||
TestUtils.assertSame(nanZero, ComplexUtils.tanh(infOne));
|
||||
TestUtils.assertSame(nanZero, ComplexUtils.tanh(negInfOne));
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.tanh(infInf));
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.tanh(infNegInf));
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.tanh(negInfInf));
|
||||
TestUtils.assertSame(Complex.NaN, ComplexUtils.tanh(negInfNegInf));
|
||||
}
|
||||
|
||||
public void testTanhCritical() {
|
||||
TestUtils.assertSame(nanInf, ComplexUtils.tanh(new Complex(0, pi/2)));
|
||||
}
|
||||
|
||||
public void testTanhNull() {
|
||||
try {
|
||||
Complex z = ComplexUtils.tanh(null);
|
||||
fail("Expecting NullPointerException");
|
||||
} catch (NullPointerException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -115,6 +115,11 @@ public final class EmpiricalDistributionTest extends RetryTestCase {
|
|||
assertEquals
|
||||
(empiricalDistribution2.getSampleStats().getStandardDeviation(),
|
||||
1.0173699343977738,10E-7);
|
||||
|
||||
double[] bounds = empiricalDistribution2.getUpperBounds();
|
||||
assertEquals(bounds.length, 100);
|
||||
assertEquals(bounds[99], 1.0, 10e-12);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -421,12 +421,18 @@ public class RandomDataTest extends RetryTestCase {
|
|||
/* remove this test back soon,
|
||||
* since it takes about 4 seconds */
|
||||
|
||||
try {
|
||||
randomData.setSecureAlgorithm("SHA1PRNG","SUN");
|
||||
} catch (NoSuchProviderException ex) {
|
||||
;
|
||||
}
|
||||
assertTrue("different seeds",
|
||||
!hex.equals(randomData.nextSecureHexString(40)));
|
||||
try {
|
||||
randomData.setSecureAlgorithm("NOSUCHTHING","SUN");
|
||||
fail("expecting NoSuchAlgorithmException");
|
||||
} catch (NoSuchProviderException ex) {
|
||||
;
|
||||
} catch (NoSuchAlgorithmException ex) {
|
||||
;
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ import org.apache.commons.math.util.NumberTransformer;
|
|||
public class ListUnivariateImpl extends DescriptiveStatistics implements Serializable {
|
||||
|
||||
/** Serializable version identifier */
|
||||
static final long serialVersionUID = -8837442489133392138L;
|
||||
private static final long serialVersionUID = -8837442489133392138L;
|
||||
|
||||
/**
|
||||
* Holds a reference to a list - GENERICs are going to make
|
||||
|
|
|
@ -38,7 +38,7 @@ The <action> type attribute can be add,update,fix,remove.
|
|||
Commons Math Release Notes</title>
|
||||
</properties>
|
||||
<body>
|
||||
<release version="1.2" date="TBD">
|
||||
<release version="1.2-SNAPSHOT" date="TBD">
|
||||
</release>
|
||||
<release version="1.1" date="2005-12-17"
|
||||
description="This is a maintenance release containing bug fixes and enhancements.
|
||||
|
|
Loading…
Reference in New Issue