Package com.nr.ran

Examples of com.nr.ran.Ran


   

    // Test Fitmed
    System.out.println("Testing Fitmed");

    Ran myran = new Ran(17);
    for (i=0;i<N;i++) {
      x[i]=10.0*myran.doub();
      y[i]=sqrt(2.0)+pi*x[i];
    }

    Fitmed fit1 = new Fitmed(x,y);   // Perfect fit, no noise

View Full Code Here


   

    // Test Fitab
    System.out.println("Testing Fitab");

    Ran myran =new Ran(17);
    sumx2=0;
    for (i=0;i<N;i++) {
      x[i]=10.0*myran.doub();
      y[i]=sqrt(2.0)+pi*x[i];
      sig[i]=1.0;
      sumx2 += SQR(x[i]);
    }

View Full Code Here

   

    // Test piksrt
    System.out.println("Testing piksrt");
    Ran myran = new Ran(17);
    for (i=0;i<N;i++) x[i]=myran.doub();
    Sorter.piksrt(x);
    for (i=0;i<N-1;i++) localflag = localflag || (x[i] > x[i+1]);
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** piksrt: Sorted values are not correctly ordered");
View Full Code Here

   

    // Test hpsort
    System.out.println("Testing hpsort");
    Ran myran = new Ran(17);
    for (i=0;i<N;i++) x[i]=myran.doub();
    Sorter.hpsort(x);
    for (i=0;i<N-1;i++) localflag = localflag || (x[i] > x[i+1]);
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** hpsort: Sorted values are not correctly ordered");
View Full Code Here

   

    // Test Jacobi
    System.out.println("Testing Jacobi");

    Ran myran = new Ran(17);
    for (i=0;i<N;i++) {
      a[i][i]=myran.doub();
      for (j=0;j<i;j++) {
        a[i][j]=myran.doub();
        a[j][i]=a[i][j];
      }
    }
    Jacobi jac = new Jacobi(a);
   
View Full Code Here

   

    // Test Unsymmeig, symmetric, interface1
    System.out.println("Testing Unsymmeig, symmetric, interface1");

    Ran myran=new Ran(17);
    for (i=0;i<N;i++) {
      a[i][i]=myran.doub();
      for (j=0;j<i;j++) {
        a[i][j]=myran.doub();
        a[j][i]=a[i][j];
      }
    }
    Unsymmeig usym = new Unsymmeig(a,true,false);

//    for (i=0;i<N;i++) System.out.printf(usym.wri[i]);

    // Test that all eigenvalues are real for symmetric matrix
    for (i=0;i<N;i++)
      localflag = localflag || (usym.wri[i].im() != 0);
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Unsymmeig, symmetric, interface1: Symmetric matrix gave an eigenvalue that was not real");
     
    }

    // Test eigenvector/eigenvalue pairs
    for (i=0;i<N;i++) {   // for each eigenvector
      for (j=0;j<N;j++) vec[j]=usym.zz[j][i];
      res=matmul(a,vec);
      for (j=0;j<N;j++) vec[j] *= usym.wri[i].re();
//      System.out.printf(maxel(vecsub(res,vec)));
      localflag = localflag || (maxel(vecsub(res,vec)) > sbeps);
    }
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Unsymmeig, symmetric, interface1: Matrix times eigenvector was not the same as lambda*eigenvector");
     
    }
   
    // Test the sorting of the eigenvalues
    for (i=1;i<N;i++)
      localflag = localflag || (usym.wri[i].re() > usym.wri[i-1].re());
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Unsymmeig, symmetric, interface1: Eigenvalues not sorted in high-to-low order");
     
    }

    //------------------------------------------------------------------------
    // Test Unsymmeig, non-symmetric, interface1
    System.out.println("Testing Unsymmeig, non-symmetric, interface1");
    ranmat(a);
    Unsymmeig usym2 = new Unsymmeig(a,true,false);

//    for (i=0;i<N;i++) System.out.printf(usym2.wri[i]);

    // Test eigenvector/eigenvalue pairs
    for (i=0;i<N;i++) {   // for each eigenvector
      if (usym2.wri[i].im() == 0.0) {
        for (j=0;j<N;j++) vec[j]=usym2.zz[j][i];
        res=matmul(a,vec);
        for (j=0;j<N;j++) vec[j] *= usym2.wri[i].re();
//        System.out.println("real eigenvalue  " << maxel(vecsub(res,vec)));
        localflag = localflag || (maxel(vecsub(res,vec)) > sbeps);
      } else {
        if (usym2.wri[i].im() > 0.0)
          for (j=0;j<N;j++) zvec[j]=new Complex(usym2.zz[j][i],usym2.zz[j][i+1]);
        else
          for (j=0;j<N;j++) zvec[j]=new Complex(usym2.zz[j][i-1],-usym2.zz[j][i]);
        for (j=0;j<N;j++) {
          zres[j]=new Complex(0.,0.);
          for (k=0;k<N;k++) zres[j] = zres[j].add(zvec[k].mul(a[j][k]));
        }
        for (j=0;j<N;j++) zvec[j] = zvec[j].mul(usym2.wri[i]);
        max=0.;
        for (j=0;j<N;j++) max = (max > zres[j].sub(zvec[j]).abs() ? max : zres[j].sub(zvec[j]).abs());
//        System.out.println("imag eigenvalue  " << max);
        localflag = localflag || (max > sbeps);
      }
      max=0.;
      for (j=0;j<N;j++) max = (max > zres[j].sub(zvec[j]).abs() ? max : zres[j].sub(zvec[j]).abs());
      localflag = localflag || (max > sbeps);
    }
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Unsymmeig, non-symmetric, interface1: Matrix times eigenvector was not the same as lambda*eigenvector");
     
    }
   
    // Test the sorting of the eigenvalues
    for (i=1;i<N;i++)
      localflag = localflag || (usym2.wri[i].re() > usym2.wri[i-1].re());
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Unsymmeig, non-symmetric, interface1: Eigenvalues not sorted in high-to-low order of real part");
     
    }

    for (i=1;i<N;i++)
      localflag = localflag || (usym2.wri[i].im() > 0.0) && (!usym2.wri[i].equals(usym2.wri[i+1].conj()));
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Unsymmeig, non-symmetric, interface1: A complex eigenvalue with positive imag part is not followed by its conjugate");
     
    }

    //------------------------------------------------------------------------
    // Test Unsymmeig, non-symmetric, interface2
    System.out.println("Testing Unsymmeig, non-symmetric, interface2");
    for (i=0;i<N;i++)
      for (j=0;j<N;j++)
        a[i][j]= (i > j+1 ? 0.0 : myran.doub());
    Unsymmeig usym3 = new Unsymmeig(a,true,true);

//    for (i=0;i<N;i++) System.out.printf(usym3.wri[i]);

    // Test eigenvector/eigenvalue pairs
View Full Code Here

   

    // Test Symmeig
    System.out.println("Testing Symmeig, interface1");
    Ran myran = new Ran(17);
    for (i=0;i<N;i++) {
      a[i][i]=myran.doub();
      for (j=0;j<i;j++) {
        a[i][j]=myran.doub();
        a[j][i]=a[i][j];
      }
    }
    Symmeig sym = new Symmeig(a);
   
View Full Code Here

      depend[i] = new NRsparseCol();
    }
    pr = new int[mm];
    t =0;
    asum=0;
    ran = new Ran(seed);
   
    int i,j,k,d;
    describereactions();
    sparmatfill(outchg,outstate);
    double[][] dep = new double[mm][mm];
View Full Code Here

        x2[j]=(double)(j)/(N-1);
        y[i][j]=x1[i]+x2[j];
      }
    }
    Bilin_interp z = new Bilin_interp(x1,x2,y);
    Ran myran = new Ran(17);
    for (i=0;i<N;i++) {
      xx1=myran.doub();
      xx2=myran.doub();
      yy[i]=z.interp(xx1,xx2)// interpolated values
      zz[i]=xx1+xx2;        // Actual values
    }
    sbeps=1.e-15;
    System.out.printf("     Bilin_interp: Max. actual error:    %f\n", maxel(vecsub(zz,yy)));
View Full Code Here

      fail("*** betai: Incorrect function values");
     
    }

    // Round trip test
    Ran myran = new Ran(17);
    sbeps=1.e-8;
    for (i=0;i<M;i++) {
      c=10.0*myran.doub();
      d=10.0*myran.doub();
      u=myran.doub();
//      System.out.printf(i << " %f\n", u;
      r=Beta.betai(c,d,u);
//      System.out.println(" %f\n", r;
      uu=Beta.invbetai(r,c,d);
//      System.out.println(" %f\n", uu);
View Full Code Here

TOP

Related Classes of com.nr.ran.Ran

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.