Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #define PI acos(-1.)
- double yy;
- double f0(double x){
- return (PI - 2 * x) / (2 * sin(x) * sin(x)) - 1 / tan(x) - yy;
- }
- double findroot(double lb,double ub,double eps2,double(*pfunc)(double)){
- double mid,f = 1e3;
- while(fabs(f) > eps2){
- mid = (lb + ub) / 2;
- f = pfunc(mid);
- if(lb > ub){
- break;
- }
- else{
- if(f > 0){
- lb = mid;
- }
- else if(f < 0){
- ub = mid;
- }
- }
- }
- return mid;
- }
- int main(int argc,char **argv){
- scanf("%lf",&yy);
- printf("%.6f\n",findroot(0,5000,1e-10,f0));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement