List of usage examples for org.apache.commons.math3.complex Complex multiply
public Complex multiply(double factor)
From source file:mandelbrot.MainDraw.java
public static Complex mandelFunction(Complex z, Complex c) { Complex zz = z.multiply(z); return (c.add(zz)); }
From source file:com.thalespf.dip.DeblurringTest.java
private static Complex deconvolutionByWiener(Complex imagem, Complex psf) { double K = Math.pow(1.07, 32) / 10000.0; double energyValue = Math.pow(psf.getReal(), 2) + Math.pow(psf.getImaginary(), 2); double wienerValue = energyValue / (energyValue + K); Complex divided = imagem.divide(psf); Complex c = divided.multiply(wienerValue); return c;/*from w ww.j a v a 2 s . co m*/ }
From source file:com.hurence.tmp.FFT.java
public static Complex[] fft(Complex[] x) { int N = x.length; // base case/*from ww w . jav a2 s . com*/ if (N == 1) { return new Complex[] { x[0] }; } // radix 2 Cooley-Tukey FFT if (N % 2 != 0) { throw new RuntimeException("N is not a power of 2"); } // fft of even terms Complex[] even = new Complex[N / 2]; for (int k = 0; k < N / 2; k++) { even[k] = x[2 * k]; } Complex[] q = fft(even); // fft of odd terms Complex[] odd = even; // reuse the array for (int k = 0; k < N / 2; k++) { odd[k] = x[2 * k + 1]; } Complex[] r = fft(odd); // combine Complex[] y = new Complex[N]; for (int k = 0; k < N / 2; k++) { double kth = -2 * k * Math.PI / N; Complex wk = new Complex(Math.cos(kth), Math.sin(kth)); y[k] = q[k].add(wk.multiply(r[k])); y[k + N / 2] = q[k].subtract(wk.multiply(r[k])); } return y; }
From source file:com.wwidesigner.geometry.calculation.Tube.java
/** * Calculate the transfer matrix of a cylinder. * @param waveNumber - 2*pi*f/c, in radians per metre * @param length - length of the cylinder, in metres. * @param radius - radius of the cylinder, in metres. * @param params - physical parameters//from ww w. j a v a 2 s . com * @return Transfer matrix */ public static TransferMatrix calcCylinderMatrix(double waveNumber, double length, double radius, PhysicalParameters params) { double Zc = params.calcZ0(radius); double epsilon = params.getAlphaConstant() / (radius * FastMath.sqrt(waveNumber)); Complex gammaL = new Complex(epsilon, 1.0 + epsilon).multiply(waveNumber * length); Complex coshL = gammaL.cosh(); Complex sinhL = gammaL.sinh(); TransferMatrix result = new TransferMatrix(coshL, sinhL.multiply(Zc), sinhL.divide(Zc), coshL); return result; }
From source file:edu.ucsf.valelab.saim.calculations.SaimCalc.java
/** * Calculates the transverse electric (TE) component, perpendicular to the * plane of incidence, of the Fresnel coefficient of reflection between the * sample interface and the virtual silicon oxidesilicon layer, * as described in://ww w.java 2 s . c om * Paszek, M.J., C.C. DuFort, M.G. Rubashkin, M.W. Davidson, K.S. Thorn, J.T. * Liphardt, and V.M. Weaver. 2012. * Scanning angle interference microscopy reveals cell dynamics at the nanoscale. * Nat Meth. 9:825827. doi:10.1038/nmeth.2077. * * * 1/11/2016: Note that the above manuscript contains a mistake that is corrected * in a later publication: http://dx.doi.org/10.1016/B978-0-12-420138-5.00013-6 * That correction is now applied. * * * @param wavelength of the excitation light source in nm * @param angle with respect to the normal in radiance * @param dOx Thickness of the Silicon Oxide layer in nm * @param nSample Refractive index of the sample's buffer * @return FresnelCoefficient for these conditions */ public static Complex fresnelTE(final double wavelength, final double angle, final double dOx, final double nSample) { double nSi = RI.getRI(RI.Compound.SILICON, wavelength); double nOx = RI.getRI(RI.Compound.SILICONOXIDE, wavelength); double kOx = k(wavelength, nOx); double angleOx = snell2(angle, nSample, RI.getRI(RI.Compound.SILICONOXIDE, wavelength)); double cosOx = Math.cos(angleOx); double cosSi = Math.cos(snell2(angleOx, nOx, RI.getRI(RI.Compound.SILICON, wavelength))); double p0 = nSi * cosSi; double p1 = nOx * cosOx; double p2 = nSample * Math.cos(angle); double kOxdOxCosOx = kOx * dOx * cosOx; double cosOfkOxdOxCosOx = Math.cos(kOxdOxCosOx); double sinOfkOxdOxCosOx = Math.sin(kOxdOxCosOx); double m11TE = cosOfkOxdOxCosOx; Complex m12TE = Complex.I.multiply(-1 / p1 * sinOfkOxdOxCosOx); Complex m21TE = Complex.I.multiply(-p1 * sinOfkOxdOxCosOx); double m22TE = cosOfkOxdOxCosOx; Complex tmp1 = ((m12TE.multiply(p0)).add(m11TE)).multiply(p2); // this is the only line changed due to the error in the NM paper Complex tmp2 = tmp1.subtract(m21TE.add(m22TE * p0)); //Complex tmp2 = tmp1.add( m21TE.subtract(m22TE * p0) ); Complex tmp3 = tmp1.add(m21TE.add(m22TE * p0)); Complex rTE = tmp2.divide(tmp3); return rTE; }
From source file:com.wwidesigner.geometry.calculation.Tube.java
/** * Calculate the impedance of an unflanged open end of a real pipe. * @param freq - fundamental frequency of the waveform. * @param radius - radius of pipe, in metres. * @param params - physical parameters//from w w w . ja va 2 s . c o m * @return impedance as seen by pipe. */ public static Complex calcZload_old(double freq, double radius, PhysicalParameters params) { Complex zRel = new Complex(9.87 * freq * radius / params.getSpeedOfSound(), 3.84) .multiply(freq * radius / params.getSpeedOfSound()); return zRel.multiply(params.calcZ0(radius)); }
From source file:com.wwidesigner.geometry.calculation.Tube.java
/** * Calculate the impedance of an open end of a real pipe, * assuming an infinite flange.// w w w . j a v a 2 s.c o m * @param freq - fundamental frequency of the waveform. * @param radius - radius of pipe, in metres. * @param params - physical parameters * @return impedance as seen by pipe. */ public static Complex calcZflanged_old(double freq, double radius, PhysicalParameters params) { Complex zRel = new Complex(19.7 * freq * radius / params.getSpeedOfSound(), 5.33) .multiply(freq * radius / params.getSpeedOfSound()); return zRel.multiply(params.calcZ0(radius)); }
From source file:edu.ucsf.valelab.saim.calculations.SaimCalc.java
public static double fieldStrength(final double wavelength, final double angle, final double nSample, final double dOx, final double distance) { Complex rTE = fresnelTE(wavelength, angle, dOx, nSample); double phaseDiff = PhaseDiff(wavelength, angle, nSample, distance); Complex tmp = new Complex(Math.cos(phaseDiff), Math.sin(phaseDiff)); Complex fieldStrength = rTE.multiply(tmp); fieldStrength = fieldStrength.add(1.0); return fieldStrength.getReal() * fieldStrength.getReal() + fieldStrength.getImaginary() * fieldStrength.getImaginary(); }
From source file:bb.mcmc.analysis.ConvergeStatUtils.java
private static double calSpectrum0(double[] newData) { final int N = newData.length; final int Nfreq = (int) Math.floor(N / 2); final double oneOverN = 1.0 / N; double[] freq = new double[Nfreq]; double[] f1 = new double[Nfreq]; for (int i = 0; i < Nfreq; i++) { freq[i] = oneOverN * (i + 1);/*from w w w . j av a 2s . com*/ f1[i] = SQRT3 * (4 * freq[i] - 1); } double[] complexArray = ConvergeStatUtils.realToComplexArray(newData); double[] spec = new double[N]; DoubleFFT_1D fft = new DoubleFFT_1D(N); fft.complexForward(complexArray); for (int i = 0; i < N; i++) { Complex complexData = new Complex(complexArray[i * 2], complexArray[i * 2 + 1]); complexData = complexData.multiply(complexData.conjugate()); spec[i] = complexData.getReal() / N; } spec = Arrays.copyOfRange(spec, 1, f1.length + 1); double[] coefficients = gammaGLM.coefficients(spec, f1); double v = Math.exp(coefficients[0] + coefficients[1] * -SQRT3); return v; }
From source file:com.wwidesigner.geometry.calculation.Tube.java
/** * Calculate the transfer matrix of a conical tube. * @param waveNumber - 2*pi*f/c, in radians per metre * @param length - length of the tube, in metres. * @param sourceRadius - radius of source end the tube, in metres. * @param loadRadius - radius of load end the tube, in metres. * @param params - physical parameters//from w w w . j a v a 2s . c o m * @return Transfer matrix */ public static TransferMatrix calcConeMatrix(double waveNumber, double length, double sourceRadius, double loadRadius, PhysicalParameters params) { // From: Antoine Lefebvre and Jean Kergomard. if (sourceRadius == loadRadius) { return calcCylinderMatrix(waveNumber, length, sourceRadius, params); } // Mean complex wave vector along the whole cone, from Lefebvre and Kergomard. double alpha_0 = params.getAlphaConstant() / FastMath.sqrt(waveNumber); double epsilon; if (FastMath.abs(loadRadius - sourceRadius) <= 0.00001 * sourceRadius) { // Use limiting value as loadRadius approaches sourceRadius. epsilon = alpha_0 / loadRadius; } else { epsilon = alpha_0 / (loadRadius - sourceRadius) * FastMath.log(loadRadius / sourceRadius); } Complex mean = new Complex(1.0 + epsilon, -epsilon); Complex kMeanL; if (length >= MINIMUM_CONE_LENGTH) { kMeanL = mean.multiply(waveNumber * length); } else { // Limit how short the cone can be. // Length of zero leads to a divide-by-zero below. kMeanL = mean.multiply(waveNumber * MINIMUM_CONE_LENGTH); } // Cotangents of theta_in and theta_out. Complex cot_in = new Complex((loadRadius - sourceRadius) / sourceRadius).divide(kMeanL); Complex cot_out = new Complex((loadRadius - sourceRadius) / loadRadius).divide(kMeanL); // sine and cosine of kMean * L. Complex sin_kL = kMeanL.sin(); Complex cos_kL = kMeanL.cos(); Complex A = cos_kL.multiply(loadRadius / sourceRadius).subtract(sin_kL.multiply(cot_in)); Complex B = Complex.I.multiply(sin_kL).multiply(params.calcZ0(loadRadius) * (loadRadius / sourceRadius)); Complex C = Complex.I.multiply(loadRadius / (sourceRadius * params.calcZ0(sourceRadius))).multiply( sin_kL.multiply(cot_out.multiply(cot_in).add(1.0)).add(cos_kL.multiply(cot_out.subtract(cot_in)))); Complex D = cos_kL.multiply(sourceRadius / loadRadius).add(sin_kL.multiply(cot_out)); TransferMatrix tm = new TransferMatrix(A, B, C, D); // assert tm.determinant() == Complex.valueOf(1.0,0.0); return tm; }