Format
Plain text
Post date
2019-01-15 23:39
Zeitraum der Veröffentlichung
Unbegrenzt
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<math.h>
  4. #define EPS 1.0e-8
  5. #define POW 2
  6. double Newton(double);
  7. double Func(double, double);
  8. double dFunc(double);
  9. int main(){
  10. double Ln = Newton(2.0);//L_1 = sqrt(2)
  11. printf("%12.10f\n",Ln);
  12. int n = 1;
  13. int pow_base = 2;
  14. int n_max = 20;
  15. while( n < n_max ){
  16. printf( "%12.10f\n", pow_base * Ln );
  17. Ln = Newton( 2-Newton(4 - pow(Ln, 2)) );
  18. n += 1;
  19. pow_base *= POW;
  20. }
  21. return 0;
  22. }
  23. //平方根を求める
  24. double Newton(double C){
  25. double x = C;
  26. double dx = -Func(x, C) / dFunc(x);
  27. while( fabs(dx) > EPS ){
  28. x += dx;
  29. dx = -Func(x, C) / dFunc(x);
  30. }
  31. return x;
  32. }
  33. double Func(double x, double C){
  34. return x*x-C;
  35. }
  36. double dFunc(double x){
  37. return 2.0 * x;
  38. }
Download Printable view

URL of this paste

Embed with JavaScript

Embed with iframe

Raw text