List of usage examples for org.apache.commons.math.complex Complex multiply
public Complex multiply(double rhs)
From source file:com.discursive.jccook.math.ComplexNumbers.java
public static void main(String[] args) { Complex a = new Complex(2, 3); Complex b = new Complex(4, 5); Complex c = new Complex(0.3, 2); Complex e = new Complex(4, 4); Complex sum = a.add(b);//from w w w. j a v a 2 s. co m Complex d = c.divide(sum); Complex f = e.multiply(d.conjugate()); System.out.println("D is: " + ComplexFormat.formatComplex(d)); System.out.println("F is: " + ComplexFormat.formatComplex(f)); double realF = f.getReal(); double imD = d.getImaginary(); double answer = realF / imD; System.out.println("Answer: " + NumberFormat.getInstance().format(answer)); }
From source file:geogebra.common.geogebra3D.kernel3D.geos.Geo3DVec.java
final public static void complexMultiply(GeoVecInterface a, GeoVecInterface b, GeoVec2D c) { if (!Kernel.isZero(a.getZ()) || !Kernel.isZero(b.getZ())) { c.setX(Double.NaN);/*from w ww .j ava 2s . c o m*/ c.setY(Double.NaN); c.setMode(Kernel.COORD_COMPLEX); return; } Complex out = new Complex(a.getX(), a.getY()); out = out.multiply(new Complex(b.getX(), b.getY())); c.setX(out.getReal()); c.setY(out.getImaginary()); c.setMode(Kernel.COORD_COMPLEX); }
From source file:geogebra.kernel.GeoVec2D.java
/** c = a * b Michael Borcherds 2007-12-09 */ final public static void complexMultiply(GeoVec2D a, NumberValue b, GeoVec2D c) { // NB temporary variables *crucial*: a and c can be the same variable //double x1=a.x,y1=a.y,x2=b.getDouble(); // do multiply //c.x = (x1 * x2); //c.y = (x2 * y1); Complex out = new Complex(a.x, a.y); out = out.multiply(new Complex(b.getDouble(), 0)); c.x = out.getReal();/*from ww w . j a v a2 s . com*/ c.y = out.getImaginary(); c.setMode(Kernel.COORD_COMPLEX); }
From source file:geogebra.kernel.GeoVec2D.java
/** c = a * b Michael Borcherds 2007-12-09 */ final public static void complexMultiply(GeoVec2D a, GeoVec2D b, GeoVec2D c) { // NB temporary variables *crucial*: a and c can be the same variable //double x1=a.x,y1=a.y,x2=b.x,y2=b.y; // do multiply //c.x = (x1 * x2 - y1 * y2); //c.y = (y2 * x1 + x2 * y1); Complex out = new Complex(a.x, a.y); out = out.multiply(new Complex(b.x, b.y)); c.x = out.getReal();/* ww w. j a v a 2 s. com*/ c.y = out.getImaginary(); c.setMode(Kernel.COORD_COMPLEX); }
From source file:com.QMTunnelling.GaussianPotential.java
public Complex getA() {//finds A coef Complex psi1 = this.psi[0]; Complex psi2 = this.psi[1]; double x1 = this.xvals[0]; double x2 = this.xvals[1]; Complex A = (psi2.multiply(Exp(Complex.I.multiply(Math.sqrt(kappa) * x2)))); A = A.subtract(psi1.multiply(Exp(Complex.I.multiply(Math.sqrt(kappa) * x1)))); Complex divisor = Exp(Complex.I.multiply(2 * Math.sqrt(kappa) * x2)) .subtract(Exp(Complex.I.multiply(2 * Math.sqrt(kappa) * x1))); A = A.divide(divisor);//from www . ja v a 2s . c o m return A; }
From source file:geogebra.common.kernel.geos.GeoVec2D.java
/** * c = a * b Michael Borcherds 2007-12-09 * //www .ja v a2 s.c o m * @param a * factor * @param b * factor * @param c * result */ final public static void complexMultiply(GeoVec2D a, GeoVec2D b, GeoVec2D c) { Complex out = new Complex(a.x, a.y); out = out.multiply(new Complex(b.x, b.y)); c.x = out.getReal(); c.y = out.getImaginary(); c.setMode(Kernel.COORD_COMPLEX); }
From source file:geogebra.common.kernel.geos.GeoVec2D.java
/** * c = a * b Michael Borcherds 2007-12-09 * // w ww . ja v a 2s .c om * @param a * factor * @param b * factor * @param c * result */ final public static void complexMultiply(GeoVec2D a, NumberValue b, GeoVec2D c) { // NB temporary variables *crucial*: a and c can be the same variable // double x1=a.x,y1=a.y,x2=b.getDouble(); // do multiply // c.x = (x1 * x2); // c.y = (x2 * y1); Complex out = new Complex(a.x, a.y); out = out.multiply(new Complex(b.getDouble(), 0)); c.x = out.getReal(); c.y = out.getImaginary(); c.setMode(Kernel.COORD_COMPLEX); }
From source file:org.eclipse.ice.reflectivity.ReflectivityCalculator.java
/** * This operation returns the value of the squared modulus of the specular * reflectivity for a single wave vector Q. * * @param waveVectorQ/*from w w w.j ava 2 s .c o m*/ * the value of the wave vector * @param wavelength * the wavelength of the incident neutrons * @param tiles * the list of Tiles that contains the physical parameters needed * for the calculation, including the scattering densities, * absorption parameters and thicknesses. * @return the squared modulus of the specular reflectivity */ public double getModSqrdSpecRef(double waveVectorQ, double wavelength, Tile[] tiles) { double modSqrdSpecRef = 0.0; if (wavelength > 0.0) { // Variables only needed if we are going to do the work, i.e. - // wavelength > 0.0. Tile tile; Complex aNm1Sq, fNm1N, rNm1N = new Complex(0.0, 0.0), one = new Complex(1.0, 0.0), qN = new Complex(0.0, 0.0), rNNp1 = new Complex(0.0, 0.0); // Get the bottom tile int nLayers = tiles.length; tile = tiles[nLayers - 1]; // Starting point--no reflected beam in bottom-most (bulk) layer double qCSq = 16.0 * Math.PI * tile.scatteringLength; double muLAbs = tile.trueAbsLength; double mulInc = tile.incAbsLength; double thickness = tile.thickness; // Setup other values for the problem double betaNm1 = 4.0 * Math.PI * (muLAbs + mulInc / wavelength); Complex qNm1 = new Complex(waveVectorQ * waveVectorQ - qCSq, -2.0 * betaNm1); qNm1 = qNm1.sqrt(); // Loop through to calculate recursion formula described in Parratt. // Start at the bottom and work up. for (int i = nLayers - 1; i > 0; i--) { // Get the tile above tile[i] (started at the bottom tile = tiles[i - 1]; // Calculate the normal component of Q for layer and layer-1 qN = qNm1; qCSq = 16.0 * Math.PI * tile.scatteringLength; muLAbs = tile.trueAbsLength; mulInc = tile.incAbsLength; thickness = tile.thickness; betaNm1 = 4.0 * Math.PI * (muLAbs + mulInc / wavelength); qNm1 = new Complex(waveVectorQ * waveVectorQ - qCSq, -2.0 * betaNm1); qNm1 = qNm1.sqrt(); // Calculate phase factor, e^(-0.5*d*qNm1) aNm1Sq = (new Complex(qNm1.getImaginary(), qNm1.getReal()).multiply(-0.5 * thickness)).exp(); // CDiv(qNm1-qN,qNm1+qN) fNm1N = qNm1.subtract(qN).divide(qNm1.add(qN)); // Calculate the reflectivity amplitude. // CMult(aNm1Sq, CMult(aNm1Sq, CDiv(CAdd(rNNp1, fNm1N), // CAdd(CMult(rNNp1, fNm1N), CReal(1))))) Complex y = rNNp1.multiply(fNm1N).add(one); Complex z = rNNp1.add(fNm1N); rNm1N = aNm1Sq.multiply(aNm1Sq).multiply(z.divide((y))); // Carry over to the next iteration rNNp1 = rNm1N; } modSqrdSpecRef = rNm1N.getReal() * rNm1N.getReal() + rNm1N.getImaginary() * rNm1N.getImaginary(); } return modSqrdSpecRef; }
From source file:org.renjin.primitives.MathGroup.java
@Builtin public static ComplexVector cumprod(ComplexVector source) { ComplexArrayVector.Builder result = new ComplexArrayVector.Builder(); result.setAttribute(Symbols.NAMES, source.getNames()); if (source.length() > 0) { Complex prod = source.getElementAsComplex(0); result.add(prod);/*ww w . j a va 2 s.co m*/ for (int i = 1; i < source.length(); i++) { if (ComplexVector.isNA(prod)) { result.add(ComplexVector.NA); } else { prod = prod.multiply(source.getElementAsComplex(i)); result.add(prod); } } } return result.build(); }
From source file:pl.dp.bz.poid.fouriertest.FourierProc.java
private Complex[] computeDIFForOneDimension(Complex[] pixelTable) { int bits = 9; double N = pixelTable.length; Complex[] transformedSignal = new Complex[(int) N]; for (int i = 0; i < transformedSignal.length; i++) { transformedSignal[i] = new Complex(0.0, 0.0); }//from w w w. java2s .c o m Complex signalTab[] = new Complex[(int) N]; Complex[] localTR = new Complex[(int) N]; int index = 0; for (int i = 0; i < pixelTable.length; i++) { signalTab[index] = new Complex(pixelTable[i].getReal(), pixelTable[i].getImaginary()); index++; } index = 0; for (Complex cv : signalTab) { // System.out.println("x(" + index + ") = " + cv.getReal() + " IM: i" + cv.getImaginary()); index++; } //Zmienna okrelajca na jakiej wielkoci ma operowa na tablicy int part = 2; //Ptla okrelajca cykl przechodzenia, przez kolejne kolumny for (int iteration = 1; iteration <= bits; iteration++) { // System.out.println("PART "+part); //Ile razy ma si wykona for (int i = 0; i < part; i += 2) { int r = 0; for (int actualIndex = (signalTab.length / part) * i, counter = 0; counter < signalTab.length / part; counter++, actualIndex++) { int secondIndex = (actualIndex + (signalTab.length / part)); Complex a = signalTab[actualIndex].add(signalTab[secondIndex]); Complex b = signalTab[actualIndex].subtract(signalTab[secondIndex]); Complex W = new Complex(Math.cos((2.0 * Math.PI * r) / N), -Math.sin((2.0 * Math.PI * r) / N)); b = b.multiply(W); signalTab[actualIndex] = a; signalTab[secondIndex] = b; r += part - (part / 2); } } part += part; } localTR[0] = signalTab[0]; localTR[localTR.length - 1] = signalTab[signalTab.length - 1]; for (int i = 1; i < signalTab.length - 1; i++) { String bitIndex = Integer.toBinaryString(i); if (bitIndex.length() < bits) { while (bitIndex.length() < bits) { bitIndex = "0" + bitIndex; } } char[] tab = bitIndex.toCharArray(); for (int j = 0; j < tab.length / 2; j++) { char temp = tab[j]; tab[j] = tab[tab.length - j - 1]; tab[tab.length - j - 1] = temp; } bitIndex = new String(tab); localTR[Integer.parseInt(bitIndex, 2)] = signalTab[i]; } for (int i = 0; i < localTR.length; i++) { transformedSignal[i] = new Complex(localTR[i].getReal(), localTR[i].getImaginary()); } return transformedSignal; }