No to tak, wybiorę sobie może jeden przypadek, a Ty spróbujesz zrobić drugi. Wybieram
f(x) = (1 + x) ^ (1/3)
Drugi przypadek jest analogiczny, doprowadzisz go sobie do porządku sam.
#include <assert.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_ITER 4000
double
szereg(double x, int iterations)
{
double coeff = 1.0;
double result = 1.0;
int ii;
/*
* For |x| <= 1.0:
* +inf
* __
* sqrt3(1 + x) ~= \ n ( 1/3 )
* /_ x ( n )
* n=0
*/
for (ii = 1; fabs(coeff) > 1e-48 && ii < iterations; ii++) {
coeff *= (1.0 / 3.0 - (double)(ii - 1)) / (double)ii * x;
result += coeff;
}
return (result);
}
int
main()
{
int lp;
double a, b, step, x;
scanf("%lf %lf %d", &a, &b, &lp);
step = (b - a) / (double)lp;
for (x = a; x <= b; x += step) {
const double v1 = szereg(x, MAX_ITER);
const double v2 = pow(1.0 + x, 1.0 / 3.0);
printf("%lf %.07lf %.07lf %.032lf\n", x, v1, v2, fabs(v1 - v2));
}
}
Dla wartości x bliskich -1 cała zabawa się wywala, bo w sumie samo przybliżenie Taylorem tej funkcji jest trochę słabe w tej okolicy. Spróbuj ogarnąć sam przypadek dla f(x) = (1 - x)^(1/3).