當前位置: 首頁>>代碼示例>>Java>>正文


Java Complex.abs方法代碼示例

本文整理匯總了Java中org.apache.commons.math3.complex.Complex.abs方法的典型用法代碼示例。如果您正苦於以下問題:Java Complex.abs方法的具體用法?Java Complex.abs怎麽用?Java Complex.abs使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.math3.complex.Complex的用法示例。


在下文中一共展示了Complex.abs方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: otherSide

import org.apache.commons.math3.complex.Complex; //導入方法依賴的package包/類
public SV otherSide(float r, float x, float g, float b, float ratio) {
    Complex z = new Complex(r, x); // z=r+jx
    Complex y = new Complex(g, b); // y=g+jb
    Complex s1 = new Complex(p, q); // s1=p1+jq1
    Complex u1 = ComplexUtils.polar2Complex(u, Math.toRadians(a));
    Complex v1 = u1.divide(Math.sqrt(3f)); // v1=u1/sqrt(3)

    Complex v1p = v1.multiply(ratio); // v1p=v1*rho
    Complex i1 = s1.divide(v1.multiply(3)).conjugate(); // i1=conj(s1/(3*v1))
    Complex i1p = i1.divide(ratio); // i1p=i1/rho
    Complex i2 = i1p.subtract(y.multiply(v1p)); // i2=i1p-y*v1p
    Complex v2 = v1p.subtract(z.multiply(i2)); // v2=v1p-z*i2
    Complex s2 = v2.multiply(3).multiply(i2.conjugate()); // s2=3*v2*conj(i2)

    Complex u2 = v2.multiply(Math.sqrt(3f));
    return new SV((float) -s2.getReal(), (float) -s2.getImaginary(), (float) u2.abs(), (float) Math.toDegrees(u2.getArgument()));
}
 
開發者ID:powsybl,項目名稱:powsybl-core,代碼行數:18,代碼來源:SV.java

示例2: featureVectorsFromImage

import org.apache.commons.math3.complex.Complex; //導入方法依賴的package包/類
/**
 * Extracts the Lightfield Fourier descriptors from a provided BufferedImage. The returned list contains
 * elements for each identified contour of adequate size.
 *
 * @param image Image for which to extract the Lightfield Fourier descriptors.
 * @param poseidx Poseidx of the extracted image.
 * @return List of descriptors for image.
 */
@Override
protected List<float[]> featureVectorsFromImage(BufferedImage image, int poseidx) {
    final List<ZernikeMoments> moments = ZernikeHelper.zernikeMomentsForShapes(image, RENDERING_SIZE /2, 10);
    final List<float[]> features = new ArrayList<>(moments.size());
    for (ZernikeMoments moment : moments) {
        float[] feature = new float[SIZE];
        int i = 0;
        for (Complex m : moment.getMoments()) {
            feature[i] = (float)m.abs();
            i++;
        }
        feature = MathHelper.normalizeL2InPlace(feature);
        feature[0] = poseidx;
        features.add(feature);
    }
    return features;
}
 
開發者ID:vitrivr,項目名稱:cineast,代碼行數:26,代碼來源:LightfieldZernike.java

示例3: computeEnergy

import org.apache.commons.math3.complex.Complex; //導入方法依賴的package包/類
/**
 * Compute the signal energy using FFTs
 * <p>
 * Reference: Matlab \\TODO
 * </p>
 *
 * @param data Input data array
 * @param inc  Increment
 * @return Energy
 */
public static double computeEnergy(double[] data, int inc) {
    double result = 0;

    int NFFT = nextPower2(data.length);

    double[] buffer = new double[NFFT];
    System.arraycopy(data, 0, buffer, 0, data.length);

    FastFourierTransformer f = new FastFourierTransformer(DftNormalization.STANDARD);
    Complex[] fftC = f.transform(buffer, TransformType.FORWARD);

    for (Complex aFftC : fftC) {
        result += (aFftC.abs() / inc) * (aFftC.abs() / inc);
    }
    return result;
}
 
開發者ID:MD2Korg,項目名稱:stream-processor,代碼行數:27,代碼來源:ECG.java

示例4: 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;
}
 
開發者ID:jkunimune15,項目名稱:Map-Projections,代碼行數:20,代碼來源:Elliptic.java

示例5: toSv2

import org.apache.commons.math3.complex.Complex; //導入方法依賴的package包/類
public StateVariable toSv2(StateVariable sv1) {
    Complex s1 = new Complex(-sv1.p, -sv1.q); // s1=p1+jq1
    Complex u1 = ComplexUtils.polar2Complex(sv1.u, Math.toRadians(sv1.theta));
    Complex v1 = u1.divide(SQUARE_3); // v1=u1/sqrt(3)
    Complex v1p = v1.multiply(ratio); // v1p=v1*rho
    Complex i1 = s1.divide(v1.multiply(3)).conjugate(); // i1=conj(s1/(3*v1))
    Complex i1p = i1.divide(ratio); // i1p=i1/rho
    Complex i2 = i1p.subtract(y.multiply(v1p)).negate(); // i2=-(i1p-y*v1p)
    Complex v2 = v1p.subtract(z.multiply(i2)); // v2=v1p-z*i2
    Complex s2 = v2.multiply(3).multiply(i2.conjugate()); // s2=3*v2*conj(i2)
    Complex u2 = v2.multiply(SQUARE_3);
    return new StateVariable(-s2.getReal(), -s2.getImaginary(), u2.abs(), Math.toDegrees(u2.getArgument()));
}
 
開發者ID:itesla,項目名稱:ipst,代碼行數:14,代碼來源:TransformerModel.java

示例6: 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()));
}
 
開發者ID:itesla,項目名稱:ipst,代碼行數:14,代碼來源:TransformerModel.java

示例7: isZero

import org.apache.commons.math3.complex.Complex; //導入方法依賴的package包/類
/**
 * Returns true if the FFT only contains zeros and false
 * otherwise
 */
public final boolean isZero() {
    for (Complex coefficient : this.data) {
        if (coefficient.abs() > 0) {
          return false;
        }
    }
    return true;
}
 
開發者ID:vitrivr,項目名稱:cineast,代碼行數:13,代碼來源:FFT.java

示例8: add_item_simulate

import org.apache.commons.math3.complex.Complex; //導入方法依賴的package包/類
private void add_item_simulate(final JMenu circuit_menu) {
	JMenuItem item_simulate = new JMenuItem(new AbstractAction("Simulate") {
		private static final long serialVersionUID = 8549028014281850661L;

		@Override
		public void actionPerformed(ActionEvent arg0) {	
			try {
				Circuit circuit = new Circuit(gate_table.get_table());
				FieldVector<Complex> results = circuit.operate(qubit_table.get_qubits());
				
				StringBuilder text = new StringBuilder("<html>Simulation results:<table cellspacing=\"0\" cellpadding=\"0\">");
				
				final int qubits_number = Integer.toBinaryString(results.getDimension() - 1).length();
				for (int index = 0; index < results.getDimension(); index++) {
					final Complex current = results.getEntry(index);
					final double current_magnitude = current.abs();
					
					if (!show_all_checkbox.isSelected() && Tools.equal(current_magnitude, 0))
						continue;
					
					double current_percentage = Math.pow(current_magnitude, 2) * 100;
					current_percentage = Tools.round(current_percentage);
					
					StringBuilder qubits_values = new StringBuilder(Integer.toBinaryString(index));
					for (int length = qubits_values.length(); length < qubits_number; length++)
						qubits_values.insert(0, '0');
					
					text.append("<tr><td>" + Tools.round(current.getReal()) + (current.getImaginary() < 0 ? "" : "+") +
							Tools.round(current.getImaginary()) + "i |" + qubits_values + ">&emsp;&emsp;</td><td>" +
							current_percentage + "% chance</td></tr>");
				}
				
				text.append("</table></html>");
				result_text_pane.setText(text.toString());
			} catch (RuntimeException ex) {
				Tools.error(frame, "A runtime exception has been caught:\n" + ex.getMessage());
				ex.printStackTrace();
			}
		}
	});
	item_simulate.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W, 0));
	circuit_menu.add(item_simulate);
}
 
開發者ID:QwertygidQ,項目名稱:DeutschSim,代碼行數:44,代碼來源:GUI.java

示例9: fft

import org.apache.commons.math3.complex.Complex; //導入方法依賴的package包/類
public static double[] fft(short[] buffer, int offset, int len) {
        int len2 = (int) Math.pow(2, Math.ceil(Math.log(len) / Math.log(2)));

        final double[][] dataRI = new double[][]{
                new double[len2], new double[len2]
        };

        double[] dataR = dataRI[0];
        double[] dataI = dataRI[1];

        double powerInput = 0;
        for (int i = 0; i < len; i++) {
            dataR[i] = buffer[offset + i] / (float) 0x7fff;
            powerInput += dataR[i] * dataR[i];
        }
        powerInput = Math.sqrt(powerInput / len);

        FastFourierTransformer.transformInPlace(dataRI, DftNormalization.STANDARD, TransformType.FORWARD);

        double[] data = new double[len2 / 2];

        data[0] = 10 * Math.log10(Math.pow(new Complex(dataR[0], dataI[0]).abs() / len2, 2));

        double powerOutput = 0;
        for (int i = 1; i < data.length; i++) {
            Complex c = new Complex(dataR[i], dataI[i]);
            double p = c.abs();
            p = p / len2;
            p = p * p;
            p = p * 2;
            double dB = 10 * Math.log10(p);

            powerOutput += p;
            data[i] = dB;
        }
        powerOutput = Math.sqrt(powerOutput);

//        if(powerInput != powerOutput) {
//            throw new RuntimeException("in " + powerInput + " out " + powerOutput);
//        }

        return data;
    }
 
開發者ID:NandagopalR,項目名稱:Android-Audio-Recorder,代碼行數:44,代碼來源:FFTView.java

示例10: isRoot

import org.apache.commons.math3.complex.Complex; //導入方法依賴的package包/類
/**
 * Check whether the given complex root is actually a real zero
 * in the given interval, within the solver tolerance level.
 *
 * @param min Lower bound for the interval.
 * @param max Upper bound for the interval.
 * @param z Complex root.
 * @return {@code true} if z is a real zero.
 */
public boolean isRoot(double min, double max, Complex z) {
    if (isSequence(min, z.getReal(), max)) {
        double tolerance = FastMath.max(getRelativeAccuracy() * z.abs(), getAbsoluteAccuracy());
        return (FastMath.abs(z.getImaginary()) <= tolerance) ||
             (z.abs() <= getFunctionValueAccuracy());
    }
    return false;
}
 
開發者ID:biocompibens,項目名稱:SME,代碼行數:18,代碼來源:LaguerreSolver.java


注:本文中的org.apache.commons.math3.complex.Complex.abs方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。