Skip to content

Commit

Permalink
Composite simpson's rule
Browse files Browse the repository at this point in the history
  • Loading branch information
BSVino committed May 9, 2016
1 parent bf8ddd6 commit c33f7d4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
44 changes: 44 additions & 0 deletions game/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,52 @@ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON A
using std::vector;


// This is actually midpoint rule
double BoringRectangles(double t0, double t1, int n)
{
double h = (t1-t0) / n;
double sum = 0;

for (int k = 0; k < n; k++)
{
double t = t0 + k*h + h/2;
double rectangle_area = h * exp(t);
sum += rectangle_area;
}

return sum;
}

double CompositeSimpsonsRule(double t0, double t1, int n)
{
double h = (t1-t0) / n;
double endpoints = exp(t0) + exp(t1);
double X4 = 0;
double X2 = 0;

for (int k = 1; k < n; k += 2)
{
double t = t0 + k*h;
X4 += exp(t);
}

for (int k = 2; k < n; k += 2)
{
double t = t0 + k*h;
X2 += exp(t);
}

return (h / 3) * (endpoints + 4 * X4 + 2 * X2);
}



int main(int argc, char* argv[])
{
printf("Actual value: %.16f\n", exp(1) - 1);
printf("Boring rectangles: %.16f\n", BoringRectangles(0, 1, 64));
printf("Composite Simpson: %.16f\n", CompositeSimpsonsRule(0, 1, 64));

mtsrand(0);

// Create a game
Expand Down
1 change: 0 additions & 1 deletion renderer/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ bool CApplication::OpenWindow(size_t iWidth, size_t iHeight, bool bFullscreen, b
{
if (!glfwInit())
{
DWORD k = GetLastError();
printf("glfwInit failed\n");
exit(1);
}
Expand Down

0 comments on commit c33f7d4

Please sign in to comment.