Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _USE_MATH_DEFINES
- #include <math.h>
- #include <stdio.h>
- typedef double (*function) (double x) ;
- double search_solution(double a, double b, double eps, function f){
- double dx = b - a;
- double x = dx / 2;
- while ( abs( (*f)(x) ) > eps ){
- dx = dx / 2;
- x = a + dx;
- if ( (*f)(x) * (*f)(b) < 0 )
- a = x;
- else
- b = x;
- }
- return x;
- }
- double F(double x){
- return ( sin(x)-x+1 );
- }
- int main(){
- double x = search_solution(M_PI/2, M_PI, 0.000001, F);
- printf("Solution: %f", x);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement