Need help on writing a program for integration ASAP
Author |
Message |
sweety
|
Posted: 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

|
|
 |
jernst

|
Posted: 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 |
|
|
|
|
 |
|
|