C program for Regula Falsi Method

Algorithm Enter two guesses value i.e x1 and x2. [note: guesses must selected in such a way that root of the equation is in between gues...

Algorithm

  1. Enter two guesses value i.e x1 and x2. [note: guesses must selected in such a way that root of the equation is in between guesses otherwise program display message to enter guess again]
  2. Find f1=f(x1) anf f2=f(x2)
  3. if f1f2>0 stop the program
  4. else, find x0=x1-(f(x1)f(x2))/(f(x2)-f(x1)) and f0=f(x0)
  5. if f1f0<0, x2=x0 and f2=f0
  6. else, x1=x0 and f1=f0
  7. if modulus of (x2-x1)/x2 is less or equal to error criterian i.e e, then print root and stop
  8. else, goto step 4.
  9. Exit




Program

#include<conio.h>
#include<stdio.h>
#include<math.h>
#define f(x) x*x-4*x-10
#define e 0.0001
void main()
{
float x0,x1,x2,f0,f1,f2,root;
int i=1;
clrscr();
printf("Regula Falsi Method to find root of equation x^2-4x-10=0\n");
printf("Enter values of x1 and x2\n");
a:printf("x1: ");
scanf("%f",&x1);
printf("x2: ");
scanf("%f",&x2);
f1=f(x1);
f2=f(x2);
if((f1*f2)>0)
{
printf("Enter Again\n");
goto a;
}
else
{
printf("steps\tx0\tf0\tx1\tf(x1)\tx2\tf(x2)\n");
b:x0=x1-((f1*(x2-x1))/(f2-f1));
f0=f(x0);
printf("%d\t%.4f\t%.4f\t%.4f\t%.4f\t%.4f\t%.4f\n",i,x0,f0,x1,f1,x2,f2);
i++;
}
if((f1*f0)<0)
{
x2=x0;
f2=f0;
}
else
{
x1=x0;
f1=f0;
}
if(fabs(f(x0))<=e)
{
root=x0;
printf("The root is %.4f",root);
goto c;
}
else
{
goto b;
}
c:
getch();
}


Output












Note: For other equation you have to change the #define f(x) x*x-4*x-10  as per your requires.

COMMENTS

BLOGGER: 3
Loading...
Name

Accident Alert,1,AI,2,Array,1,Aurdino,1,C,2,Computer Graphics,9,Data Science,3,Dataset,1,Decoratot,1,Django,1,ESP32,1,Fixed point/iteration method,1,Greater or smaller,1,html,1,Image Processing,1,JAVA,1,Javascript,22,Machine Learning,1,Matlab,3,Numerical Method,13,OOP,1,Other,3,PHP,1,Point operation,1,Python,11,Raspberry pi,1,Recommendation System,1,Regression,1,Reservation System,1,Robotics,1,Simulation,2,sine wave,1,String Handling Function,1,Web scrap,1,Webpage,1,
ltr
item
COMPUTER PROGRAMMING: C program for Regula Falsi Method
C program for Regula Falsi Method
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiw-PPNefYEtXSqa_Tx1BjarePcm8Ri1w0nOwb8cMftJeVVJ3YTKkpbkbMFcinpc6yr3w-f-O66O_lVutGekVXNuRwid-64LUlaGDaYGm8OLPVw7fsUldYdASnyjDlwjl0i_P3etgBiiL4q/s320/Screenshot+%252837%2529.png
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiw-PPNefYEtXSqa_Tx1BjarePcm8Ri1w0nOwb8cMftJeVVJ3YTKkpbkbMFcinpc6yr3w-f-O66O_lVutGekVXNuRwid-64LUlaGDaYGm8OLPVw7fsUldYdASnyjDlwjl0i_P3etgBiiL4q/s72-c/Screenshot+%252837%2529.png
COMPUTER PROGRAMMING
https://computerprogram4ru.blogspot.com/2016/07/c-program-for-regula-falsi-method.html
https://computerprogram4ru.blogspot.com/
https://computerprogram4ru.blogspot.com/
https://computerprogram4ru.blogspot.com/2016/07/c-program-for-regula-falsi-method.html
true
8672391763020279633
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy