Fórmulas de Vieta

La fórmula de Vieta relaciona los coeficientes del polinomio con la suma y el producto de sus raíces, así como los productos de las raíces tomados en grupos. La fórmula de Vieta describe la relación de las raíces de un polinomio con sus coeficientes. Considere el siguiente ejemplo para encontrar un polinomio con raíces dadas. (Solo analice los polinomios con valores reales, es decir, los coeficientes de los polinomios son números reales). Tomemos un polinomio cuadrático. Dadas dos raíces reales  r_{1}     r_{2}     , encuentra un polinomio. 
Considere el polinomio  a_{2}x^{2} + a_{1}x + a_{0}     . Dadas las raíces, también podemos escribirlo como 
k(x - r_{1})(x - r_{2})     .
Dado que ambas ecuaciones representan el mismo polinomio, igualamos ambos polinomios
a_{2}x^{2} + a_{1}x + a_{0} = k(x - r_{1})(x - r_{2})
Simplificando la ecuación anterior, obtenemos
a_{2}x^{2} + a_{1}x + a_{0} = kx^{2}-k(r_{1} + r_{2})x + k(r_{1}r_{2})
Comparando los coeficientes de ambos lados, obtenemos
Para x^{2}     a_{2} = k     ,
Para  x     a_{1} = -k(r_{1} + r_{2})
Para término constante,  a_{0} = kr_{1}r_{2}     ,
Lo que da, 
a_{2} = k     ,
\frac{a_{1}}{a_{2}} = -(r_{1} + r_{2})........(1)
\frac{a_{0}}{a_{2}} = r_{1}r_{2}..................(2)
Las ecuaciones (1) y (2) se conocen como fórmulas de Vieta para un polinomio de segundo grado. 
En general, para un  nth     polinomio de grado, existen n Fórmulas de Vieta diferentes. Se pueden escribir en forma condensada como 
Para  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}}.
Los siguientes ejemplos ilustran el uso de la fórmula de Vieta para resolver un problema.
Ejemplos: 
 

Input : n = 2
        roots = {-3, 2}
Output : Polynomial coefficients: 1, 1, -6

Input : n = 4
        roots = {-1, 2, -3, 7}
Output : Polynomial coefficients: 1, -5, -19, 29, 42

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[n] = 1;
 
    for (int i = 1; i <= n; i++) {
        for (int j = n - i - 1; j < n; j++) {
            coeff[j] = coeff[j] + (-1) *
                roots[i - 1] * 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

// Java program to implement vieta formula
// to calculate polynomial coefficients.
import java.util.Arrays;
 
class GFG
{
 
// Function to calculate polynomial
// coefficients.
static void vietaFormula(int roots[], int n)
{
    // Declare an array for
    // polynomial coefficient.
    int coeff[] = new int[++n + 1];
    Arrays.fill(coeff, 0);
     
    // Set highest order coefficient as 1
    coeff[n] = 1;
 
    for (int i = 1; i <n; i++)
    {
        for (int j = n - i - 1; j < n; j++)
        {
            coeff[j] = coeff[j] + (-1) *
                roots[i - 1] * 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)
{
    // 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);
    }
}
 
/* This code contributed by PrinciRaj1992 */

Python3

# Python3 program to implement
# Vieta's formula to calculate
# polynomial coefficients.
def vietaFormula(roots, n):
     
    # Declare an array for
    # polynomial coefficient.
    coeff = [0] * (n + 1)
     
    # Set Highest Order
    # Coefficient as 1
    coeff[n] = 1
    for i in range(1, n + 1):
        for j in range(n - i - 1, n):
            coeff[j] += ((-1) * roots[i - 1] *
                                coeff[j + 1])
     
    # Reverse Array
    coeff = coeff[::-1]
     
    print("Polynomial Coefficients : ", end = "")
     
    # Print Coefficients
    for i in coeff:
        print(i, end = " ")
    print()
 
# Driver Code
if __name__ == "__main__":
     
    # Degree of Polynomial
    n = 4
     
    # Initialise an array by
    # root of polynomial
    roots = [-1, 2, -3, 7]
     
    # Function call
    vietaFormula(roots, n)
     
# This code is contributed
# by Arihant Joshi

C#

// C# program to implement vieta formula
// to calculate polynomial coefficients.
using System;
     
class GFG
{
 
// Function to calculate polynomial
// coefficients.
static void vietaFormula(int []roots, int n)
{
    // Declare an array for
    // polynomial coefficient.
    int []coeff = new int[++n + 1];
     
    // Set highest order coefficient as 1
    coeff[n] = 1;
 
    for (int i = 1; i <n; i++)
    {
        for (int j = n - i - 1; j < n; j++)
        {
            coeff[j] = coeff[j] + (-1) *
                roots[i - 1] * 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)
{
    // 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);
}
}
 
// This code has been contributed by 29AjayKumar

PHP

<?php
// PHP program to implement vieta formula
// to calculate polynomial coefficients.
 
// Function to calculate polynomial
// coefficients.
function vietaFormula($roots, $n)
{
    // Declare an array for
    // polynomial coefficient.
    $coeff = array_fill(0, $n + 1, 0);
 
    // Set all coefficients as zero initially
     
    // Set highest order coefficient as 1
    $coeff[$n] = 1;
 
    for ($i = 1; $i <= $n; $i++)
    {
        for ($j = $n - $i; $j < $n; $j++)
        {
            $coeff[$j] = $coeff[$j] + (-1) *
                         $roots[$i - 1] *
                         $coeff[$j + 1];
        }
    }
 
    echo "polynomial coefficients: ";
    for ($i = $n; $i >= 0; $i--)
    {
        echo $coeff[$i]. " ";
    }
}
 
// Driver code
 
// Degree of required polynomial
$n = 4;
 
// Initialise an array by
// root of polynomial
$roots = array(-1, 2, -3, 7);
 
// Function call
vietaFormula($roots, $n);
 
// This code is contributed by mits
?>

Javascript

<script>
// 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);
    for(let i = 0; i < coeff.length; i++)
        coeff[i] = 0;
       
    // Set highest order coefficient as 1
    coeff[n] = 1;
   
    for (let i = 1; i <n; i++)
    {
        for (let j = n - i - 1; j < n; j++)
        {
            coeff[j] = coeff[j] + (-1) *
                roots[i - 1] * coeff[j + 1];
        }
    }
   
    document.write("Polynomial Coefficients: ");
    for (let i = n; i > 0; i--)
    {
        document.write(coeff[i] + " ");
    }
}
 
// Driver code
// 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);
 
// This code is contributed by rag2127
</script>
Producción: 

Polynomial Coefficients: 1 -5 -19 29 42 

 

Tiempo Complejidad : \mathcal{O}(n^{2})     .
 

Publicación traducida automáticamente

Artículo escrito por AayushChaturvedi y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *