Package com.nr.inv

Examples of com.nr.inv.Wwghts


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

    Quad quad =new Quad();
    Wwghts weight2 = new Wwghts(1.0,2,quad);
    w2=weight2.weights();
//    for (i=0;i<2;i++) System.out.printf(w2[i] << " ";
//    System.out.printf(endl;

    sum=0.0;
    for (i=0;i<2;i++) sum += w2[i];
//    System.out.printf(abs(sum-1.0));
    localflag = abs(sum-1.0) > sbeps;
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Wwghts: 2-point weights do not add to 1.0");
     
    }

    // Check integral of 1+x => x + x^2/2
    expect=1.0+0.5;
    sum=w2[0]*1.0+w2[1]*2.0;
//    System.out.printf(expect << " %f\n", sum);
    localflag = abs(sum/expect-1.0) > sbeps;
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Wwghts: 2-point weights fail on linear function");
     
    }

    Wwghts weight3 = new Wwghts(1.0/2.0,3,quad);
    w3=weight3.weights();
//    for (i=0;i<3;i++) System.out.printf(w3[i] << " ";
//    System.out.printf(endl;

    sum=0.0;
    for (i=0;i<3;i++) sum += w3[i];
//    System.out.printf(abs(sum-1.0));
    localflag = abs(sum-1.0) > sbeps;
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Wwghts: 3-point weights do not add to 1.0");
     
    }

    // Check integral of 1+x+x^2 => x + x^2/2 + x^3/3
    expect=1.0+0.5+1.0/3.0;
    sum=w3[0]*1.0+w3[1]*(1.0+0.5*(1.0+0.5))+w3[2]*3.0;
//    System.out.printf(expect << " %f\n", sum);
    localflag = abs(sum/expect-1.0) > sbeps;
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Wwghts: 3-point weights fail on quadratic function");
     
    }

    Wwghts weight4 = new Wwghts(1.0/3.0,4,quad);
    w4=weight4.weights();
//    for (i=0;i<4;i++) System.out.printf(w4[i] << " ";
//    System.out.printf(endl;

    sum=0.0;
    for (i=0;i<4;i++) sum += w4[i];
//    System.out.printf(abs(sum-1.0));
    localflag = abs(sum-1.0) > sbeps;
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Wwghts: 4-point weights do not add to 1.0");
     
    }

    // Check integral of 1+x+x^2+x^3 => x + x^2/2 + x^3/3 + x^4/4
    expect=1.0+0.5+1.0/3.0+0.25;
    sum=w4[0]*1.0
      +w4[1]*(1.0+(1.0/3.0)*(1.0+(1.0/3.0)*(1.0+(1.0/3.0))))
      +w4[2]*(1.0+(2.0/3.0)*(1.0+(2.0/3.0)*(1.0+(2.0/3.0))))
      +w4[3]*4.0;
//    System.out.printf(expect << " %f\n", sum);
    localflag = abs(sum/expect-1.0) > sbeps;
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Wwghts: 4-point weights fail on cubic polynomial");
     
    }

    Wwghts weight5=new Wwghts(1.0/4.0,5,quad);
    w5=weight5.weights();
//    for (i=0;i<5;i++) System.out.printf(w5[i] << " ";
//    System.out.printf(endl;

    sum=0.0;
    for (i=0;i<5;i++) sum += w5[i];
//    System.out.printf(abs(sum-1.0));
    localflag = abs(sum-1.0) > sbeps;
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Wwghts: 5-point weights do not add to 1.0");
     
    }

    // Check integral of 1+x+x^2+x^3 => x + x^2/2 + x^3/3 + x^4/4
    expect=1.0+0.5+1.0/3.0+0.25;
    sum=w5[0]*1.0
      +w5[1]*(1.0+0.25*(1.0+0.25*1.25))
      +w5[2]*(1.0+0.50*(1.0+0.50*1.50))
      +w5[3]*(1.0+0.75*(1.0+0.75*1.75))
      +w5[4]*4.0;
//    System.out.printf(expect << " %f\n", sum);
    localflag = abs(sum/expect-1.0) > sbeps;
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Wwghts: 5-point weights fail on cubic polynomial");
     
    }

    Wwghts weight6=new Wwghts(1.0/5.0,6,quad);
    w6=weight6.weights();
//    for (i=0;i<6;i++) System.out.printf(w6[i] << " ";
//    System.out.printf(endl;

    sum=0.0;
    for (i=0;i<6;i++) sum += w6[i];
View Full Code Here

TOP

Related Classes of com.nr.inv.Wwghts

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.