Java Array Multiply multiplyComplex(double[] one, double[] two)

Here you can find the source of multiplyComplex(double[] one, double[] two)

Description

Multiplies two arrays of complex numbers pairwise

License

Open Source License

Parameter

Parameter Description
one the first array
two the second array

Return

the array of null if the lengths of the arrays don't match

Declaration

public static double[] multiplyComplex(double[] one, double[] two) 

Method Source Code

//package com.java2s;
/*// w w  w .  ja  v a2 s . com
 * Copyright (C) 2010-2014  Andreas Maier
 * CONRAD is developed as an Open Source project under the GNU General Public License (GPL).
 */

public class Main {
    /**
     * Multiplies two complex values
     * @param realOne real part one
     * @param imagOne imaginary part one
     * @param realTwo real part two
     * @param imagTwo imaginary part two
     * @return an array of two values: first entry is real, second imaginary
     */
    public static double[] multiplyComplex(double realOne, double imagOne,
            double realTwo, double imagTwo) {
        double[] revan = new double[2];
        revan[0] = (realOne * realTwo) - (imagOne * imagTwo);
        revan[1] = (imagOne * realTwo) + (realOne * imagTwo);
        return revan;
    }

    /**
     * Multiplies two arrays of complex numbers pairwise
     * @param one the first array
     * @param two the second array
     * @return the array of null if the lengths of the arrays don't match
     */
    public static double[] multiplyComplex(double[] one, double[] two) {
        double[] revan = null;
        if (one.length == two.length) {
            revan = new double[one.length];
            for (int i = 0; i < one.length / 2; i++) {
                revan[2 * i] = (one[2 * i] * two[2 * i])
                        - (one[(2 * i) + 1] * two[(2 * i) + 1]);
                revan[(2 * i) + 1] = (one[(2 * i) + 1] * two[2 * i])
                        + (one[2 * i] * two[(2 * i) + 1]);
            }
        }
        return revan;
    }
}

Related

  1. multiplyAndSum(double[] r1, double[] r2)
  2. multiplyAndSum(final double[] d, final double scale)
  3. multiplyArray(float[] array, float num)
  4. multiplyByScalar(double scalar, double[] vector)
  5. multiplyBytes(byte[] in, int count, int mul)
  6. multiplyComplexVectors(float[] cA, float[] cB, long limit)
  7. multiplycst(int k, double[] t)
  8. multiplyElementwise(double[] a, int[] b)
  9. multiplyHarmonics(float[] powerSpectrumInOut, int nHarmonics)