Method of Regula-Falsi using C








Sumit Kar, Numerical Methods, C, Timus Rak


/*


Method of Regula-Falsi



Equation: x^3-4x-9=0


*/
#include<conio.h>
#include<stdio.h>

void main()
{
float a,b,k,c;
int i;
float f(float);
clrscr();
printf("\nEnter first initial value:: ");
scanf("%f",&a);
printf("\nEnter second initial value:: ");
scanf("%f",&b);
for(i=1;i<=5;i++)
{
c=b-((b-a)*(f(b)/(f(b)-f(a))));
k=f(c);
if(k>0)
b=c;
if(k<=0)
a=c;
}
printf("\nRoot is:: %f",c);
getch();
}
float f(float x)
{
return (x*x*x)-(4*x)-9;
}


0 Comments