Tuesday, August 2, 2016

PROGRAM FOR REGULA FALSI

/*PROGRAM FOR REGULA FALSI*/
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float x0,x1,x2,e;
int n,i,g=0;
float f(float);
clrscr();
printf("\n enter the value of x0,x1,e,n:\n");
scanf("%f%f%f%d",&x0,&x1,&e,&n);
if((f(x0)*f(x1)<0)
{
for(i=1;i<=n;i++)
{
x2=(x0*f(x1)-x1*f(x0)/(f(x1)-f(x0));
}
if(fabs(f(x2))<e)
{
g=1;
break;
}
if(f(x2)*f(x0)<0)
x1=x2;
else
{
x0=x2;
printf("Iteration: %f\n",x2);
}
 }
 }
 if(g==0)
 printf("\n Root does not found in n iteration upto desired accuracy");
 else
 printf("\n ANSWER:Root=%f",x2);
 getch();
 }
 float f(float x)
 {
 return(x*x*x-2*x-5);
 }


 /****************************OUTPUT*************************/
 Enter the value of x0,x1,e,n:
 1
 3
 .000006
 80
 Iteration:1.545455
 Iteration:1.859163
 Iteration:2.002119
 Iteration:2.059644
 Iteration:2.081572
 Iteration:2.089974
 Iteration:2.092782
 Iteration:2.093899
 Iteration:2.094311
 Iteration:2.094463
 Iteration:2.094519
 Iteration:2.094539
 Iteration:2.094547
 Iteration:2.094550
 Iteration:2.094551
 ANSWER ROOT IS=2.094551*/

No comments:

Post a Comment