0% found this document useful (0 votes)
43 views2 pages

Er - Puneet Kumar Tyagi

The document describes a C program that implements the bisection method to find the root of a function. It defines a function f(x) and initializes x1 and x2 values entered by the user. It iterates n times, calculating the midpoint x3 and function value y3 at each step. It updates x1 or x2 based on whether y1 and y3 have opposite signs, converging on the root. The program outputs the final root value x3.

Uploaded by

erpuneettyagi
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views2 pages

Er - Puneet Kumar Tyagi

The document describes a C program that implements the bisection method to find the root of a function. It defines a function f(x) and initializes x1 and x2 values entered by the user. It iterates n times, calculating the midpoint x3 and function value y3 at each step. It updates x1 or x2 based on whether y1 and y3 have opposite signs, converging on the root. The program outputs the final root value x3.

Uploaded by

erpuneettyagi
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Er.

Puneet kumar tyagi


AIM :- Write a program for BISECTION METHOD

#include<stdio.h>
#include<conio.h>
#include<math.h>
float f(float x)
{
return((-0.9)*(x*x)+(1.7)*x+2.5);
}
void main()
{
float x1,x2,x3,y1,y2,y3;
int i,n;
clrscr();
printf("\n enter the value of initial guess x1");
scanf("%f", &x1);
printf("\n enter the value of another guess x2");
scanf("%f", &x2);
printf("\n enter the number of iterations =");
scanf("%d", &n);
y1=f(x1);
y2=f(x2);
while(y1*y2>0)
{
printf("\n enter the value of x1 again =");
scanf("%f", &x1);
printf("\n enter value of x2 again =");
scanf("%f", &x2);
y1=f(x1);
y2=f(x2);
}
for(i=1;i<=n;i++)
{
x3=((x1+x2)/2);
Er.Puneet kumar tyagi
y3=f(x3);
if(y1*y3<0)
{
x2=x3;
y2=y3;
}
else
{
x1=x3;
y1=y3;
}
}
printf("\n the root x3=%f", x3);
getch();
}

OUTPUT

Enter the value of initial guess x1=2.8


Enter the value of initial guess x2=3
Enter the number of iterations =3
The root x3 =2.875000

You might also like