Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Need help on writing a program for integration ASAP
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
sweety




PostPosted: Wed May 14, 2008 11:07 am   Post subject: Need help on writing a program for integration ASAP

I have a computer science project to do in which I should integrate using Left-hand endpoint, Midpoint rule and trapezoid rule.

I have the code for trapezoid rule but not sure it if is right.Please help me as soon as possible.

public class Trapezoid
{
static double integrate(double a, double b, int N)
{
double h = (b - a) / N;
double sum = 0.5 * (f(a) + f(b));
for (int i = 1; i < N; i++)
{
double x = a + h * i;
sum = sum + f(x);
}
return sum * h;
}
}
Sponsor
Sponsor
Sponsor
sponsor
jernst




PostPosted: Wed May 14, 2008 4:08 pm   Post subject: Re: Need help on writing a program for integration ASAP

you know you could just test the thing by putting in numbers and checking it against real results...thats how most ppl check to see if their code works rather than waiting for an answer from forums
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: