#include <stdio.h> #include <stdlib.h> #include <math.h> #define EPS 1E-8 double kansu(double x); double dou_kansu(double x); main(){ int n = 0; double x,i; printf("初期値は? "); scanf("%lf",&x); while(n < 30) { n++; x = x - kansu(x) / dou_kansu(x); if ( fabs( kansu(x) ) < EPS ) break; } if (n == 30){ printf("収束しません。\n"); }else{ printf("反復回数:%2d 近似解:%.16f 誤差:%.16f\n", n, x, fabs(kansu(x))); } } double kansu(double x){ double a; a=1/x-tan(x); return a; } double dou_kansu(double x){ double a; a=-1/(x*x)-1/(cos(x)*cos(x)); return a; }
Copyright (C) 1999-2000 木野田和正