Guest User

Untitled

a guest
Dec 10th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. double hordi(double x1, double x2, double epsilon){
  5. double x, x3, fx1, fx2, f, k, b;
  6. x3=2000;
  7. do
  8. {
  9. fx1 = sin(x1) - 0.5;
  10. fx2 = sin(x2) - 0.5;
  11. if (fx1 * fx2 > 0)
  12. return -1;
  13. x=x3;
  14. k = (fx2 - fx1) / (x2 - x1); /* Nahodim koafficient k */
  15. b = fx1 - (((fx2 - fx1) * x1) / (x2 - x1)); /* Nahodim svobodnii chlen b */
  16. x3 = x1 - (((x2-x1) * fx1)/(fx2-fx1)); /* Nahodim tochku persechenia */
  17. f = sin(x3) - 0.5;
  18.  
  19. if (f * fx1 > 0)
  20. x1 = x3;
  21. else
  22. x2 = x3;
  23. }
  24. while (fabs(x3-x) > epsilon);
  25. return x3;
  26. }
  27. int main(void)
  28. {
  29. double otvet;
  30. otvet = hordi(0, 2, 1e-6);
  31. if (otvet == -1)
  32. printf("nepravilnij interval");
  33. else
  34. { printf("%f", otvet);
  35. printf("/n");
  36. }
  37.  
  38. return 0;
  39. }
Add Comment
Please, Sign In to add comment