Example usage for org.apache.commons.math3.complex Complex Complex

List of usage examples for org.apache.commons.math3.complex Complex Complex

Introduction

In this page you can find the example usage for org.apache.commons.math3.complex Complex Complex.

Prototype

public Complex(double real) 

Source Link

Document

Create a complex number given only the real part.

Usage

From source file:ch.epfl.leb.sass.models.illuminations.internal.SquareUniformElectricFieldTest.java

/**
 * Test of getEx method, of class SquareUniformElectricField.
 *///from   w  w w. j a  v  a2s .co  m
@Test
public void testGetEx() {
    System.out.println("testGetEx");
    SquareUniformElectricField instance = builder.build();

    // Inside the illumination area
    when(dummyRefractiveIndex.getN(10, 20, 0)).thenReturn(new Complex(1.0));
    Complex result = instance.getEx(10, 20, 0);
    assertEquals(1, result.getReal(), 0.0);
    assertEquals(0, result.getImaginary(), 0.0);

    // Inside the illumination area, different z-position
    Complex expResult = ComplexUtils.polar2Complex(orientation.getX(), MathUtils.TWO_PI / wavelength * 1.0);

    when(dummyRefractiveIndex.getN(10, 20, 1)).thenReturn(new Complex(1.0));
    result = instance.getEx(10, 20, 1);
    assertEquals(expResult.getReal(), result.getReal(), 0.0);
    assertEquals(expResult.getImaginary(), result.getImaginary(), 0.0);

    // Outside the illumination area
    when(dummyRefractiveIndex.getN(-10, 20, 10)).thenReturn(new Complex(1.0));
    result = instance.getEx(-10, 20, 10);
    assertEquals(0, result.getReal(), 0.0);
    assertEquals(0, result.getImaginary(), 0.0);

    // Outside the illumination area
    when(dummyRefractiveIndex.getN(30, 20, -10)).thenReturn(new Complex(1.0));
    result = instance.getEx(30, 20, -10);
    assertEquals(0, result.getReal(), 0.0);
    assertEquals(0, result.getImaginary(), 0.0);

    // Outside the illumination area
    when(dummyRefractiveIndex.getN(10, -10, 100)).thenReturn(new Complex(1.0));
    result = instance.getEx(10, -10, 100);
    assertEquals(0, result.getReal(), 0.0);
    assertEquals(0, result.getImaginary(), 0.0);

    // Outside the illumination area
    when(dummyRefractiveIndex.getN(10, 50, -100)).thenReturn(new Complex(1.0));
    result = instance.getEx(10, 50, -100);
    assertEquals(0, result.getReal(), 0.0);
    assertEquals(0, result.getImaginary(), 0.0);
}

From source file:ch.epfl.leb.sass.models.fluorophores.commands.internal.FluorophoreReceiverIT.java

@Before
public void setUp() {
    // Camera//from   ww w. j  a  va  2 s.  c  om
    DefaultCamera.Builder cameraBuilder = new DefaultCamera.Builder();

    cameraBuilder.nX(32); // Number of pixels in x
    cameraBuilder.nY(32); // Number of pixels in y
    cameraBuilder.readoutNoise(1.6); // Standard deviation, electrons
    cameraBuilder.darkCurrent(0.06);
    cameraBuilder.quantumEfficiency(0.8);
    cameraBuilder.aduPerElectron(2.2);
    cameraBuilder.emGain(0); // Set to zero for CMOS cameras
    cameraBuilder.baseline(100); // ADU
    cameraBuilder.pixelSize(6.45); // microns
    camera = cameraBuilder.build();

    // Illumination profile
    RefractiveIndex n = new UniformRefractiveIndex(new Complex(1.33));
    SquareUniformIllumination.Builder illumBuilder = new SquareUniformIllumination.Builder();
    illumBuilder.height(32 * 6.45 / 60); // microns
    illumBuilder.orientation(new Vector3D(1.0, 0, 0)); // x-polarized
    illumBuilder.power(1.0);
    illumBuilder.refractiveIndex(n);
    illumBuilder.wavelength(0.642);
    illumBuilder.width(32 * 6.45 / 60); // microns
    illumination = illumBuilder.build();

    // PSF, create a 2D Gaussian point-spread function
    psfBuilder = new Gaussian2D.Builder();
    psfBuilder.stageDisplacement(0).NA(1.3).FWHM(0.3).wavelength(0.68).resLateral(0.108);

    // Fluorophore dynamics and properties; rates are in units of 1/frames
    SimpleDynamics.Builder fluorPropBuilder = new SimpleDynamics.Builder();

    fluorPropBuilder.signal(2500); // Photons per fluorophore per frame
    fluorPropBuilder.wavelength(0.68); // Wavelength, microns
    fluorPropBuilder.tOn(3); // Mean on time
    fluorPropBuilder.tOff(100); // Mean off time
    fluorPropBuilder.tBl(10000); // Mean bleaching time
    fluorDynamics = fluorPropBuilder.build();
}

From source file:net.sf.dsp4j.octave.packages.signal_1_0_11.Bilinear.java

public Bilinear(Complex[] sZero, Complex[] sPole, double sGain, double T) {

    Complex _2 = new Complex(2);

    if (sZero.length > sPole.length || sPole.length == 0) {
        //    error("bilinear: must have at least as many poles as zeros in s-plane");
    }/*  w w w. j  a  v  a 2 s . c o m*/

    Complex[] bz = new Complex[sZero.length];
    for (int i = 0; i < sZero.length; i++) {
        bz[i] = _2.subtract(sZero[i].multiply(T)).divide(T);
    }
    Complex[] bp = new Complex[sPole.length];
    for (int i = 0; i < sPole.length; i++) {
        bp[i] = _2.subtract(sPole[i].multiply(T)).divide(T);
    }

    zGain = new Complex(sGain, 0).multiply(prod(bz).divide(prod(bp))).getReal();
    zPole = new Complex[sPole.length];
    for (int i = 0; i < sPole.length; i++) {
        zPole[i] = _2.add(sPole[i].multiply(T)).divide(_2.subtract(sPole[i].multiply(T)));
    }
    zZero = new Complex[sPole.length];
    if (sZero.length == 0) {
        Arrays.fill(zZero, Complex.ONE.negate());
    } else {
    }
    for (int i = 0; i < sZero.length; i++) {
        zZero[i] = _2.add(sZero[i].multiply(T)).divide(_2.subtract(sZero[i].multiply(T)));
    }
    if (sZero.length < zZero.length) {
        Arrays.fill(zZero, sZero.length, zZero.length, Complex.ONE.negate());
    }
}

From source file:ch.epfl.leb.sass.models.MicroscopeIT.java

/**
 * Sets up a basic Microscope for an acquisition simulation.
 *//*from   w  w  w  . j a  v a2 s .c  om*/
@Before
public void setUp() {
    if (setupIsDone) {
        // Skip setup if it has already run.
        return;
    }

    // The seed determines the outputs of the random number generator.
    RNG.setSeed(42);

    DefaultCamera.Builder cameraBuilder = new DefaultCamera.Builder();

    cameraBuilder.nX(32); // Number of pixels in x
    cameraBuilder.nY(32); // Number of pixels in y
    cameraBuilder.readoutNoise(1.6); // Standard deviation, electrons
    cameraBuilder.darkCurrent(0.06);
    cameraBuilder.quantumEfficiency(0.8);
    cameraBuilder.aduPerElectron(2.2);
    cameraBuilder.emGain(0); // Set to zero for CMOS cameras
    cameraBuilder.baseline(100); // ADU
    cameraBuilder.pixelSize(6.45); // microns
    cameraBuilder.thermalNoise(0.05); // electrons/frame/pixel

    // DefaultObjective
    DefaultObjective.Builder objectiveBuilder = new DefaultObjective.Builder();

    objectiveBuilder.NA(1.3); // Numerical aperture
    objectiveBuilder.mag(60); // Magnification

    // DefaultLaser
    DefaultLaser.Builder laserBuilder = new DefaultLaser.Builder();

    laserBuilder.currentPower(0.0);
    laserBuilder.minPower(0.0);
    laserBuilder.maxPower(500.0);
    laserBuilder.wavelength(0.642);

    // Illumination profile
    // TODO: Add illumination setup to the GUI
    RefractiveIndex n = new UniformRefractiveIndex(new Complex(1.33));
    SquareUniformIllumination.Builder illumBuilder = new SquareUniformIllumination.Builder();
    illumBuilder.height(32 * 6.45 / 60);
    illumBuilder.orientation(new Vector3D(1.0, 0, 0)); // x-polarized
    illumBuilder.refractiveIndex(n);
    illumBuilder.width(32 * 6.45 / 60);

    // DefaultStage
    DefaultStage.Builder stageBuilder = new DefaultStage.Builder();

    stageBuilder.x(0);
    stageBuilder.y(0);
    stageBuilder.z(0); // Coverslip surface is at z = 0

    // PSF, create a 2D Gaussian point-spread function
    Gaussian2D.Builder psfBuilder = new Gaussian2D.Builder();

    // Fluorophore dynamics and properties; rates are in units of 1/frames
    PalmDynamics.Builder fluorPropBuilder = new PalmDynamics.Builder();

    fluorPropBuilder.signal(2500); // Photons per fluorophore per frame
    fluorPropBuilder.wavelength(0.6); // Wavelength, microns
    fluorPropBuilder.kA(100); // Activation rate
    fluorPropBuilder.kB(0); // Bleaching rate
    fluorPropBuilder.kD1(0.065); // Transition rate to first dark state
    fluorPropBuilder.kD2(0.013); // Transition rate to second dark state
    fluorPropBuilder.kR1(0.004); // Return rate from first dark state
    fluorPropBuilder.kR2(0.157); // Return rate from second dark state

    // Fluorophore positions on a square grid
    GenerateFluorophoresGrid2D.Builder fluorPosBuilder = new GenerateFluorophoresGrid2D.Builder();
    fluorPosBuilder.spacing(4); // pixels

    // Add fiducials to the field of view at a random location
    GenerateFiducialsRandom2D.Builder fidBuilder = new GenerateFiducialsRandom2D.Builder();
    fidBuilder.numFiducials(2);
    fidBuilder.brightness(3000); // photons per frame

    // Add a constant background
    GenerateUniformBackground.Builder backgroundBuilder = new GenerateUniformBackground.Builder();
    backgroundBuilder.backgroundSignal(10); // photons

    // Assemble the microscope.
    microscope = new Microscope(cameraBuilder, laserBuilder, objectiveBuilder, psfBuilder, stageBuilder,
            fluorPosBuilder, fluorPropBuilder, fidBuilder, backgroundBuilder, illumBuilder);

    setupIsDone = true;
}

From source file:ch.epfl.leb.sass.models.illuminations.internal.SquareUniformElectricFieldTest.java

/**
 * Test of getEy method, of class SquareUniformElectricField.
 *///from  w  ww  .j  av a 2s . c  o  m
@Test
public void testGetEy() {
    System.out.println("testGetEy");
    SquareUniformElectricField instance = builder.build();

    // Inside the illumination area
    when(dummyRefractiveIndex.getN(10, 20, 0)).thenReturn(new Complex(1.0));
    Complex result = instance.getEy(10, 20, 0);
    assertEquals(0, result.getReal(), 0.0);
    assertEquals(0, result.getImaginary(), 0.0);

    // Outside the illumination area
    when(dummyRefractiveIndex.getN(-10, 20, 10)).thenReturn(new Complex(1.0));
    result = instance.getEy(-10, 20, 10);
    assertEquals(0, result.getReal(), 0.0);
    assertEquals(0, result.getImaginary(), 0.0);

    // Outside the illumination area
    when(dummyRefractiveIndex.getN(30, 20, -10)).thenReturn(new Complex(1.0));
    result = instance.getEy(30, 20, -10);
    assertEquals(0, result.getReal(), 0.0);
    assertEquals(0, result.getImaginary(), 0.0);

    // Outside the illumination area
    when(dummyRefractiveIndex.getN(10, -10, 100)).thenReturn(new Complex(1.0));
    result = instance.getEy(10, -10, 100);
    assertEquals(0, result.getReal(), 0.0);
    assertEquals(0, result.getImaginary(), 0.0);

    // Outside the illumination area
    when(dummyRefractiveIndex.getN(10, 50, -100)).thenReturn(new Complex(1.0));
    result = instance.getEy(10, 50, -100);
    assertEquals(0, result.getReal(), 0.0);
    assertEquals(0, result.getImaginary(), 0.0);
}

From source file:ch.epfl.leb.sass.models.illuminations.internal.SquareUniformElectricField.java

/**
* Returns the x-component of the time-independent electric field at the position (x, y, z).
* 
* @param x The x-position within the sample.
* @param y The y-position within the sample.
* @param z The z-position within the sample.
* @return The x-component of the electric field at the position (x, y, z).
*//*from w ww .  j av a2 s.  c  o m*/
@Override
public Complex getEx(double x, double y, double z) {
    if (x < 0 || x > width)
        return new Complex(0);
    if (y < 0 || y > height)
        return new Complex(0);

    Complex arg = getArgument(x, y, z);
    double magnitude = orientation.getX() * Math.exp(-arg.getImaginary());
    return ComplexUtils.polar2Complex(magnitude, arg.getReal());
}

From source file:ch.epfl.leb.sass.server.RPCServerIT.java

/**
 * Sets up two different Microscopes for acquisition simulations.
 *///from   ww  w  .j  a  va2  s  .c  o  m
@Before
public void setUp() throws InterruptedException {
    // The seed determines the outputs of the random number generator.
    RNG.setSeed(42);

    DefaultCamera.Builder cameraBuilder = new DefaultCamera.Builder();

    cameraBuilder.nX(32); // Number of pixels in x
    cameraBuilder.nY(32); // Number of pixels in y
    cameraBuilder.readoutNoise(1.6); // Standard deviation, electrons
    cameraBuilder.darkCurrent(0.06);
    cameraBuilder.quantumEfficiency(0.8);
    cameraBuilder.aduPerElectron(2.2);
    cameraBuilder.emGain(0); // Set to zero for CMOS cameras
    cameraBuilder.baseline(100); // ADU
    cameraBuilder.pixelSize(6.45); // microns
    cameraBuilder.thermalNoise(0.05); // electrons/frame/pixel

    // DefaultObjective
    DefaultObjective.Builder objectiveBuilder = new DefaultObjective.Builder();

    objectiveBuilder.NA(1.3); // Numerical aperture
    objectiveBuilder.mag(60); // Magnification

    // DefaultLaser
    DefaultLaser.Builder laserBuilder = new DefaultLaser.Builder();

    laserBuilder.currentPower(0.0);
    laserBuilder.minPower(0.0);
    laserBuilder.maxPower(500.0);
    laserBuilder.wavelength(0.642);

    // Illumination profile
    // TODO: Add illumination setup to the GUI
    RefractiveIndex n = new UniformRefractiveIndex(new Complex(1.33));
    SquareUniformIllumination.Builder illumBuilder = new SquareUniformIllumination.Builder();
    illumBuilder.height(32 * 6.45 / 60);
    illumBuilder.orientation(new Vector3D(1.0, 0, 0)); // x-polarized
    illumBuilder.refractiveIndex(n);
    illumBuilder.width(32 * 6.45 / 60);

    // DefaultStage
    DefaultStage.Builder stageBuilder = new DefaultStage.Builder();

    stageBuilder.x(0);
    stageBuilder.y(0);
    stageBuilder.z(0); // Coverslip surface is at z = 0

    // PSF, create a 2D Gaussian point-spread function
    Gaussian2D.Builder psfBuilder = new Gaussian2D.Builder();

    // Fluorophore dynamics and properties; rates are in units of 1/frames
    PalmDynamics.Builder fluorPropBuilder = new PalmDynamics.Builder();

    fluorPropBuilder.signal(2500); // Photons per fluorophore per frame
    fluorPropBuilder.wavelength(0.6); // Wavelength, microns
    fluorPropBuilder.kA(100); // Activation rate
    fluorPropBuilder.kB(0); // Bleaching rate
    fluorPropBuilder.kD1(0.065); // Transition rate to first dark state
    fluorPropBuilder.kD2(0.013); // Transition rate to second dark state
    fluorPropBuilder.kR1(0.004); // Return rate from first dark state
    fluorPropBuilder.kR2(0.157); // Return rate from second dark state

    // Fluorophore positions on a square grid
    GenerateFluorophoresGrid2D.Builder fluorPosBuilder = new GenerateFluorophoresGrid2D.Builder();
    fluorPosBuilder.spacing(4); // pixels

    // Add fiducials to the field of view at a random location
    GenerateFiducialsRandom2D.Builder fidBuilder = new GenerateFiducialsRandom2D.Builder();
    fidBuilder.numFiducials(2);
    fidBuilder.brightness(3000); // photons per frame

    // Add a constant background
    GenerateUniformBackground.Builder backgroundBuilder = new GenerateUniformBackground.Builder();
    backgroundBuilder.backgroundSignal(10); // photons

    // Assemble the microscope and the simulator.
    Microscope microscope1 = new Microscope(cameraBuilder, laserBuilder, objectiveBuilder, psfBuilder,
            stageBuilder, fluorPosBuilder, fluorPropBuilder, fidBuilder, backgroundBuilder, illumBuilder);
    RPCSimulator sim0 = new RPCSimulator(microscope1);
    sims[0] = sim0;

    // Change the number of pixels for the second microscopy
    cameraBuilder.nX(64);
    cameraBuilder.nY(64);
    Microscope microscope2 = new Microscope(cameraBuilder, laserBuilder, objectiveBuilder, psfBuilder,
            stageBuilder, fluorPosBuilder, fluorPropBuilder, fidBuilder, backgroundBuilder, illumBuilder);
    RPCSimulator sim1 = new RPCSimulator(microscope2);
    sims[1] = sim1;

    // Adds the simulations to the manager.
    manager = new DefaultSimulationManager();
    manager.addSimulator(sims[0]);
    manager.addSimulator(sims[1]);

    // Starts the server.
    rpcServer = new RPCServer(manager, PORT);

    Runnable serverRunnable = new Runnable() {
        public void run() {
            rpcServer.serve();
        }
    };
    new Thread(serverRunnable).start();
    Thread.sleep(500); // Give the server time to start
    System.out.println("Server started!");

    // Creates the client.
    rpcClient = new RPCClient(HOST_URL, PORT);
    RemoteSimulationService.Client client = rpcClient.getClient();
}

From source file:matrix.SquareMatrix.java

public static Complex[] eigenvalues(SquareMatrix A) {
    Complex[] e = new Complex[A.getRows()];

    QRDecomposition qr = new QRDecomposition();

    qr.iterations = 0;//w w w . ja v  a 2s  .  c  om
    int total_iter = 0;
    int num_eigen_found = 0;

    //in general, QR decomposition will converge faster from an upper
    //Hessenberg matrix.  so, first things first, we bring QRIterator to that form
    SquareMatrix QRIterator = new SquareMatrix(qr.hessenberg(A));
    //SquareMatrix QRIterator = new SquareMatrix(A);

    int max = MAX_ITERATIONS;
    double lastElement;
    SquareMatrix ScaledIdentity;
    do {

        System.out.println("Pre-decompose: QRIterator (Iteration#" + (qr.iterations + 1) + "):\n" + QRIterator);
        if (QRIterator.getRows() == 1) {
            //very last 1x1 element in matrix
            e[num_eigen_found++] = new Complex(QRIterator.getMatrix()[0][0]);
            break;
        } else {

            lastElement = QRIterator.getMatrix()[QRIterator.getRows() - 1][QRIterator.getColumns() - 1];
            ScaledIdentity = new SquareMatrix(Matrix.IdentityMatrix(QRIterator.getRows()).scale(lastElement));
            try {
                QRIterator = new SquareMatrix(QRIterator.subtract(ScaledIdentity));
            } catch (DimensionMismatchException ex) {
                System.out.println("Unexpected execption during QRIterator -= I*alpha, bailing.");
                System.exit(-1);

            }
            qr.decompose(QRIterator);
        }
        try {
            QRIterator = new SquareMatrix(qr.R.mult(qr.Q)/*.add(ScaledIdentity)*/);

        } catch (DimensionMismatchException ex) {
            System.out.println("An unexpected exception occurred during QRIterator = R*Q, bailing.");
            System.exit(-1);
        }
        qr.iterations++;

        //testing indicates that MAX_ITERATIONS iterations should be more than sufficient to converge, if its going to at all
        if (qr.iterations == max
                || Math.abs(QRIterator.getMatrix()[QRIterator.getRows() - 1][QRIterator.getColumns()
                        - 2]) < CONVERGENCE_CHECK) {
            System.out.println("QRIterator (at max iteration or converged) (Iteration#" + qr.iterations + "):\n"
                    + QRIterator + "\nlastElement value:\t" + lastElement);
            if (Math.abs(QRIterator.getMatrix()[QRIterator.getRows() - 1][QRIterator.getColumns()
                    - 2]) < CONVERGENCE_CHECK) {
                //then the value at M[n][n] is an eigenvalue and it is real
                e[num_eigen_found++] = new Complex(
                        QRIterator.getMatrix()[QRIterator.getRows() - 1][QRIterator.getColumns() - 1]);

                //System.out.println("e[" + (num_eigen_found - 1) + "]:\t" + e[num_eigen_found - 1] + "\nQRIterator before deflation:\n" + QRIterator);
                double[][] deflatedMatrix = deflate(QRIterator.getMatrix(), 1);
                QRIterator = new SquareMatrix(deflatedMatrix);

                total_iter += qr.iterations;
                qr.iterations = 0; //reset the iterations counter to find the next eigenvalue

                //System.out.println("\nQRIterator after deflation:\n" + QRIterator);
                /*if (2 <= QRIterator.getRows()) {
                 total_iter += qr.iterations;
                 qr.iterations = 0;  //reset the iterations counter to find the next eigenvalue
                 } else {
                 if (QRIterator.getRows() == 2) {
                 //i'm on the last 2x2 set and it's converged, so i'm going to pull the eigenvalues off the diagonal
                 e[num_eigen_found++] = new Complex(
                 QRIterator.getMatrix()[QRIterator.getRows() - 1][QRIterator.getColumns() - 1]
                 );
                 e[num_eigen_found++] = new Complex(
                 QRIterator.getMatrix()[QRIterator.getRows() - 2][QRIterator.getColumns() - 2]
                 );
                        
                 } else if (QRIterator.getRows() == 1) {
                 //i'm on the very last 1x1 submatrix and it contains the last eigenvalue
                 e[num_eigen_found++] = new Complex(
                 QRIterator.getMatrix()[QRIterator.getRows() - 1][QRIterator.getColumns() - 1]
                 );
                 }
                        
                 break;
                 }*/
            } else {
                //this is a 2x2 matrix with either real or complex roots.  need to find them.
                //characteristic equation of 2x2 array => E^2 - (w + z)E + (wz - xy) = 0 where E = eigenvalue (possibly pair, possibly singular, possibly real, possibly complex)
                // and the matrix {{w, x}, {y, z}} is the input array, the task is to calculate the root(s) of that equation
                //that is a quadratic equation => (root = (-b +- sqrt(b^2  - 4ac))/2a)
                //determinant b^2 - 4ac will determine behavior of roots => positive means 2 real roots, 0 means 1 repeated real root, negative means conjugate pair of imaginary roots

                //first, get the wxyz from the (possibly bigger) matrix
                int n = QRIterator.getRows();
                double w = QRIterator.getMatrix()[n - 2][n - 2];
                double x = QRIterator.getMatrix()[n - 2][n - 1];
                double y = QRIterator.getMatrix()[n - 1][n - 2];
                double z = QRIterator.getMatrix()[n - 1][n - 1];

                //a not used since it's = 1
                double b = -(w + z);
                double c = (w * z - x * y);

                //calculate determinant of quadratic equation
                double determ = b * b - 4 * c;

                if (determ >= 0) {
                    //one or two real roots 
                    double sqrt_determ_real = Math.sqrt(determ);
                    e[num_eigen_found++] = new Complex((-b + sqrt_determ_real) / 2.0);
                    e[num_eigen_found++] = new Complex((-b - sqrt_determ_real) / 2.0);
                    //in the zero determinant case that's simply going to add the same eigenvalue to the list twice.  I'm ok with that for now.
                } else if (determ < 0) {
                    //conjugate pair of complex roots
                    double sqrt_determ_imag = Math.sqrt(-determ);
                    e[num_eigen_found++] = new Complex(-b / 2.0, sqrt_determ_imag / 2.0);
                    e[num_eigen_found++] = new Complex(-b / 2.0, -sqrt_determ_imag / 2.0);
                }

                if (QRIterator.getRows() > 2) {
                    total_iter += qr.iterations;
                    qr.iterations = 0; //reset the iterations counter to find the next eigenvalue
                    double[][] deflatedMatrix = deflate(QRIterator.getMatrix(), 2);
                    QRIterator = new SquareMatrix(deflatedMatrix);
                }
            }
        }
        //QRIterator = new SquareMatrix(qr.hessenberg(QRIterator));

    } while (qr.iterations < max);

    //used for debugging here
    /*System.out.println("Finished iterating.  Iterations:\t" + qr.iterations
     + "\nFinal value of qr.Q:\n" + qr.Q + "\nFinal value of qr.R:\n" + qr.R
     + "\nFinal value of QRIterator:\n" + QRIterator
     + "\nOriginal SquareMatrix A:\n" + A);
     */
    return e;
}

From source file:ch.epfl.leb.sass.models.illuminations.internal.SquareUniformElectricFieldTest.java

/**
 * Test of getEz method, of class SquareUniformElectricField.
 *//*from  w  ww  .j a v a2s.c om*/
@Test
public void testGetEz() {
    System.out.println("testGetEy");
    SquareUniformElectricField instance = builder.build();

    // Inside the illumination area
    when(dummyRefractiveIndex.getN(10, 20, 0)).thenReturn(new Complex(1.0));
    Complex result = instance.getEz(10, 20, 0);
    assertEquals(0, result.getReal(), 0.0);
    assertEquals(0, result.getImaginary(), 0.0);

    // Outside the illumination area
    when(dummyRefractiveIndex.getN(-10, 20, 10)).thenReturn(new Complex(1.0));
    result = instance.getEz(-10, 20, 10);
    assertEquals(0, result.getReal(), 0.0);
    assertEquals(0, result.getImaginary(), 0.0);

    // Outside the illumination area
    when(dummyRefractiveIndex.getN(30, 20, -10)).thenReturn(new Complex(1.0));
    result = instance.getEz(30, 20, -10);
    assertEquals(0, result.getReal(), 0.0);
    assertEquals(0, result.getImaginary(), 0.0);

    // Outside the illumination area
    when(dummyRefractiveIndex.getN(10, -10, 100)).thenReturn(new Complex(1.0));
    result = instance.getEz(10, -10, 100);
    assertEquals(0, result.getReal(), 0.0);
    assertEquals(0, result.getImaginary(), 0.0);

    // Outside the illumination area
    when(dummyRefractiveIndex.getN(10, 50, -100)).thenReturn(new Complex(1.0));
    result = instance.getEz(10, 50, -100);
    assertEquals(0, result.getReal(), 0.0);
    assertEquals(0, result.getImaginary(), 0.0);
}

From source file:ch.epfl.leb.sass.models.illuminations.internal.SquareUniformElectricField.java

/**
* Returns the y-component of the time-independent electric field at the position (x, y, z).
* 
* @param x The x-position within the sample.
* @param y The y-position within the sample.
* @param z The z-position within the sample.
* @return The y-component of the electric field at the position (x, y, z).
*//*ww w .  j  a v a  2  s .  c om*/
@Override
public Complex getEy(double x, double y, double z) {
    if (x < 0 || x > width)
        return new Complex(0);
    if (y < 0 || y > height)
        return new Complex(0);

    Complex arg = getArgument(x, y, z);
    double magnitude = orientation.getY() * Math.exp(-arg.getImaginary());
    return ComplexUtils.polar2Complex(magnitude, arg.getReal());
}