Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- typedef double (*func_t) (double);
- double half (double eps, double alpha);
- double integrand(double t);
- double integrate (func_t f, double eps);
- double half (double eps, double alpha) {
- double a = 0;
- double b = 1;
- double x;
- while (b - a > eps) {
- x = (a + b) / 2;
- if ((integrate(integrand, a, eps) - alpha)*(integrate(integrand, x, eps) - alpha) > 0) {
- a = x;
- }
- else {
- b = x;
- }
- }
- return x;
- }
- double integrand(double t) {
- return x*x / ((1 + pow(x, 4)) * sqrt(1 - pow(x, 4)));
- }
- double integrate (func_t f, double x, double eps) {
- double a = 0;
- double b = 1;
- double value = 0;
- double h = (b - a) / 100;
- double x = a;
- int working = 1;
- double integral_1;
- double integral_2;
- while (working) {
- if (x + h >= b) {
- h = b - x;
- working = 0;
- }
- integral_1 = (x + h - x) * integrand(x);
- integral_2 = (x + h/2 - x) * integrand(x) + (x + h - x + h / 2) * integrand(x + h / 2);
- if (fabs(integral_1 - integral_2) < eps / 4) {
- value = value + integral_1;
- x = x + h;
- h *= 1.5;
- }
- else if (fabs(integral_1 - integral_2) < eps) {
- value = value + integral_1;
- x = x + h;
- }
- else {
- h = h / 2;
- working = 1;
- }
- return value;
- }
- int main(void) {
- double eps;
- double x;
- double alpha = M_PI/8;
- printf ("Enter epsilon!\n");
- if (scanf("%lf", &eps) != 1) {
- printf ("Incorrect value!\n");
- return -1;
- }
- x = half(eps, alpha);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement