Commit e9191165 authored by Taddeüs Kroes's avatar Taddeüs Kroes

Worked on ass5.

parent cebe0b55
......@@ -3,7 +3,7 @@
#include <math.h>
#include "func_ptr.h"
#define DX 1e-6
#define DX 1e-3
typedef double (*method_ptr)(func_ptr, double, double);
......@@ -19,6 +19,10 @@ double simpson(func_ptr f, double a, double b) {
return (2 * rectangle(f, a, b) + trapezoidal(f, a, b)) / 3;
}
double gauss(func_ptr f, double a, double b) {
return 0;
}
double integral(func_ptr f, method_ptr method, double a, double b) {
int steps = (int)((b - a) / DX), i;
double x, surface = 0;
......@@ -34,16 +38,36 @@ double f1(double x) {
}
double f2(double x) {
return x * pow(M_E, -x);
return x * f1(x);
}
#define PRINT_INTEGRAL(func, method, a, b) (printf(#func " from " #a " to " \
#b " using " #method " method: %.11f\n", integral(&func, &method, a, b)))
#b " using %-19s %.11f\n", #method " method:", integral(&func, &method, a, b)))
#define PRINT_GAUSS(func, a, b) (printf(#func " from " #a " to " \
#b " using %-19s %.11f\n", "gauss method:", gauss(&func, a, b)))
int main(void) {
PRINT_INTEGRAL(f1, rectangle, 0, 1);
PRINT_INTEGRAL(f1, trapezoidal, 0, 1);
PRINT_INTEGRAL(f1, simpson, 0, 1);
//PRINT_INTEGRAL(f1, rectangle, 0, 1);
//PRINT_INTEGRAL(f1, trapezoidal, 0, 1);
//PRINT_INTEGRAL(f1, simpson, 0, 1);
//puts("");
//PRINT_INTEGRAL(f2, rectangle, 0, 2);
//PRINT_INTEGRAL(f2, trapezoidal, 0, 2);
//PRINT_INTEGRAL(f2, simpson, 0, 2);
//puts("");
//PRINT_INTEGRAL(f2, rectangle, 0, 20);
//PRINT_INTEGRAL(f2, trapezoidal, 0, 20);
//PRINT_INTEGRAL(f2, simpson, 0, 20);
//puts("");
//PRINT_INTEGRAL(f2, rectangle, 0, 200);
//PRINT_INTEGRAL(f2, trapezoidal, 0, 200);
//PRINT_INTEGRAL(f2, simpson, 0, 200);
//puts("");
//PRINT_INTEGRAL(sin, rectangle, 0, 8 * M_PI);
//PRINT_INTEGRAL(sin, trapezoidal, 0, 8 * M_PI);
//PRINT_INTEGRAL(sin, simpson, 0, 8 * M_PI);
PRINT_GAUSS(f1, 0, 1);
return 0;
}
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