0% found this document useful (0 votes)
53 views1 page

Intersection PDF

This C program defines a function findRoot() that uses bisection to find the root of a function f(x) between input values a and b. It then calls findRoot() twice to find two roots, generates 200 evenly spaced x-values between the roots, and prints the sin and cos values of each x-value to output a comma-separated values file.

Uploaded by

Md. Mehedi Hasan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views1 page

Intersection PDF

This C program defines a function findRoot() that uses bisection to find the root of a function f(x) between input values a and b. It then calls findRoot() twice to find two roots, generates 200 evenly spaced x-values between the roots, and prints the sin and cos values of each x-value to output a comma-separated values file.

Uploaded by

Md. Mehedi Hasan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

#include<stdio.

h>
#include<math.h>
#include<stdlib.h>
#define f(x) (cos(x)-sin(x))
#define EPS 1.0e-6
double findRoot(double a, double b){
double x0=0.00;
while(1){
if(f(a)*f(b) > 0){
printf("Invalid input...\n");
exit(0);
}
x0 = (a+b)/2;
if(fabs(f(x0)) < EPS){
break;
}
if(f(a)*f(x0)<0)
b=x0;
else
a=x0;
}
return x0;
}

int main(void){
double a = 0, b = 3.1416, c = 2*3.1416, x1,x2;
int i;
x1 = findRoot(a, b);
x2 = findRoot(b, c);
int n=200;
double h, x, y, z;
a=x1;
b=x2;
h = (b-a)/n;
printf("\"x\",\"Sin(x)\",\"Cos(x)\"\n");
for (i=0; i<=n; i++) {
x = a + i*h;
y = sin(x);
z = cos(x);
printf("%lf, %lf, %lf\n",x,y,z);
}
}

You might also like