Exemplo n.º 1
1
 private void doCurrentMethodStep() {
   switch (type) {
     case 0: // bisectiei
       if (Math.abs(function.evaluate((Cn.lastElement()).x)) < err) {
         complete = true;
         theTimer.stop();
       } else if (function.evaluate((An.lastElement()).x) * function.evaluate((Cn.lastElement()).x)
           < 0) {
         Bn.add(Cn.lastElement());
         Cn.add(new PointDP(((An.lastElement()).x + (Bn.lastElement()).x) / 2, 0.0));
       } else {
         An.add(Cn.lastElement());
         Cn.add(new PointDP(((An.lastElement()).x + (Bn.lastElement()).x) / 2, 0.0));
       }
       break;
     case 1: // coardei
       {
         double evn = function.evaluate((An.lastElement()).x);
         if (Math.abs(evn) < err) {
           complete = true;
           theTimer.stop();
         } else {
           double ev0 = function.evaluate((An.firstElement()).x);
           double newVal = (An.firstElement().x * evn - An.lastElement().x * ev0) / (evn - ev0);
           An.add(new PointDP(newVal, 0.0));
         }
       }
       break;
     case 2: // secantei
       {
         double exn = function.evaluate((An.lastElement()).x);
         if (Math.abs(exn) < err) {
           complete = true;
           theTimer.stop();
         } else {
           double exn1 = function.evaluate((An.elementAt(An.size() - 2)).x);
           double newVal =
               (An.elementAt(An.size() - 2).x * exn - (An.lastElement()).x * exn1) / (exn - exn1);
           An.add(new PointDP(newVal, 0.0));
         }
       }
       break;
     case 3: // newton
       double xn = An.lastElement().x;
       if (Math.abs(function.evaluate(xn)) < err) {
         complete = true;
         theTimer.stop();
       }
       An.add(new PointDP(xn - function.evaluate(xn) / function.evaluate_1(xn), 0.0));
       break;
   }
 }
Exemplo n.º 2
0
 public void nudge(int i) {
   x[i] += (double) rand.nextInt(1000) / 8756;
   y[i] += (double) rand.nextInt(1000) / 5432;
   int tmpScale = (int) (Math.abs(Math.sin(x[i])) * 10);
   scale[i] = (double) tmpScale / 10;
   int nudgeX = (int) (((double) getWidth() / 2) * .8);
   int nudgeY = (int) (((double) getHeight() / 2) * .60);
   xh[i] = (int) (Math.sin(x[i]) * nudgeX) + nudgeX;
   yh[i] = (int) (Math.sin(y[i]) * nudgeY) + nudgeY;
 }
Exemplo n.º 3
0
  /**
   * private method to produce a time string from the indicated DTG we've moved it out of the
   * newTime box so that we can access it from a tester
   */
  public String getNewTime(final HiResDate DTG) {
    final String pattern = _dateFormatter.toPattern();

    String res = "";

    if (pattern.startsWith("'T+'")) {
      // hey, we're doing our "Special format".
      res = "T ";

      // get the T-zero time
      final HiResDate theTZero = getTimeZero();
      if (theTZero == null) {
        // no, return an error message
        return "N/A";
      }

      final long Tzero = theTZero.getMicros();

      // what's the elapsed time
      final long elapsed = DTG.getMicros() - Tzero;

      if (Math.abs(elapsed) > 1000000000000l) {
        res = "N/A";
      } else {

        // how many seconds is this?
        long secs = (long) (elapsed / 1000000d);

        // are we +ve?
        if (secs > 0) {
          res += "+";
        } else {
          res += "-";
        }

        // ok, we've handled the +ve/-ve make it absolute
        secs = Math.abs(secs);

        // which format do they want?
        String format = pattern.substring(pattern.indexOf(" "));

        // strip the format string
        format = format.trim();

        if (format.equals("SSS")) {
          // do we have our number formatter?
          if (_secondsFormat == null) _secondsFormat = new java.text.DecimalFormat("000s");

          res += _secondsFormat.format(secs);
        } else if (format.equals("MM:SS")) {
          // how many mins?
          final long mins = secs / 60;

          // and the seconds
          secs -= mins * 60;

          res += mins;

          res += ":";

          res += MWC.Utilities.TextFormatting.BriefFormatLocation.df2.format(secs);

        } else {
          MWC.Utilities.Errors.Trace.trace("Step control: invalid TZero format found:" + format);
        }
      }
    } else {
      // are we in hi-res mode or not?
      if (HiResDate.inHiResProcessingMode()) res = DebriefFormatDateTime.formatMicros(DTG);
      else res = _dateFormatter.format(DTG.getDate());
    }

    return res;
  }