
- Data Structures & Algorithms
- DSA - Home
- DSA - Overview
- DSA - Environment Setup
- Algorithm
- DSA - Algorithms Basics
- DSA - Asymptotic Analysis
- DSA - Greedy Algorithms
- DSA - Divide and Conquer
- DSA - Dynamic Programming
- Data Structures
- DSA - Data Structure Basics
- DSA - Array Data Structure
- Stack & Queue
- DSA - Stack
- DSA - Expression Parsing
- DSA - Queue
- Searching Techniques
- DSA - Linear Search
- DSA - Binary Search
- DSA - Interpolation Search
- DSA - Hash Table
- Sorting Techniques
- DSA - Sorting Algorithms
- DSA - Bubble Sort
- DSA - Insertion Sort
- DSA - Selection Sort
- DSA - Merge Sort
- DSA - Shell Sort
- DSA - Quick Sort
- Graph Data Structure
- DSA - Graph Data Structure
- DSA - Depth First Traversal
- DSA - Breadth First Traversal
- Tree Data Structure
- DSA - Tree Data Structure
- DSA - Tree Traversal
- DSA - Binary Search Tree
- DSA - AVL Tree
- DSA - Spanning Tree
- DSA - Heap
- DSA Useful Resources
- DSA - Questions and Answers
- DSA - Quick Guide
- DSA - Useful Resources
- DSA - Discussion
Secant method to solve non-linear equationn
Secant method is also used to solve non-linear equations. This method is similar to the Newton-Raphson method, but here we do not need to find the differentiation of the function f(x). Only using f(x), we can find f’(x) numerically by using Newton’s Divide difference formula. From the Newton-Raphson formula,
we know that,
Now, using divide difference formula, we get,
By replacing the f’(x) of Newton-Raphson formula by the new f’(x), we can find the secant formula to solve non-linear equations.
Note: For this method, we need any two initial guess to start finding the root of non-linear equations.
Input and Output
Input: The function f(x) = (x*x) - (4*x) - 10 Output: The root is: -1.74166
Algorithm
secant(x1, x2)
Input: Two initial guess for root.
Output: The approximate root of a non-linear equation f(x).
Begin f1 := f(x1) f2 := f(x2) x3 := ((f2*x1) – (f1*x2)) / (f2 – f1) while relative error of x3 and x2 are > precision, do x1 := x2 f1 := f2 x2 := x3 f2 := f(x2) x3 := ((f2*x1) – (f1*x2)) / (f2 – f1) done root := x3 return root End
Example
#include<iostream> #include<cmath> using namespace std; double absolute(double value) { //to find magnitude of value if(value < 0) return (-value); return value; } double f(double x) { //the given function x^2-4x-10 return ((x*x)-(4*x)-10); } double secant(double x1, double x2) { double x3, root; double f1, f2; f1 = f(x1); f2 = f(x2); x3 = (f2*x1-f1*x2)/(f2-f1); while(absolute((x3-x2)/x3) > 0.00001) { //test accuracy of x3 x1 = x2; //shift x values f1 = f2; x2 = x3; f2 = f(x2); //find new x2 x3 = (f2*x1-f1*x2)/(f2-f1); //calculate x3 } root = x3; return root; //root of the equation } main() { double a, b, res; a = 0.5; b = 0.75; res = secant(a, b); cout << "The root is: " << res; }
Output
The root is: -1.74166
- Related Articles
- C++ Program to Solve any Linear Equation in One Variable
- Solve a linear matrix equation or system of linear scalar equations in Python
- How can we use the SciPy library to solve a Linear equation?
- Modelling the Secant Method in Python
- Which linear function of SciPy is used to solve a banded matrix equation?
- Which linear function of SciPy is used to solve the circulant matrix equation?
- What is a linear equation? Solve: $\frac{3m}{2}-3=3$.
- Which linear function of SciPy is used to solve Hermitian positive-definite banded matrix equation?
- Solve the following linear equation.\( \frac{x-5}{3}=\frac{x-3}{5} \).
- Solve the pair of linear equation: $2x+y=5\ .......\ ( i)$$3x+2y=8\ .......\ ( ii)$
- How to solve simultaneous linear equations?
- What is linear equation?
- Program to find root of an equations using secant method in C++
- How to solve an Equation?
- Solve the following linear equation.\( m-\frac{m-1}{2}=1-\frac{m-2}{3} \).

Advertisements