/**
  * Computes and plots correlation functions
  *
  * @param tauMax is the maximum time for correlation functions
  */
 public void computeCorrelation(int tauMax) {
   plotFrame.clearData();
   double energyAccumulator = 0, magnetizationAccumulator = 0;
   double energySquaredAccumulator = 0, magnetizationSquaredAccumulator = 0;
   for (int t = 0; t < numberOfPoints; t++) {
     energyAccumulator += energy[t];
     magnetizationAccumulator += magnetization[t];
     energySquaredAccumulator += energy[t] * energy[t];
     magnetizationSquaredAccumulator += magnetization[t] * magnetization[t];
   }
   double averageEnergySquared = Math.pow(energyAccumulator / numberOfPoints, 2);
   double averageMagnetizationSquared = Math.pow(magnetizationAccumulator / numberOfPoints, 2);
   // compute normalization factors
   double normE = (energySquaredAccumulator / numberOfPoints) - averageEnergySquared;
   double normM = (magnetizationSquaredAccumulator / numberOfPoints) - averageMagnetizationSquared;
   for (int tau = 1; tau <= tauMax; tau++) {
     double c_MAccumulator = 0;
     double c_EAccumulator = 0;
     int counter = 0;
     for (int t = 0; t < numberOfPoints - tau; t++) {
       c_MAccumulator += magnetization[t] * magnetization[t + tau];
       c_EAccumulator += energy[t] * energy[t + tau];
       counter++;
     }
     // correlation function defined so that c(0) = 1 and c(infinity) -> 0
     plotFrame.append(0, tau, ((c_MAccumulator / counter) - averageMagnetizationSquared) / normM);
     plotFrame.append(1, tau, ((c_EAccumulator / counter) - averageEnergySquared) / normE);
   }
   plotFrame.setVisible(true);
 }
Ejemplo n.º 2
0
 /**
  * Calculates the trajectory of a falling particle and plots the position as a function of time.
  */
 public void calculate() {
   plotFrame.setAutoclear(false); // data not cleared at beginning of each calculation
   // gets initial conditions
   double y0 = control.getDouble("Initial y");
   double v0 = control.getDouble("Initial v");
   // sets initial conditions
   Particle ball = new FallingParticle(y0, v0);
   // gets parameters
   ball.dt = control.getDouble("dt");
   while (ball.y > 0) {
     ball.step();
     plotFrame.append(0, ball.t, ball.y);
     plotFrame.append(1, ball.t, ball.analyticPosition());
   }
 }
Ejemplo n.º 3
0
 /** Calculates the wave function. */
 public void calculate() {
   schroedinger.xmin = control.getDouble("xmin");
   schroedinger.xmax = control.getDouble("xmax");
   schroedinger.stepHeight = control.getDouble("step height at x = 0");
   schroedinger.numberOfPoints = control.getInt("number of points");
   schroedinger.energy = control.getDouble("energy");
   schroedinger.initialize();
   schroedinger.solve();
   frame.append(0, schroedinger.x, schroedinger.phi);
 }