09/01/07 16:59:44
>>337
#include<stdio.h>
#include<math.h>
//英語わからん
#define YUUKOUKETASUU 1e-5
double f(double x) {
return x*x*x - 10*x*x + 10*x + 50;
}
double g(double x) {
return 3*x*x - 20*x +10;
}
double NewtonMethod(double xn) {
double xn1 = xn - (f(xn)/g(xn));
if (fabs(xn1 - xn) < YUUKOUKETASUU)
return xn1;
return NewtonMethod(xn1);
}
int main(void) {
double x = NewtonMethod(0);
printf("f(x) = x^3 - 10x^2 +10x + 50\n");
printf("f(%f) = %f\n", x, f(x));
return 0;
}