
- 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 - Data Structures and Types
- DSA - Array Data Structure
- Linked Lists
- DSA - Linked List Basics
- DSA - Doubly Linked List
- DSA - Circular Linked List
- 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 - Red Black Trees
- DSA - B Trees
- DSA - B+ Trees
- DSA - Splay Trees
- DSA - Spanning Tree
- DSA - Tries
- DSA - Heap
- Recursion
- DSA - Recursion Basics
- DSA - Tower of Hanoi
- DSA - Fibonacci Series
- DSA Useful Resources
- DSA - Questions and Answers
- DSA - Quick Guide
- DSA - Useful Resources
- DSA - Discussion
Vieta’s Formulas
In mathematics, Vieta’s formulas are the concept of polynomials which relates a polynomial’s coefficients to the sums and products of the roots of the polynomial. Vieta’s formulas can be useful tools for learning relations between the polynomial’s roots without really knowing their numerical value and coefficients of the equation. We will be focusing on the concept of Vieta’s formulas and try to solve some problems using this formula in this article.
Vieta’s Formulas
The formulas developed by the mathematician Vieta establish the relationship between the sum and product of any polynomial’s roots and its coefficients. Since this formula deals with the roots and coefficients of the polynomial, we can use this formula to solve the problems related to relations between roots of the polynomial, or find the equation from provided roots using this formula.
Vieta’s formula for general polynomial
Any polynomial can be written as,
$$\mathrm{P(x)\:=\:a_{n}x^{n}\:+\:a_{n-1}x^{n-1}\:+\:...\:+a_1x+a_0}$$
Let's assume 𝑃(𝑥) be a polynomial with roots $f_1,\:f_2,\:.\:.\:.,\:f_n.$ Then, Vieta’s formulas gives the relation as −
$$f_1\:+\:f_2\:+\:.\:.\:.+\:f_n\:=\:-\frac{a_{n-1}}{a_{n}}$$
and,
$$f_1f_2f_3...f_n\:=\:(-1)^{n}\frac{a_{0}}{a_{n}}$$
Vieta’s formula for quadratic equation
Let us consider a quadratic equation $P(x)\:=\:ax^{2}\:+\:bx\:+\:c$.
Let's say the roots of the above quadratic equation are $f_1$ 𝑎𝑛𝑑 $f_2$.
According to the vieta’s formula,
The sum of roots of the quadratic equation is given by -b/a.
$$f_1\:+\:f_2\:=\:-\frac{b}{a}$$
The product of the roots of the quadratic equation is given by c/a.
$$f_1f_2\:=\:\frac{c}{a}$$
If we are given both the sum of the roots and the product of the roots of the quadratic equation then it can be expressed as −
$$ax^{2}\:+\:bx\:+\:c\:=\:0$$
Dividing the whole equation by a,
$$x^{2}\:+\:\frac{b}{a}x\:+\:\frac{c}{a}\:=\:0$$
Since b/a is -(sum of roots of the equation) and c/a is the product of roots of the equation. So the equation can be written as −
$$x^{2}\:-\:(sum\:of\:roots)x\:+\:(product\:o\:roots)\:=\:0$$
$$x^{2}\:-\:(f_1\:+\:f_2)x\:+\:(f_1f_2)\:=\:0$$
Vieta’s formula for cubic equation
Let us consider a cubic equation $P(x)\:=\:ax^{3}\:+\:bx^{2}\:+\:cx\:+\:d$.
Let’s say the roots of the above cubic equations are $f_1,f_2\:and\:f_3$.
According to the vieta’s formula,
The sum of the roots of the cubic equation is given by -b/a.
$$f_1\:+\:f_2\:+\:f_3\:=\:-\frac{b}{a}$$
The sum of product of the two roots of the cubic equation is given by c/a.
$$f_1f_2\:+\:f_1f_3\:+\:f_2f_3\:=\:\frac{c}{a}$$
The product of roots of the cubic equation is given by -d/a.
$$f_1f_2f_3\:=\:-\frac{d}{a}$$
If we given sum of roots, sum of the product of two roots and the product of roots of the cubic equation, then the equation can be expressed as −
$$ax^{3}\:+\:bx^{2}\:+\:cx\:+\:d\:=\:0$$
Dividing the equation by a,
$$x^{3}\:+\:\frac{b}{a}x^{2}\:+\:\frac{c}{a}x\:+\:\frac{d}{a}\:=\:0$$
Since -b/a is sum of roots, c/a is sum of product of two roots and -d/a is the product of roots of the cubic equation, it can be written as
$$x^{3}\:-\:(sum\:of\:roots)x^{2}\:+\:(sum\:of\:product\:of\:two\:roots)x\:-\:(product\:of\:roots)\:=\:0$$
Let us go through some sample problems related to Vieta's formula.
Examples
Example-1
In this example, we will be given the coefficients of the quadratic equation as an input i.e. a, b and c and we need to find out the sum of roots and product of roots of the quadratic equation using Vieta’s formula.
Take coefficients of quadratic equation $(ax^{2}\:+\:bx\:+\:c)$ which are a, b and c as input.
We will initialise a function to calculate the sum and product of roots of the quadratic equation.
Using Vieta’s formula, we will calculate the sum of roots(-b/a) and product of roots(c/a).
Print the values which will be our required output.
Below is the implementation of the approach in C++ −
#include <iostream> #include <bits/stdc++.h> using namespace std; //function to calculate sum and product of roots of quadratic equation void roots(float a,float b,float c){ float sumOfroots=-(b)/a; //calculating sum of products using vieta's formula float productOfroots=c/a; //calculating product of roots using Vieta's formula cout<<"Sum of the roots = "<<sumOfroots<<endl; cout<<"Product of the roots = "<<productOfroots<<endl; } int main(){ //coefficient of quadratic equation which is 2x^2-10x-5=0 (ax^2+bx+c) float a=2; float b=-10; float c=-5; roots(a,b,c); return 0; }
Output
Sum of the roots = 5 Product of the roots = -2.5
Time Complexity : O(1), since constant time is taken.
Space Complexity : O(1), since no extra space is required.
Example-2
In this example, we will be given the coefficients of the cubic equation as an input i.e. a, b, c and d. We need to print the sum of the roots, sum of product of two roots and product of roots of the given cubic equation using Vieta’s formula.
Take the coefficients of the cubic equation $(ax^{3}\:+\:bx^{2}\:+\:cx\:+\:d)$ which are a, b, c and d as input.
Initialize a function to calculate the sum of the roots, sum of product of two roots and product of two roots of the cubic equation.
Using Vieta’s formula, calculate the required values and store it in a variable.
Print all the values.
Below is the implementation of the approach in C++ −
#include <iostream> #include <bits/stdc++.h> using namespace std; //function to calculate sum of roots, sum of product of two roots and product of roots void roots(float a,float b,float c,float d){ //calculating required values using Vieta's formulas float sumOfroots=-(b)/a; float sumOfproductOfTworoots=c/a; float productOfroots=-d/a; cout<<"Sum of the roots = "<<sumOfroots<<endl; cout<<"Sum of the product of two roots = "<<sumOfproductOfTworoots<<endl; cout<<"Product of two roots = "<<productOfroots<<endl; } int main(){ //a, b, c and d are the coefficients of the cubic equation which can be represented as 2x^3-10x^2-5x+4=0 float a=2; float b=-10; float c=-5; float d=4; roots(a,b,c,d); return 0; }
Output
Sum of the roots = 5 Sum of the product of two roots = -2.5 Product of two roots = -2
Time Complexity : O(1)
Space Complexity : O(1)
Conclusion
In this article, we tried to explain Vieta's formulas for general polynomial, quadratic equations and cubic equations. We also learn to find out the sum and product of roots of the quadratic equation and sum, product and sum of product of two roots of the cubic equation for any quadratic or cubic equation using C++.
I hope you find this article helpful to learn the basic concepts of Vieta’s Formulas.
- Related Articles
- Write the Trigonometry formulas.
- DC Generator – Formulas and Equations
- Write the formulas of trigonometric identities.
- Given some formulas of Algebraic identities.
- Define the formulas of the Rectangle.
- Electrical Transformers – Formulas and Equations Handbook
- Basic Electrical Engineering – Formulas and Equations
- Understanding Earned Value Management and Formulas
- Mention some of the formulas of Mensuration.
- How can I make formulas in chemistry?
- What are the formulas related to pendulum?
- What are kite and rhombus? Give the formulas.
- How to Convert Text Strings to Formulas in Excel?
- Change cell reference in formulas to range names in Excel
- How to check if / find cells contains formulas in Excel?
