Sei sulla pagina 1di 3

Page No. :EXPERIMENT No.

:-

Date of assignment:-

Date of submission:-

Aim of the experiment:Write and execute a program in C to find a root of a transcendental equation by using the Bisection method. Use the program to find a real root of the equation x2 sin x 9 = 0

Page No. :-

#include<stdio.h> #include<conio.h> #include<math.h> #define f(x) (pow(x,2)-sin(x)-9)

void main() { int i; float x0, x1, x2, y0, y1, y2; clrscr(); read: printf("\n\n Enter the two starting values x0 and x1: "); scanf("%f %f", &x0, &x1); y0=f(x0); y1=f(x1); i=0; if(y0*y1>0) { printf("\n\n Starting values unsuitable...."); goto read; } else { while(fabs((x1-x0)/x1)>pow(10,-3)) { x2=(x0+x1)/2.0; y2=f(x2); i=i+1; if(y0*y2>0) x0=x2; else x1=x2; } printf("\n\n Solution converges to a root: %f",x2); printf("\n\n Number of iterations= %d",i); } getch(); }

Page No. :-

Output:-

Enter the two starting values x0 and x1: 2 3

Starting values unsuitable.... Enter the two starting values x0 and x1: 4 5

Starting values unsuitable.... Enter the two starting values x0 and x1: 3 4

Solution converges to a root: 3.021484 Number of iterations= 9

Potrebbero piacerti anche