Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Hi guys need help with Trapezoidal Rule Java code
Hi guys need help with Trapezoidal Rule Java code [message #1496762] Wed, 03 December 2014 08:47
George Maravich is currently offline George MaravichFriend
Messages: 7
Registered: December 2014
Junior Member
Hi guys. Need help...
I tried running the code for trapezoidal rule. It's my project in Numerical Methods, here's the code:

static double trapezoidRule (int size, double[] x, double[] y)
   {  double sum = 0.0,
             increment;

      for ( int k = 1; k < size; k++ )
      {//Trapezoid rule:  1/2 h * (f0 + f1)
         increment = 0.5 * (x[k]-x[k-1]) * (y[k]+y[k-1]);
         sum += increment;
      }
      return sum;
   }

   public static void main ( String[] args ) throws Exception
   {  String   fileName = args.length > 0 ? args[0] : "InpData.txt";
      Scanner  inp = new Scanner(new File(fileName));
      int      k, size;
      double[] x, y;
      double   integral;

      size = inp.nextInt();
      System.out.println ("Number of points:  " + size);

      x = new double[size];
      y = new double[size];

      for ( k = 0; k < size; k++ )
      {  x[k] = inp.nextDouble();
         y[k] = inp.nextDouble();
      }
      integral = trapezoidRule (size, x, y);
      System.out.printf ("Integral:  %4.4f\n", integral);
      System.out.printf ("Check:  log(%2.2f) = %8.8f\n",
                         x[size-1], Math.log(x[size-1]) );
   }
}


It cannot be compiled and I always get FileNotFoundException. I found on Javadocs.com that this will be thrown when a file with the path name does not exist. Please help. Thanks!

Previous Topic:Helpful ways of having one project use the classes/jars of another
Next Topic:HELP ME PLEASE (Some basic java)
Goto Forum:
  


Current Time: Thu Dec 03 20:40:59 GMT 2020

Powered by FUDForum. Page generated in 0.04719 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top