Vieta's formula relates the coefficients of polynomial to the sum and product of their roots, as well as the products of the roots taken in groups. Vieta's formula describes the relationship of the roots of a polynomial with its coefficients. Consider the following example to find a polynomial with given roots. (Only discuss real-valued polynomials, i.e. the coefficients of polynomials are real numbers). Let's take a quadratic polynomial. Given two real roots r_{1} and r_{2} , then find a polynomial.
Consider the polynomial a_{2}x^{2} + a_{1}x + a_{0} . Given the roots, we can also write it as
k(x - r_{1})(x - r_{2}) .
Since both equation represents the same polynomial, so equate both polynomial
a_{2}x^{2} + a_{1}x + a_{0} = k(x - r_{1})(x - r_{2})
Simplifying the above equation, we get
a_{2}x^{2} + a_{1}x + a_{0} = kx^{2}-k(r_{1} + r_{2})x + k(r_{1}r_{2})
Comparing the coefficients of both sides, we get
For x^{2} , a_{2} = k ,
For x , a_{1} = -k(r_{1} + r_{2}) ,
For constant term, a_{0} = kr_{1}r_{2} ,
Which gives,
a_{2} = k ,
\frac{a_{1}}{a_{2}} = -(r_{1} + r_{2})........(1)
\frac{a_{0}}{a_{2}} = r_{1}r_{2}..................(2)
Equation (1) and (2) are known as Vieta's Formulas for a second degree polynomial.
In general, for an nth degree polynomial, there are n different Vieta's Formulas. They can be written in a condensed form as
For 0 \leq k \leq n
\sum_{1 \leq i_{1} < i_{2} < ... < i_{k} \leq n} (r_{i_{1}}r_{i_{2}} ... r_{i_{k}}) = (-1)^{k}\frac{a_{n-k}}{a_{n}}.
The following examples illustrate the use of Vieta's formula to solve a problem.
Examples:
Input : n = 2 roots = {-3, 2} Output : Polynomial coefficients: -6, -1, 1 Input : n = 4 roots = {-1, 2, -3, 7} Output : Polynomial coefficients: 42 -29 -19 5 1
C++ // C++ program to implement vieta formula // to calculate polynomial coefficients. #include <bits/stdc++.h> using namespace std; // Function to calculate polynomial // coefficients. void vietaFormula(int roots[], int n) { // Declare an array for // polynomial coefficient. int coeff[n + 1]; // Set all coefficients as zero initially memset(coeff, 0, sizeof(coeff)); // Set highest order coefficient as 1 coeff[0] = 1; for (int i = 0; i < n; i++) { for (int j = i + 1; j > 0; j--) { coeff[j] += roots[i] * coeff[j - 1]; } } cout << "Polynomial Coefficients: "; for (int i = n; i >= 0; i--) { cout << coeff[i] << " "; } } // Driver code int main() { // Degree of required polynomial int n = 4; // Initialise an array by // root of polynomial int roots[] = { -1, 2, -3, 7 }; // Function call vietaFormula(roots, n); return 0; }
Java import java.util.*; public class Main { // Function to calculate polynomial coefficients public static void vietaFormula(int[] roots, int n) { int[] coeff = new int[n + 1]; // Set all coefficients as zero initially Arrays.fill(coeff, 0); // Set highest order coefficient as 1 coeff[0] = 1; for (int i = 0; i < n; i++) { for (int j = i + 1; j > 0; j--) { coeff[j] += roots[i] * coeff[j - 1]; } } System.out.print("Polynomial Coefficients: "); for (int i = n; i >= 0; i--) { System.out.print(coeff[i] + " "); } } // Driver code public static void main(String[] args) { int n = 4; int[] roots = { -1, 2, -3, 7 }; vietaFormula(roots, n); } }
Python3 def vieta_formula(roots, n): # Initialize an array for polynomial coefficients coeff = [0] * (n + 1) # Set the highest order coefficient as 1 coeff[0] = 1 for i in range(n): for j in range(i + 1, 0, -1): coeff[j] += roots[i] * coeff[j - 1] # Return the coefficients list in reverse order return coeff[::-1] def main(): n = 4 roots = [-1, 2, -3, 7] # Call the vieta_formula function coefficients = vieta_formula(roots, n) print("Polynomial Coefficients: ", coefficients) if __name__ == "__main__": main()
C# // C# code using System; public class Program { // Function to calculate polynomial coefficients public static void vietaFormula(int[] roots, int n) { int[] coeff = new int[n + 1]; // Set all coefficients as zero initially Array.Fill(coeff, 0); // Set highest order coefficient as 1 coeff[0] = 1; for (int i = 0; i < n; i++) { for (int j = i + 1; j > 0; j--) { coeff[j] += roots[i] * coeff[j - 1]; } } Console.Write("Polynomial Coefficients: "); for (int i = n; i >= 0; i--) { Console.Write(coeff[i] + " "); } } // Driver code public static void Main(string[] args) { int n = 4; int[] roots = { -1, 2, -3, 7 }; vietaFormula(roots, n); } }
JavaScript // Javascript program to implement vieta formula // to calculate polynomial coefficients. // Function to calculate polynomial // coefficients. function vietaFormula(roots, n) { // Declare an array for // polynomial coefficient. let coeff = new Array(n + 1).fill(0); // Set highest order coefficient as 1 coeff[0] = 1; for (let i = 0; i < n; i++) { for (let j = i + 1; j > 0; j--) { coeff[j] += roots[i] * coeff[j - 1]; } } console.log("Polynomial Coefficients: "); for (let i = n; i >= 0; i--) { console.log(coeff[i] + " "); } } // Driver code function main() { // Degree of required polynomial let n = 4; // Initialise an array by // root of polynomial let roots = [ -1, 2, -3, 7 ]; // Function call vietaFormula(roots, n); return 0; } main();
OutputPolynomial Coefficients: 42 -29 -19 5 1
Time Complexity : \mathcal{O}(n^{2}) .
Auxiliary Space: O(n) because it is using extra space for array coeff
Similar Reads
General and Middle Terms - Binomial Theorem - Class 11 Maths Binomial theorem or expansion describes the algebraic expansion of powers of a binomial. According to this theorem, it is possible to expand the polynomial "(a + b)n" into a sum involving terms of the form "axzyc", the exponents z and c are non-negative integers where z + c = n, and the coefficient
7 min read
Types of Polynomials (Based on Terms and Degrees) Types of Polynomials: In mathematics, an algebraic expression is an expression built up from integer constants, variables, and algebraic operations. There are mainly four types of polynomials based on degree-constant polynomial (zero degree), linear polynomial ( 1st degree), quadratic polynomial (2n
9 min read
Polynomials in One Variable | Polynomials Class 9 Maths Polynomials in One Variable: Polynomial word originated from two words âpolyâ which means âmanyâ and the word ânominalâ which means âtermâ. In maths, a polynomial expression consists of variables known as indeterminate and coefficients. Polynomials are expressions with one or more terms with a non-z
7 min read
Vieta's Formula Vieta's Formulas provide a way to relate the coefficients of a polynomial to the sums and products of its roots. Named after the French mathematician François Viète, these formulas establish a connection between the roots of a polynomial and its coefficients.If you have a polynomial equation and kno
8 min read
Class 8 RD Sharma Solutions- Chapter 6 Algebraic Expressions And Identities -Â Exercise 6.6 | Set 1 Question 1. Write the following squares of binomials as trinomials:(i) (x + 2)2 Solution: x2 + 2 (x) (2) + 22 x2 + 4x + 4 (ii) (8a + 3b)2 Solution: (8a)2 + 2 (8a) (3b) + (3b) 64a2 + 48ab + 9b2 (iii) (2m + 1)2 Solution: (2m)2 + 2 (2m) (1) + 12 4m2 + 4m + 1 (iv) (9a + 1/6)2 Solution: (9a)2 + 2 (9a) (1
9 min read