List of usage examples for org.apache.commons.math3.complex Complex I
Complex I
To view the source code for org.apache.commons.math3.complex Complex I.
Click Source Link
From source file:com.wwidesigner.geometry.calculation.DefaultHoleCalculator.java
public TransferMatrix calcTransferMatrix_2010(Hole hole, boolean isOpen, double waveNumber, PhysicalParameters parameters) { double radius = mFudgeFactor * hole.getDiameter() / 2; double boreRadius = hole.getBoreDiameter() / 2; Complex Zs = null;//w w w . ja v a 2s.c o m Complex Za = null; // double Z0 = parameters.calcZ0(boreRadius); double Z0h = parameters.calcZ0(radius); double delta = radius / boreRadius; double tm = (radius * delta / 8.) * (1. + 0.207 * delta * delta * delta); double te = hole.getHeight() + tm; double ta = 0.; // Complex Gamma = Complex.I.multiply(wave_number); if (isOpen) // open { double kb = waveNumber * radius; double ka = waveNumber * boreRadius; double xhi = 0.25 * kb * kb; ta = (-0.35 + 0.06 * Math.tanh(2.7 * hole.getHeight() / radius)) * radius * delta * delta * delta * delta; Complex Zr = Complex.I.multiply(waveNumber * 0.61 * radius).add(xhi); Complex Zo = (Zr.multiply(Math.cos(waveNumber * te)).add(Complex.I.multiply(Math.sin(waveNumber * te)))) .divide(Complex.I.multiply(Zr).multiply(Math.sin(waveNumber * te)) .add(Math.cos(waveNumber * te))); double ti = radius * (0.822 - 0.10 * delta - 1.57 * delta * delta + 2.14 * delta * delta * delta - 1.6 * delta * delta * delta * delta + 0.50 * delta * delta * delta * delta * delta) * (1. + (1. - 4.56 * delta + 6.55 * delta * delta) * (0.17 * ka + 0.92 * ka * ka + 0.16 * ka * ka * ka - 0.29 * ka * ka * ka * ka)); Zs = Complex.I.multiply(waveNumber * ti).add(Zo).multiply(Z0h); } else { ta = (-0.12 - 0.17 * Math.tanh(2.4 * hole.getHeight() / radius)) * radius * delta * delta * delta * delta; Zs = Complex.valueOf(0, -Z0h / Math.tan(waveNumber * te)); } Za = Complex.I.multiply(Z0h * waveNumber * ta); Complex Za_Zs = Za.divide(Zs); TransferMatrix result = new TransferMatrix(Za_Zs.divide(2.).add(1.), Za.multiply(Za_Zs.divide(4.).add(1.)), Complex.ONE.divide(Zs), Za_Zs.divide(2.0).add(1.)); assert result.determinant() == Complex.ONE; 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://from w w w .j av a 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.DefaultHoleCalculator.java
@Override public TransferMatrix calcTransferMatrix(Hole hole, boolean isOpen, double waveNumber, PhysicalParameters parameters) { double radius = mFudgeFactor * hole.getDiameter() / 2; double boreRadius = hole.getBoreDiameter() / 2; Complex Ys = Complex.ZERO; // Shunt admittance == 1/Zs Complex Za = Complex.ZERO; // Series impedance double Z0h = parameters.calcZ0(radius); double delta = radius / boreRadius; double delta2 = delta * delta; // double Z0 = parameters.calcZ0(boreRadius); // Z0 == Z0h * delta*delta double tm = (radius * delta / 8.) * (1. + 0.207 * delta * delta2); double te = hole.getHeight() + tm; double ta = 0.; // Complex Gamma = Complex.I.multiply(wave_number); if (isOpen) { double kb = waveNumber * radius; double ka = waveNumber * boreRadius; ta = (-0.35 + 0.06 * FastMath.tanh(2.7 * hole.getHeight() / radius)) * radius * delta2; Complex Zr = new Complex(0.25 * kb * kb, (0.822 - 0.47 * FastMath.pow(radius / (boreRadius + hole.getHeight()), 0.8)) * waveNumber * radius);// w w w . j av a 2 s .co m double cos = FastMath.cos(waveNumber * te); Complex jsin = new Complex(0, FastMath.sin(waveNumber * te)); Complex Zo = (Zr.multiply(cos).add(jsin)).divide(Zr.multiply(jsin).add(cos)); double ti = radius * (0.822 + delta * (-0.095 + delta * (-1.566 + delta * (2.138 + delta * (-1.640 + delta * 0.502))))) * (1. + (1. - 4.56 * delta + 6.55 * delta2) * ka * (0.17 + ka * (0.92 + ka * (0.16 - 0.29 * ka)))); Ys = Complex.ONE.divide(Complex.I.multiply(waveNumber * ti).add(Zo).multiply(Z0h)); } else if (hole.getKey() == null) { // Tonehole closed by player's finger. if (hole.getHeight() <= AssumedFingerSize) { // Finger is likely to fill the hole. Ignore the hole entirely. ta = 0.; Ys = Complex.ZERO; } else { ta = (-0.12 - 0.17 * FastMath.tanh(2.4 * (hole.getHeight() - AssumedFingerSize) / radius)) * radius * delta2; Ys = Complex.valueOf(0, FastMath.tan(waveNumber * (te - AssumedFingerSize)) / Z0h); } } else { // Tonehole closed by key. ta = (-0.12 - 0.17 * FastMath.tanh(2.4 * hole.getHeight() / radius)) * radius * delta2; Ys = Complex.valueOf(0, FastMath.tan(waveNumber * te) / Z0h); } Za = Complex.I.multiply(Z0h * delta2 * waveNumber * ta); Complex Za_Zs = Za.multiply(Ys); Complex A = Za_Zs.divide(2.).add(1.); Complex B = Za.multiply(Za_Zs.divide(4.).add(1.)); Complex C = Ys; // Choose A and D to make the determinant = 1. // Complex A = Complex.ONE.add(B.multiply(C)).sqrt(); TransferMatrix result = new TransferMatrix(A, B, C, A); // assert result.determinant() == Complex.ONE; return result; }
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 2 s . c om * @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; }
From source file:com.wwidesigner.util.PhysicalParameters.java
/** * Compute the complex wave vector, allowing for losses. * @param waveNumber : non-lossy wave number, in radians/meter * @param radius : tube radius, in m/* w w w. ja v a2 s. c o m*/ * @return omega/v - j * alpha */ public Complex getComplexWaveNumber(double waveNumber, double radius) { double alpha = (1 / radius) * Math.sqrt(waveNumber) * mAlphaConstant; return Complex.I.multiply(waveNumber).add(Complex.valueOf(1, 1).multiply(alpha)); }
From source file:org.briljantframework.data.dataframe.MixedDataFrameTest.java
@Test public void testBuilderAddColumn() throws Exception { DataFrame.Builder builder = getBuilder(); builder.add(Vector.of((Object[]) "1 2 3 4 5".split(" "))); builder.add(Vector.of(1, 2, 3, 4, 5)); builder.add(Vector.of(1.0, 2, 3, 4, 5)); builder.add(Vector.of(Complex.I, Complex.I, Complex.I, Complex.I, Complex.I)); builder.add(Vector.of(true, true, false, false, false)); DataFrame build = builder.build();/*from w w w.j a v a 2 s .co m*/ // assertEquals(VectorType.STRING, build.getTypeAt(0)); // assertEquals(VectorType.INT, build.getTypeAt(1)); // assertEquals(VectorType.DOUBLE, build.getTypeAt(2)); // assertEquals(VectorType.COMPLEX, build.getTypeAt(3)); // assertEquals(VectorType.LOGICAL, build.getTypeAt(4)); assertEquals(1, build.loc().getAsInt(0, 1)); assertEquals(1, build.loc().getAsDouble(0, 2), 0); assertEquals(Complex.I, build.loc().get(Complex.class, 0, 3)); assertEquals(Logical.TRUE, build.loc().get(Logical.class, 0, 4)); // assertEquals(Convert.toValue(1), build.getAsValue(0, 5)); }
From source file:org.briljantframework.data.dataframe.MixedDataFrameTest.java
@Test public void testBuilderAddBuilder() throws Exception { DataFrame.Builder builder = getBuilder(); builder.add(VectorType.STRING);//from ww w . ja v a2s.com builder.add(VectorType.INT); builder.add(VectorType.DOUBLE); builder.add(VectorType.COMPLEX); builder.add(VectorType.LOGICAL); builder.add(VectorType.OBJECT); builder.loc().set(0, 0, "hello"); builder.loc().set(0, 1, 1); builder.loc().set(0, 2, 2); builder.loc().set(0, 3, Complex.I); builder.loc().set(0, 4, true); builder.loc().set(0, 5, new Date()); DataFrame df = builder.build(); // assertEquals(VectorType.STRING, df.getTypeAt(0)); // assertEquals(VectorType.INT, df.getTypeAt(1)); assertEquals(1, df.loc().getAsInt(0, 1)); // assertEquals(VectorType.DOUBLE, df.getTypeAt(2)); assertEquals(2, df.loc().getAsDouble(0, 2), 0); // assertEquals(VectorType.COMPLEX, df.getTypeAt(3)); assertEquals(Complex.I, df.loc().get(Complex.class, 0, 3)); // assertEquals(VectorType.LOGICAL, df.getTypeAt(4)); assertEquals(Logical.TRUE, df.loc().get(Logical.class, 0, 4)); // assertEquals(VectorType.OBJECT, df.getTypeAt(5)); }
From source file:org.briljantframework.data.dataframe.MixedDataFrameTest.java
@Test public void testBuilderAddBuilder1() throws Exception { DataFrame.Builder builder = getBuilder(); builder.add(VectorType.STRING.newBuilder()); builder.add(VectorType.INT.newBuilder()); builder.add(VectorType.DOUBLE.newBuilder()); builder.add(VectorType.COMPLEX.newBuilder()); builder.add(VectorType.LOGICAL.newBuilder()); builder.add(VectorType.OBJECT.newBuilder()); builder.add(VectorType.of(Date.class).newBuilder()); builder.loc().set(0, 0, "hello"); builder.loc().set(0, 1, 1);//from w ww .j av a 2 s. c o m builder.loc().set(0, 2, 2); builder.loc().set(0, 3, Complex.I); builder.loc().set(0, 4, true); builder.loc().set(0, 5, "dsadsA"); builder.loc().set(0, 6, new Date(321321321738L)); builder.loc().set(1, 6, 1232L); builder.loc().set(2, 6, "2015-03-15"); DataFrame build = builder.build(); // assertEquals(VectorType.STRING, build.getTypeAt(0)); // assertEquals(VectorType.INT, build.getTypeAt(1)); assertEquals(1, build.loc().getAsInt(0, 1)); // assertEquals(VectorType.DOUBLE, build.getTypeAt(2)); assertEquals(2, build.loc().getAsDouble(0, 2), 0); // assertEquals(VectorType.COMPLEX, build.getTypeAt(3)); assertEquals(Complex.I, build.loc().get(Complex.class, 0, 3)); // assertEquals(VectorType.LOGICAL, build.getTypeAt(4)); assertEquals(Logical.TRUE, build.loc().get(Logical.class, 0, 4)); // assertEquals(VectorType.OBJECT, build.getTypeAt(5)); // assertEquals(VectorType.from(Date.class), build.getTypeAt(6)); assertEquals(new Date(321321321738L), build.loc().get(6).loc().get(Date.class, 0)); assertEquals(1, (int) build.loc().get(Integer.class, 0, 1)); }
From source file:org.xlrnet.tibaija.processor.FullTIBasicVisitor.java
@Override public Value visitExpression_postfix(@NotNull TIBasicParser.Expression_postfixContext ctx) { List<String> operators = ctx.operators; if (ctx.expression_preeval() != null) { // Run regular right-associative postfix logic without imaginary parts Value expressionValue = (Value) ctx.expression_preeval().accept(this); for (String op : operators) expressionValue = environment.runRegisteredExpressionFunction(op, expressionValue).get(); return expressionValue; } else {// w w w. j a v a2s . com // Run imaginary logic -> e.g. ii == i(i) int imaginaryCount = ctx.IMAGINARY().size() - 1; Value lhs = Value.of(Complex.I); LOGGER.debug("(IMAGINARY) -> {}", lhs.complex()); for (String op : operators) { if (imaginaryCount >= 0) { lhs = environment.runRegisteredExpressionFunction(op, lhs).get(); if (imaginaryCount > 0) { Value before = lhs; lhs = Value.of(lhs.complex().multiply(Complex.I)); LOGGER.debug("(MULTIPLY) {} (IMAGINARY) -> {}", before.complex(), lhs.complex()); imaginaryCount--; } } } // Multiply value with all left I if (imaginaryCount > 0) { final Complex factor = TIMathUtils.imaginaryNthPower(imaginaryCount); final Value before = lhs; lhs = Value.of(lhs.complex().multiply(factor)); LOGGER.debug("(MULTIPLY) {} {} -> {}", before.complex(), factor, lhs.complex()); } return lhs; } }
From source file:org.xlrnet.tibaija.util.TIMathUtils.java
/** * Calculates the n-th power of i./*from w w w . ja v a 2 s. c om*/ * I.e.: i^0 = 1; i^1 = i i^2 = -1 * * @param imaginaryCount * The power with which i should be multiplied. Must be greater or equal to zero. * @return The n-th power of i. */ @NotNull public static Complex imaginaryNthPower(int imaginaryCount) throws TIArgumentException { if (imaginaryCount < 0) throw new TIArgumentException("Power must be zero or greater", imaginaryCount); if (imaginaryCount == 0) return Complex.ONE; else return Complex.I.multiply(imaginaryNthPower(imaginaryCount - 1)); }