Guest User

Untitled

a guest
Jan 19th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. /*
  2. * File: main.c
  3. * Author: joukaval
  4. *
  5. * Created on 12. lokakuuta 2011, 15:46
  6. */
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <math.h>
  11.  
  12. /*
  13. *
  14. */
  15. int main(int argc, char** argv) {
  16.  
  17.  
  18. double f = 0;
  19. double F = 0;
  20. double y = 0;
  21. double eps = 0.000001;
  22. double x = 1;
  23.  
  24. if (x != 0.0)
  25. for (int i = 0; i < 100; i++) {
  26.  
  27. f = (x * x);
  28. F = (2 * x);
  29. y = x - (f / F);
  30. printf("%i. iteraatio f: %f x: %f y: %f \n", i + 1, f, x, y);
  31. if (fabs(y - x) < eps)
  32. break;
  33. x = y;
  34.  
  35. }
  36. x = 3;
  37. printf("toinen polynomi\n");
  38.  
  39. if (x != 0.0)
  40. for (int i = 0; i < 100; i++) {
  41.  
  42. f = (x * x)+(eps / 2);
  43. F = (2 * x);
  44. y = x - (f / F);
  45. //printf("ABC %f\n", y);
  46. printf("%i. iteraatio f: %f x: %f y: %f \n", i + 1, f, x, y);
  47. if (fabs(y - x) < eps)
  48. break;
  49. x = y;
  50.  
  51. }
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61. return (EXIT_SUCCESS);
  62. }
Add Comment
Please, Sign In to add comment