Advertisement
dmkozyrev

task22

May 27th, 2015
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.52 KB | None | 0 0
  1. #define _USE_MATH_DEFINES
  2. #include <math.h>
  3. #include <stdio.h>
  4.  
  5. double F(double x){
  6.     return ( sin(x)-x+1 );
  7. }
  8.  
  9. double search_solution(double a, double b, double eps){
  10.     double dx = b - a;
  11.     double x = dx / 2;
  12.  
  13.     while ( abs( F(x) ) > eps ){
  14.         dx = dx / 2;
  15.         x = a + dx;
  16.         if ( F(x)*F(b) < 0 )
  17.             a = x;
  18.         else
  19.             b = x;
  20.     }
  21.  
  22.     return x;
  23. }
  24.  
  25. int main(){
  26.     double x = search_solution(M_PI/2, M_PI, 0.000001);
  27.     printf("Solution: %f", x);
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement