Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- /*
- \int_0^1 1/(2+x^3)
- f(x) = 1/(2+x^3)
- */
- float rectangle(float a, float b, float N);
- float f(float x);
- float f_2(float x);
- float find_M(float a, float b);
- int main(int argc, char **argv)
- {
- float N = 10;
- float a = 0;
- float b = 1;
- float h;
- h = (b - a) / N;
- float S = rectangle(a,b,N);
- float M = find_M(a,b);
- float R = M * pow(h,2)*(b-a) / 24;
- printf("S = %f\n", S);
- printf("M = %f\n", M);
- printf("R <= %f\n", R);
- return 0;
- }
- float rectangle(float a, float b, float N)
- {
- int i;
- float h = (b - a) / N;
- float S = 0, x_i, x_i2;
- for (i = 1; i <= N; i++) {
- x_i = a + i*h;
- x_i2 = x_i - 0.5*h;
- S += f(x_i2)*h;
- }
- return S;
- }
- float f(float x)
- {
- return 1/(2 + pow(x, 3));
- }
- float find_M(float a, float b)
- {
- float max, Max;
- max = (f_2(a) > f_2(b)) ? f_2(a) : f_2(b);
- Max = (max > f_2((b-a)/2)) ? max : f_2((b-a)/2);
- return Max;
- }
- float f_2(float x)
- {
- return fabs((-12*x*(1 - pow(x, 3))) / pow((2+pow(x,3)), 3));
- }
Advertisement
Add Comment
Please, Sign In to add comment