Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. double f(double x){
  6. return x*x+x-1;
  7. }
  8.  
  9. double fp(double x){
  10. return 2*x+1;
  11. }
  12.  
  13. int main(){
  14. int i;
  15. double eps0,epsx,x0,x1,f0,f1;
  16. eps0=1e-4;
  17. epsx=1e-4;
  18.  
  19. printf("Podaj punkt startowy");
  20. scanf("%lf", &x0);
  21.  
  22. x1 = x0 -1;
  23. f0 = f(x0);
  24. i=64;
  25.  
  26. while (i && (fabs(x1 - x0) > epsx) && (fabs(f0) >eps0)){
  27. f1 = fp(x0);
  28. if(fabs(f1) < eps0){
  29. printf("zly punkt startowy");
  30. i=0; break;
  31. }
  32. x1 = x0;
  33. x0 = x0 - f0 / f1;
  34. f0 = f(x0);
  35. if(!(--i)) printf("przekroczono limit obiegow");
  36. }
  37. if(i) printf("x0= %lf",x0);
  38.  
  39. return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement