Or login with:

| doublesimpson( | int | n | |
| double | (*f)(double)[function pointer] | ||
| double | a | ||
| double | b | ) |
#include <codecogs/maths/calculus/quadrature/simpson.h> #include <stdio.h> #include <math.h> // number of points #define N 100 // function to integrate double f(double x) { return sin(x); } // the primitive of f, to estimate errors double pf(double x) { return -cos(x); } int main() { // compute the approximate area double fi = Maths::Calculus::Quadrature::simpson(N, f, 1, 3), // use the Leibniz-Newton formula to find a more precise estimate realfi = pf(3) - pf(1); // uses the Leibniz-Newton formula // display problem data printf(" f(x) = sin(x)\n"); printf(" points = %d\n\n", N); // display the result and error estimate printf(" I(1, 3) = %.15lf\n", fi); printf("real value = %.15lf\n", realfi); printf(" error = %.15lf\n\n", fabs(fi - realfi)); return 0; }
f(x) = sin(x) points = 100 I(1, 3) = 1.530294803828911 real value = 1.530294802468585 error = 0.000000001360326
| n | the number of sample points of the function f, from which to approximate (must be even) |
| f | the function to integrate |
| a | the inferior limit of integration |
| b | the superior limit of integration |
Source code is available when you buy a Commercial licence.
Not a member, then Register with CodeCogs. Already a Member, then Login.
| doublesimpson( | int | n | |
| const double* | values | ||
| double | a | ||
| double | b | ) |
#include <codecogs/maths/calculus/quadrature/simpson.h> #include <stdio.h> #include <math.h> // the primitive of g, to estimate errors double pf(double x) { return 2*sqrt(x*x*x)/3; } int main() { // values of the function at equally spaced abscissas double ordinates[7] = {1, 1.0247, 1.04881, 1.07238, 1.09544, 1.11803, 1.14017}, // compute the approximate area fi = Maths::Calculus::Quadrature::simpson(7, ordinates, 1, 1.3), // use the Leibniz-Newton formula to find a more precise estimate realfi = pf(1.3) - pf(1); // uses the Leibniz-Newton formula // display problem data printf(" f(x) = sqrt(x)\n"); printf(" points = 7\n\n"); // display the result and error estimate printf(" I(1, 1.3) = %.15lf\n", fi); printf("real value = %.15lf\n", realfi); printf(" error = %.15lf\n\n", fabs(fi - realfi)); return 0; }
f(x) = sqrt(x) points = 7 I(1, 1.3) = 0.321485166666667 real value = 0.321485368419253 error = 0.000000201752586
| n | the number of sample points of the function f, from which to approximate (must be odd) |
| values | an array with the value of the function at equally spaced abscissas |
| a | the inferior limit of integration |
| b | the superior limit of integration |
Source code is available when you buy a Commercial licence.
Not a member, then Register with CodeCogs. Already a Member, then Login.
You must login to leave a messge