The Artima Developer Community
Sponsored Link

Java Answers Forum
Help with numerical methods project java code (trapezoidal rule)

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
George Maravich

Posts: 1
Nickname: georgemara
Registered: Dec, 2014

Help with numerical methods project java code (trapezoidal rule) Posted: Dec 3, 2014 11:26 PM
Reply to this message Reply
Advertisement
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. Any thoughts? Please help. Thanks!

Topic: Calculating tax java, need HELP Previous Topic   Next Topic Topic: USE OF SELECTONE MENU IN JSF

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use