Commit a5cde559 authored by Hans Buchmann's avatar Hans Buchmann

simpson solution

parent cec2c465
......@@ -7,7 +7,34 @@
static const double SQRT2=std::sqrt(2);
/*
n>1 odd
|------|------|------|
i-2 i-1 i
*/
//volume{
double volume(double h,double y[],unsigned n)
{
if ((n%2)==0) //n==even
{
return 0;
}
//n==odd
if (n<3)
{
return 0;
}
//3<=n and even
double s=0;
for(unsigned i=2;i<n;i=i+2) //2<=i<n n odd
{
double y2=y[i-2]*y[i-2];
double y1=y[i-1]*y[i-1];
double y0=y[i ]*y[i ];
s=s+ (1*y2 + 4* y1 +1*y0);
}
return (2*SQRT2)*(h/3)*s;
}
//volume}
double circle(double r,double y[],unsigned n)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment