- #include<stdio.h>
- #include<stdlib.h>
- #include<math.h>
- #define EPS 1.0e-8
- #define POW 2
- double Newton(double);
- double Func(double, double);
- double dFunc(double);
- int main(){
- double Ln = Newton(2.0);//L_1 = sqrt(2)
- printf("%12.10f\n",Ln);
- int n = 1;
- int pow_base = 2;
- int n_max = 20;
- while( n < n_max ){
- printf( "%12.10f\n", pow_base * Ln );
- Ln = Newton( 2-Newton(4 - pow(Ln, 2)) );
- n += 1;
- pow_base *= POW;
- }
- return 0;
- }
- //平方根を求める
- double Newton(double C){
- double x = C;
- double dx = -Func(x, C) / dFunc(x);
- while( fabs(dx) > EPS ){
- x += dx;
- dx = -Func(x, C) / dFunc(x);
- }
- return x;
- }
- double Func(double x, double C){
- return x*x-C;
- }
- double dFunc(double x){
- return 2.0 * x;
- }