本文整理匯總了Java中org.apache.commons.math3.complex.Complex.add方法的典型用法代碼示例。如果您正苦於以下問題:Java Complex.add方法的具體用法?Java Complex.add怎麽用?Java Complex.add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.math3.complex.Complex
的用法示例。
在下文中一共展示了Complex.add方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: calculateZernikeMoment
import org.apache.commons.math3.complex.Complex; //導入方法依賴的package包/類
/**
* Compute Zernike moments at specified order.
*
* @param w Width of the bounding box of the shape.
* @param h Height of the bounding box of the shape.
* @param n 1st order of the moment.
* @param m 2nd order of the moment.
*
* @return Zernike moment of data in f[][].
*/
public static Complex calculateZernikeMoment(double[][] f, int w, int h, int n, int m){
int diff = n-Math.abs(m);
if ((n<0) || (Math.abs(m) > n) || (diff%2!=0)){
throw new IllegalArgumentException("zer_mom: n="+n+", m="+m+", n-|m|="+diff);
}
final double c = -1;
final double d = 1;
ZernikeBasisFunction zernike = new ZernikeBasisFunction(n,m);
Complex res = new Complex(0.0, 0.0);
for (int i=0;i<w;i++){
for (int j=0;j<h;j++) {
Complex v = new Complex(c+(i*(d-c))/(w-1), d-(j*(d-c))/(h-1));
res = res.add(zernike.value(v).conjugate().multiply(f[i][j]));
}
}
return res.multiply((n+1)/Math.PI);
}
示例2: F
import org.apache.commons.math3.complex.Complex; //導入方法依賴的package包/類
public static final Complex F(Complex phi, final Complex k) { //series solution to incomplete elliptic integral of the first kind
final double TOLERANCE = 1e-3;
Complex sum = Complex.ZERO;
Complex i_n = phi;
Complex delt;
int n = 0;
do {
if (n > 0)
i_n = i_n.multiply((2.0 * n - 1) / (2.0 * n))
.subtract(phi.cos().multiply(phi.sin().pow(2.0 * n - 1)).divide(2.0 * n));
delt = i_n.multiply(Math.abs(Math2.combine(-.5, n))).multiply(k.pow(2.0 * n));
sum = sum.add(delt);
n ++;
} while (delt.abs() > TOLERANCE);
return sum;
}
示例3: sum
import org.apache.commons.math3.complex.Complex; //導入方法依賴的package包/類
private Complex sum() {
Complex lhs = product();
while (current.type == Token.Type.PLUS ||
current.type == Token.Type.MINUS)
if (current.type == Token.Type.PLUS) {
eat(Token.Type.PLUS);
lhs = lhs.add(product());
} else {
eat(Token.Type.MINUS);
lhs = lhs.subtract(product());
}
return lhs;
}
示例4: toSv1
import org.apache.commons.math3.complex.Complex; //導入方法依賴的package包/類
public StateVariable toSv1(StateVariable sv2) {
Complex s2 = new Complex(-sv2.p, -sv2.q); // s2=p2+jq2
Complex u2 = ComplexUtils.polar2Complex(sv2.u, Math.toRadians(sv2.theta));
Complex v2 = u2.divide(SQUARE_3); // v2=u2/sqrt(3)
Complex i2 = s2.divide(v2.multiply(3)).conjugate(); // i2=conj(s2/(3*v2))
Complex v1p = v2.add(z.multiply(i2)); // v1'=v2+z*i2
Complex i1p = i2.negate().add(y.multiply(v1p)); // i1'=-i2+v1'*y
Complex i1 = i1p.multiply(ratio); // i1=i1p*ration
Complex v1 = v1p.divide(ratio); // v1=v1p/ration
Complex s1 = v1.multiply(3).multiply(i1.conjugate()); // s1=3*v1*conj(i1)
Complex u1 = v1.multiply(SQUARE_3);
return new StateVariable(-s1.getReal(), -s1.getImaginary(), u1.abs(), Math.toDegrees(u1.getArgument()));
}
示例5: testOrthogonality
import org.apache.commons.math3.complex.Complex; //導入方法依賴的package包/類
/**
* Tests if orthogonality relation that exists between two Zernike Polynoms holds true
* for all n between 1 and 5.
*/
@Test
@DisplayName("Test Orthogonality")
void testOrthogonality() {
final double increment = 0.25e-2;
final double n_max = 5;
for (int n1=1;n1<=n_max;n1++) {
for (int m1=0; m1<=n1;m1++) {
for (int n2=1;n2<=n_max;n2++) {
for (int m2=0;m2<=n2;m2++) {
if (((n1-Math.abs(m1)) % 2 == 0) && ((n2-Math.abs(m2)) % 2 == 0)) {
Complex result = new Complex(0, 0);
/* Initialize ZernikeBasisFunctions for n1,m1 and n2,m2. */
final ZernikeBasisFunction ZF1 = new ZernikeBasisFunction(n1, m1);
final ZernikeBasisFunction ZF2 = new ZernikeBasisFunction(n2, m2);
final double expected = ((Math.PI) / (n1 + 1)) * MathHelper.kronecker(n1,n2) * MathHelper.kronecker(m1,m2);
/* Calculate integral (approximation). */
for (double theta = 0.0; theta <= 2 * Math.PI; theta += increment) {
for (double r = 0.0; r <= 1.0f; r += increment) {
Complex v = new Complex(r * FastMath.cos(theta), r * FastMath.sin(theta));
Complex res1 = ZF1.value(v);
Complex res2 = ZF2.value(v);
result = result.add(res1.conjugate().multiply(res2).multiply(r * increment * increment));
}
}
/* Result of integral must be equal to expected value. */
assertEquals(expected, result.abs(), 1e-2);
}
}
}
}
}
}
示例6: solveAll
import org.apache.commons.math3.complex.Complex; //導入方法依賴的package包/類
/**
* Find all complex roots for the polynomial with the given
* coefficients, starting from the given initial value.
*
* @param coefficients Polynomial coefficients.
* @param initial Start value.
* @return the point at which the function value is zero.
* @throws org.apache.commons.math3.exception.TooManyEvaluationsException
* if the maximum number of evaluations is exceeded.
* @throws NullArgumentException if the {@code coefficients} is
* {@code null}.
* @throws NoDataException if the {@code coefficients} array is empty.
*/
public Complex[] solveAll(Complex coefficients[], Complex initial)
throws NullArgumentException,
NoDataException,
TooManyEvaluationsException {
if (coefficients == null) {
throw new NullArgumentException();
}
final int n = coefficients.length - 1;
if (n == 0) {
throw new NoDataException(LocalizedFormats.POLYNOMIAL);
}
// Coefficients for deflated polynomial.
final Complex c[] = new Complex[n + 1];
for (int i = 0; i <= n; i++) {
c[i] = coefficients[i];
}
// Solve individual roots successively.
final Complex root[] = new Complex[n];
for (int i = 0; i < n; i++) {
final Complex subarray[] = new Complex[n - i + 1];
System.arraycopy(c, 0, subarray, 0, subarray.length);
root[i] = solve(subarray, initial);
// Polynomial deflation using synthetic division.
Complex newc = c[n - i];
Complex oldc = null;
for (int j = n - i - 1; j >= 0; j--) {
oldc = c[j];
c[j] = newc;
newc = oldc.add(newc.multiply(root[i]));
}
}
return root;
}
示例7: runObserver
import org.apache.commons.math3.complex.Complex; //導入方法依賴的package包/類
@Override
public DropletObserverResult runObserver(ExecutionInformation executionInformation, MeasurementContext measurementContext,
double dropletOffset, int microfluidicChipID) throws ResourceException, RemoteException
{
assertInitialized();
ObserverState state = loadState(measurementContext, microfluidicChipID);
int l = state.getNextDropletID(executionInformation);
double[] x = state.getEstimatedOffsets();
double c0 = state.getObserverMean();
double c1 = state.getObserverIndividual();
int N = state.getNumDroplets(); // number of droplets
double pi = Math.PI;
double y = x[l]; // estimated offset for current droplet
double h = dropletOffset; // observed offset
// Transform states by discrete Fourier transform (DFT).
Complex[] z = new Complex[N];
for(int i=0; i<N; i++)
{
z[i] = new Complex(0);
for(int k=0; k<N; k++)
{
z[i] = z[i].add(ComplexUtils.polar2Complex(1.0/N, -2.0*pi*k/N*i).multiply(x[k]));
}
}
// Update step
// Formula in Matlab: zp = z + ct/N .* exp(-2*pi*j * K.' * l/N) * (h-y);
for(int i=0; i<N; i++)
{
double c;
if(i == 0)
c=c0;
else
c=c1;
z[i] = z[i].add(ComplexUtils.polar2Complex(c/N, -2.0*pi*i/N*l).multiply(h-y));
}
// Transform states back by inverse discrete Fourier transformation (IDFT).
for(int i=0; i<N; i++)
{
Complex xi = new Complex(0);
for(int k=0; k<N; k++)
{
xi = xi.add(ComplexUtils.polar2Complex(1.0, 2.0*pi*k/N*i).multiply(z[k]));
}
x[i] = xi.getReal();
}
// Save result
state.setEstimatedOffsets(x);
saveState(state, measurementContext, microfluidicChipID);
sendMessage("Observed droplet offset of " + Integer.toString((int)dropletOffset) + "um, estimated before "+Integer.toString((int)y) + "um. Changed mean droplet offset estimate to "+Integer.toString((int)z[0].getReal())+"um.");
return new DropletObserverResult(l, x);
}