# Find the roots of a complex polynomial equation using Regula Falsi Method in C

In this article, we are going to learn **how to find the roots of a complex polynomial equation using Regula Falsi Method**?

Submitted by Sneha Dujaniya, on June 09, 2018

## Regula Falsi method

**About the method:**

We often hear many children and even many adults complaining about the difficulty level that they face while solving complex polynomial equations. It is also difficult for many to follow the steps in a scientific calculator and find the roots of the equations.

Therefore, this is a program that would help engineering students and many shopkeepers, vendors to solve complex equations via the False Position method or the **Regula Falsi method**. It is also handy, easy and calculations need not be done.

Though this is an old method and not much used now it can be useful for those students who are willing to work on a complex project and on a difficult topic like this as they can create a better impression on their professors and fetch more marks. **The method used is**:

We start this procedure by locating two points x_{0} and x_{1} where the function has opposite signs. We now connect the two points f(x_{0}) and f(x_{1}) by a straight line and find where it cuts the x-axis. Let it cut the axis at x_{2}. We find f(x_{2}). If f(x_{2}) and f(x_{0}) are of opposite signs then we replace x_{1} by x_{2} and draw a straight line connecting f(x_{2}) to f(x_{0}) to find the new intersection point. If f(x_{2}) and f(x_{0}) are of the same sign then x_{0} is replaced by x_{2} and proceed as before. In both cases, the new interval of search is smaller than the initial interval and ultimately it is guaranteed to converge to the root.

**We will now get an equation to find the successive approximations to the root:**

**Problem:**

To find the roots of the given polynomial equation using the Regula Falsi method. Here, we take the equation in the form of **f(x) = a x^{2}+ bx+c** if the equation is a quadratic equation.

**Example: f(x) = x^{2}-25**

In this method, we need to assume **2** numbers which might be the roots of the equation by equating the equation **f(x)** to zero **{f(x) = 0}**. If the actual roots do not lie between or are near to the assumed values, the program will not run. And if the actual roots lie between the assumed values then the program will give the approximate of exact answer.

**Example/program:**

#include <stdio.h> #include <math.h> #define ep 0.001 float poly(float ar[], int, float); int main() { float a[10],y0,y1,y2,x0,x1,x2,s,r; int i,n; char flag; printf("\t\t\t*****REGULA FALSI METHOD*****"); //enter 2 if it is quadratic eq. printf ("\n\n Please enter the degree of polynomial equation: "); scanf ("%d", &n); if (n>1) { for (i=0;i<=n; i++) { printf ("Enter the coefficient of x to the power %d: ", i); scanf ("%f", &a[i]); } do { //enter assumed values of roots printf ("\n Enter the initial guesses of x0 and x1: "); scanf ("%f %f",&x0,&x1); y0=poly (a, n, x0); y1=poly (a, n, x1); } while (y0*y1>0); printf ("\n x0 x1 x2 y0 y1 y2"); for (i=0; i<=100; i++) { s= (x0*y1)-(y0*x1); r= y1-y0; x2 = s/r; y2 = poly (a, n, x2); if (fabs (y2)<= ep) { flag ='T'; break; } printf("\n %f %f %f %f %f %f",x0,x1,x2,y0,y1,y2); if ((y2*y0)<0) { x1=x2; y1=y2; } else { x0=x2; y0=y2; } } if(flag=='T') printf("\n\n Convergent solution= %f",x2); else printf("Does not converge in 100 iterations."); } else { printf("\n\tDegree not acceptable!"); } return 0; } float poly(float ar[],int n,float x) { int i; float p; p=ar[n]; for(i=n;i>=1;i--) { p=ar[i-1]+(x*p); } return (p); }

**Output:**

Related Tutorials

- Introduction to Algorithms
- Introduction to Greedy Strategy in Algorithms
- Stability in sorting
- External Merge Sorting Algorithm
- Radix Sort and its Algorithm
- Bucket Sort Algorithm
- Bubble sort Algorithm, Flow Chart and C++ Code
- Insertion sort Algorithm, flowchart and C, C++ Code
- Merge Sort | One of the best sorting algorithms used for large inputs
- Binary Search in C, C++
- Randomized Binary Search
- Meta Binary Search | One-sided Binary Search
- Difference between Linear Search and Binary Search
- Binary Search in String
- Variants of Binary Search
- Sieve of Eratosthenes to find prime numbers
- Optimal Merge Pattern (Algorithm and Example)
- Given an array of n numbers, Check whether there is any duplicate or not
- Finding the missing number
- Find the number occurring an odd number of times
- Find the pair whose sum is closest to zero in minimum time complexity
- Find three elements in an array such that their sum is equal to given element K
- Bitonic Search Algorithm
- Check whether a number is Fibonacci or not
- Segregate even and odd numbers in minimum time complexity
- Find trailing zeros in factorial of a number
- Find Nearest Greatest Neighbours of each element in an array
- Interpolation search algorithm
- Floor and ceil of an element in an array using C++
- Two Elements whose sum is closest to zero
- Find a pair with a given difference
- Count number of occurrences (or frequency) in a sorted array
- Find a Fixed Point (Value equal to index) in a given array
- Find the maximum element in an array which is first increasing and then decreasing
- Dynamic Programming (Components, Applications and Elements)
- Algorithm for fractional knapsack problem
- Algorithm and procedure to solve a longest common subsequence problem
- Find the Nth Fibonacci number | C++
- Longest Common Subsequence using Dynamic programming (DP)
- Longest Increasing Subsequence using Dynamic programming (DP)
- Find the maximum sub-array sum using KADANE'S ALGORITHM
- Non-intersecting chords using Dynamic Programming (DP)
- Edit Distance using Dynamic Programming (DP)
- Finding Ugly Number using Dynamic Programming (DP)
- Egg dropping problem using Dynamic Programming (DP)
- Wild card matching problem using Dynamic programming (DP)
- Compute sum of digits in all numbers from 1 to N for a given N
- Minimum jumps required using Dynamic programming (DP)
- Graph coloring problem's solution using backtracking algorithm
- Breadth First Search (BFS) and Depth First Search (DFS) Algorithms
- Travelling Salesman Problem
- Kruskal's (P) and Prim's (K) Algorithms
- Multistage graph problem with forward approach and backward approach algorithms
- Floyd Warshall algorithm with its Pseudo Code

- Backtracking (Types and Algorithms)
- 4 Queen's problem and solution using backtracking algorithm
- N Queen's problem and solution using backtracking algorithm
- Find the GCD (Greatest Common Divisor) of two numbers using EUCLID'S ALGORITHM
- Compute the value of A raise to the power B using Fast Exponentiation
- Implement First Come First Served (FCFS) CPU Scheduling Algorithm using C program
- Implementations of FCFS scheduling algorithm using C++
- Implementation of Shortest Job First (SJF) Non-Preemptive CPU scheduling algorithm using C++
- Implementation of Shortest Job First (SJF) Preemptive CPU scheduling algorithm using C++
- Implementation of Priority scheduling (Pre-emptive) algorithm using C++
- Implementation of Priority scheduling (Non Pre-emptive) algorithm using C++
- Implementation of Round Robin CPU Scheduling algorithm using C++
- Analysis of LRU page replacement algorithm and Belady's anomaly
- Branch and Bound
- Divide and Conquer Paradigm (What it is, Its Applications, Pros and Cons)
- Implementation of Round Robin CPU Scheduling algorithm using C++
- Strassen's Matrix Multiplication in algorithms
- Huffman Coding (Algorithm, Example and Time complexity)
- Graph coloring problem's solution using backtracking algorithm
- Tournament Tree and their properties
- Deterministic and Non Deterministic Algorithms
- Lower Bound Theory
- Non Recursive Tree Traversal Algorithm
- Line Drawing Algorithm
- Breadth First Search (BFS) and Depth First Search (DFS) Algorithms
- P and NP problems and solutions | Algorithms
- Travelling Salesman Problem
- 2 – 3 Trees Algorithm
- Algorithm and procedure to solve a longest common subsequence problem
- Midpoint Circle Algorithm
- Reliability design problem
- Removing consecutive duplicates from a string
- Fast Exponentiation using Bitmasking

What's New

- C Language MCQs
- Python MCQs
- Perl MCQs
- MongoDB MCQs
- Java MCQs
- C# MCQs
- Scala MCQs
- Blockchain MCQs
- AutoCAD MCQs
- PHP MCQs
- JavaScript MCQs
- jQuery MCQs
- ReactJS MCQs
- AngularJS MCQs
- JSON MCQs
- Ajax MCQs
- SASS MCQs
- HTML MCQs
- Advanced CSS MCQs
- CSS MCQs
- OOPs MCQs
- PL/SQL MCQs
- SQL MCQs
- Oracle MCQs
- SQLite MCQs
- MS Word MCQs
- Software Engineering MCQs
- Operating System MCQs
- Data Analytics and Visualization MCQs
- MIS MCQs
- Linux MCQs
- WordPress MCQs
- Blogging MCQs

- Energy & Environment Engineering MCQs
- Project Management MCQs
- Marketing MCQs
- Generally Accepted Accounting Principles MCQs
- Bills of Exchange MCQs
- Business Environment MCQs
- Sustainable Development MCQs
- Marginal Costing and Absorption Costing MCQs
- Globalisation MCQs
- Indian Economy MCQs
- Retained Earnings MCQs
- Depreciation MCQs
- Partnership MCQs
- Sole Proprietorship MCQs
- Goods and Services Tax (GST) MCQs
- Cooperative Society MCQs
- Capital Market MCQs
- Business Studies MCQs
- Basic Accounting MCQs
- MIS Executive Interview Questions
- Go Language Interview Questions

Top Interview Coding Problems/Challenges!

- Run-length encoding (find/print frequency of letters in a string)
- Sort an array of 0's, 1's and 2's in linear time complexity
- Checking Anagrams (check whether two string is anagrams or not)
- Relative sorting algorithm
- Finding subarray with given sum
- Find the level in a binary tree with given sum K
- Check whether a Binary Tree is BST (Binary Search Tree) or not
- 1[0]1 Pattern Count
- Capitalize first and last letter of each word in a line
- Print vertical sum of a binary tree
- Print Boundary Sum of a Binary Tree
- Reverse a single linked list
- Greedy Strategy to solve major algorithm problems
- Job sequencing problem
- Root to leaf Path Sum
- Exit Point in a Matrix
- Find length of loop in a linked list
- Toppers of Class
- Print All Nodes that don't have Sibling
- Transform to Sum Tree
- Shortest Source to Destination Path

Comments and Discussions!