Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // para cosx=0, com a=0 e b=3 e epsilon
- #include <stdio.h>
- #include <math.h>
- // #include <assert.h>
- #define pi M_PI
- #define eps 1e-5
- double bisec(double x)
- {
- double f;
- int m=5; //2310
- f=tan(x)-m*x;
- return f;
- }
- int main(void)
- {
- double a=0.1, b=1.57, c, y;
- int i;
- // assert(bisec(a)>0);
- // assert(bisec(b)>0);
- while (fmax(fabs(bisec(a)),fabs(bisec(b)))>eps) // b-a
- {
- c=(a+b)/2;
- y=bisec(c);
- if (y<0)
- a=c;
- else if (y>0)
- b=c;
- else if (y==0)
- break;
- i++;
- }
- printf("Raiz calculada: %e \nIterações = %d \n",c,i);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement