Commit 0a237ba5 authored by Taddeüs Kroes's avatar Taddeüs Kroes

ModSim ass2: Implemented Simpson's Rule as calculation instead of weighted average.

parent b87a48cf
...@@ -9,7 +9,8 @@ double trapezoidal(func_ptr f, double a, double b) { ...@@ -9,7 +9,8 @@ double trapezoidal(func_ptr f, double a, double b) {
} }
double simpson(func_ptr f, double a, double b) { double simpson(func_ptr f, double a, double b) {
return (2 * rectangle(f, a, b) + trapezoidal(f, a, b)) / 3; //return (2 * rectangle(f, a, b) + trapezoidal(f, a, b)) / 3;
return (b - a) / 6 * (f(a) + 4 * f((a + b) / 2) + f(b));
} }
double gauss(func_ptr f, double a, double b) { double gauss(func_ptr f, double a, double b) {
......
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