Subject: Computation Techniques.
Practical Name: Code for finding the solution of Equation using bisection Method.
Source Code:
#include<stdio.h>
#include<conio.h>
#include<math.h>
float f(float x)
{
return((x*x*x)-(5*x)+1);
}
void main()
{
float x1,x2,x3,y1,y2,y3;
int i,n;
clrscr();
printf(" enter initial values and no. of iteration");
scanf("%f%f%d",&x1,&x2,&n);
y1=f(x1);
y2=(x2);
while ((y1*y2)>0)
{
printf("enter the initial values and no. of iteration");
scanf("%f%f%d",&x1,&x2,&n);
y1=f(x1);
y2=f(x2);
}
for (i=1;i<=n;i++)
{
x3=(x1+x2)/2;
y3=f(x3);
if((y1*y3)>0)
{
x1=x3;
y1=y3;
}
else
{
x2=x3;
y2=y3;
}
}
printf("the root is ...%f",x3);
getch();
}
/* output */
enter initial values and no. of iteration
2
4
4
the root is ...2.125000
0 Response to "Impliment bisection method using itration"
Post a Comment