#define _USE_MATH_DEFINES #include #include #include #include float f( float x ) { float k=tan(x); return k; } float F( float x ) { float p; p=-log(fabs(cos(x))); return -log(fabs(cos(x))); } /* функция численного интегрирования */ float Integral(float Left, float Right, int n, float (*func)(float)) { int i; float res,h; res=0.0; //printf("Left=%.9f ",Left); h = (Right - Left) / n; for(i = 0; i < n; i++) { //printf("Func=%.7f ", f(Left + h * (i+0.5))); res+= f(Left + (Right-Left) * (i + 0.5)/n); //printf("res=%.7f\n",res); } //printf("///////%.9f\n", Left+h*i); res *= h; return res; } int main() { long n; float D = 1.57079; float L =-D/*M_PI/4*/, R =D /*M_PI/4*/; float V, V0 = F( R ) - F( L ); printf("V0=%.9f\n", V0); setlocale( LC_ALL, "" ); /* точное решение */ printf("Число шагов;абсолютная ошибка\n"); for ( n = 1; n < 100; n += n/100+1) { V = Integral( L, R, n, f ); /* приближенное решение для n шагов */ printf( "%ld;=%.9f\n", n, (V-V0) ); /* n и абсолютная ошибка */ } return 0; }