List of usage examples for org.apache.commons.math3.complex Complex Complex
public Complex(double real, double imaginary)
From source file:com.fpuna.preproceso.TestApacheMathLibDemo.java
/** * @param args//from w w w .j a va2 s . com */ public static void main(String[] args) { RandomGenerator randomGenerator = new JDKRandomGenerator(); System.out.println(randomGenerator.nextInt()); System.out.println(randomGenerator.nextDouble()); /** * Descriptive Statistics like MEAN,GP,SD,MAX * */ DescriptiveStatistics stats = new DescriptiveStatistics(); stats.addValue(1); stats.addValue(2); stats.addValue(3); stats.addValue(4); stats.addValue(5); stats.addValue(6); stats.addValue(7); System.out.print("Mean : " + stats.getMean() + "\n"); System.out.print("Standard deviation : " + stats.getStandardDeviation() + "\n"); System.out.print("Max : " + stats.getMax() + "\n"); /** * Complex number format a+bi * */ Complex c1 = new Complex(1, 2); Complex c2 = new Complex(2, 3); System.out.print("Absolute of c1 " + c1.abs() + "\n"); System.out.print("Addition : " + (c1.add(c2)) + "\n"); }
From source file:com.hurence.tmp.FFT.java
/** * ******************************************************************* * Test client and sample execution/* w ww . j ava2 s . c o m*/ * * % java FFT 4 x ------------------- -0.03480425839330703 * 0.07910192950176387 0.7233322451735928 0.1659819820667019 * * y = fft(x) ------------------- 0.9336118983487516 -0.7581365035668999 + * 0.08688005256493803i 0.44344407521182005 -0.7581365035668999 - * 0.08688005256493803i * * z = ifft(y) ------------------- -0.03480425839330703 0.07910192950176387 * + 2.6599344570851287E-18i 0.7233322451735928 0.1659819820667019 - * 2.6599344570851287E-18i * * c = cconvolve(x, x) ------------------- 0.5506798633981853 * 0.23461407150576394 - 4.033186818023279E-18i -0.016542951108772352 * 0.10288019294318276 + 4.033186818023279E-18i * * d = convolve(x, x) ------------------- 0.001211336402308083 - * 3.122502256758253E-17i -0.005506167987577068 - 5.058885073636224E-17i * -0.044092969479563274 + 2.1934338938072244E-18i 0.10288019294318276 - * 3.6147323062478115E-17i 0.5494685269958772 + 3.122502256758253E-17i * 0.240120239493341 + 4.655566391833896E-17i 0.02755001837079092 - * 2.1934338938072244E-18i 4.01805098805014E-17i * ******************************************************************** */ public static void main(String[] args) { int N = 4; //Integer.parseInt(args[0]); Complex[] x = new Complex[N]; // original data for (int i = 0; i < N; i++) { x[i] = new Complex(i, 0); x[i] = new Complex(-2 * Math.random() + 1, 0); } show(x, "x"); // FFT of original data Complex[] y = fft(x); show(y, "y = fft(x)"); // take inverse FFT Complex[] z = ifft(y); show(z, "z = ifft(y)"); // circular convolution of x with itself Complex[] c = cconvolve(x, x); show(c, "c = cconvolve(x, x)"); // linear convolution of x with itself Complex[] d = convolve(x, x); show(d, "d = convolve(x, x)"); }
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/* w w w . j a v a2 s . c om*/ * @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:eu.itesla_project.iidm.ddb.eurostag.model.TransformerModel.java
public TransformerModel(float r, float x, float g, float b, float ratio) { this.z = new Complex(r, x); // z=r+jx this.y = new Complex(g, b); // y=g+jb this.ratio = ratio; }
From source file:eu.itesla_project.iidm.ddb.eurostag.model.TransformerModel.java
public StateVariable toSv2(StateVariable sv1) { Complex s1 = new Complex(-sv1.p, -sv1.q); // s1=p1+jq1 Complex u1 = ComplexUtils.polar2Complex(sv1.u, Math.toRadians(sv1.theta)); Complex v1 = u1.divide(SQUARE_3); // v1=u1/sqrt(3) Complex v1p = v1.multiply(ratio); // v1p=v1*rho Complex i1 = s1.divide(v1.multiply(3)).conjugate(); // i1=conj(s1/(3*v1)) Complex i1p = i1.divide(ratio); // i1p=i1/rho Complex i2 = i1p.subtract(y.multiply(v1p)).negate(); // i2=-(i1p-y*v1p) Complex v2 = v1p.subtract(z.multiply(i2)); // v2=v1p-z*i2 Complex s2 = v2.multiply(3).multiply(i2.conjugate()); // s2=3*v2*conj(i2) Complex u2 = v2.multiply(SQUARE_3);// w ww.j a va 2 s . c o m return new StateVariable(-s2.getReal(), -s2.getImaginary(), u2.abs(), Math.toDegrees(u2.getArgument())); }
From source file:ch.epfl.leb.sass.models.samples.internal.UniformRefractiveIndexTest.java
@Before public void setUp() { expResult = new Complex(1.0, 0.5); refractiveIndex = new UniformRefractiveIndex(expResult); }
From source file:net.sf.dsp4j.octave_3_2_4.Eig.java
public static Complex[] eig(RealMatrix d) { EigenDecomposition eig = new EigenDecomposition(d); double[] realEigenvalues = eig.getRealEigenvalues(); double[] imagEigenvalues = eig.getImagEigenvalues(); final Complex[] result = new Complex[realEigenvalues.length]; for (int i = 0; i < realEigenvalues.length; i++) { result[i] = new Complex(realEigenvalues[i], imagEigenvalues[i]); }/*from www. j av a 2 s.co m*/ return result; }
From source file:com.hurence.tmp.FFT.java
public static Complex[] fft(Complex[] x) { int N = x.length; // base case//from w w w. j a va2 s .c o m 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.interpss.pssl.test.aclf.AclfNet_Test.java
@Test public void singlePointTest1() { AclfNetworkDSL netDsl = IpssAclfNet.createAclfNetwork("Sample DistNetwork"); netDsl.baseMva(100.0);/* w w w . jav a 2 s.c om*/ netDsl.addAclfBus("Bus1", "name-Bus 1").baseVoltage(4000.0).genCode(AclfGenCode.SWING).voltageSpec(1.0, UnitType.PU, 0.0, UnitType.Deg); netDsl.addAclfBus("Bus2", "name-Bus 2").baseVoltage(4000.0).loadCode(AclfLoadCode.CONST_P) .load(new Complex(1.0, 0.8), UnitType.PU); netDsl.addAclfBranch("Bus1", "Bus2").branchCode(AclfBranchCode.LINE).z(new Complex(0.05, 0.1), UnitType.PU); IpssAclf.createAclfAlgo(netDsl.getAclfNet()).lfMethod(AclfMethod.NR).tolerance(0.0001, UnitType.PU) .runLoadflow(); System.out.println(AclfOutFunc.loadFlowSummary(netDsl.getAclfNet())); }
From source file:com.wwidesigner.geometry.calculation.Tube.java
/** * Calculate the impedance of an unflanged open end of a real pipe. * From F. Silva, Ph. Guillemain, J. Kergomard, B. Mallaroni, A. N. Norris, * "Approximation formulae for the acoustic radiation impedance of a cylindrical pipe," * arXiv:0811.3625v1 [physics.class-ph] 21 Nov 2008. * /*from w ww. jav a2 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 calcZload(double freq, double radius, PhysicalParameters params) { double ka = params.calcWaveNumber(freq) * radius; double ka2 = ka * ka; double z0_denominator = params.calcZ0(radius) / (1.0 + ka2 * (0.1514 + 0.05221 * ka2)); return new Complex(ka2 * (0.2499 + 0.05221 * ka2) * z0_denominator, ka * (0.6133 + 0.0381 * ka2) * z0_denominator); }