Java Array Divide divideAbsolute(double[] one, double[] two)

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

Description

Divides two arrays of complex numbers.

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[] divideAbsolute(double[] one, double[] two) 

Method Source Code

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

public class Main {
    /**
     * Divides two arrays of complex numbers. The absolute value of the second array is used to divide the complex first array.
     * @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[] divideAbsolute(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] / abs(i, two));
                revan[(2 * i) + 1] = (one[(2 * i) + 1] / abs(i, two));
            }
        }
        return revan;
    }

    /**
     * Computes the absolute value of the complex number at position pos in the array
     * @param pos the position
     * @param array the array which contains the values
     * @return the absolute value
     */
    public static double abs(int pos, double[] array) {
        return Math.sqrt(Math.pow(array[pos * 2], 2)
                + Math.pow(array[(2 * pos) + 1], 2));
    }

    /**
     * Computes the absolute values of the complex number at posx, posy in the 2D array array.
     * 
     * @param posx x position
     * @param posy y position
     * @param array the array
     * @return the absolute value of the complex number
     */
    public static double abs(int posx, int posy, double[][] array) {
        return Math.sqrt(Math.pow(array[posx][posy * 2], 2)
                + Math.pow(array[posx][(2 * posy) + 1], 2));
    }
}

Related

  1. divide(float[] array, float divident)
  2. divide(float[][] a, float num)
  3. divide(float[][][][] img, float val)
  4. divide(int[] array1, int[] array2)
  5. divide(long[] array, double value)
  6. divideAndConquer(int[] array, int num)
  7. divideArray(float[] array, float num)
  8. divideArray(T[] arr, Integer... cuts)
  9. divideArrayElements(final int[] array, final int divisor)