Dadas las raíces de una ecuación cúbica A , B y C , la tarea es formar la ecuación cúbica a partir de las raíces dadas.
Nota: Las raíces dadas son integrales.
Ejemplos:
Entrada: A = 1, B = 2, C = 3
Salida: x^3 – 6x^2 + 11x – 6 = 0
Explicación:
Dado que 1, 2 y 3 son raíces de las ecuaciones cúbicas, la ecuación viene dada por:
(x – 1)(x – 2)(x – 3) = 0
(x – 1)(x^2 – 5x + 6) = 0
x^3 – 5x^2 + 6x – x^2 + 5x – 6 = 0
x^3 – 6x^2 + 11x – 6 = 0.
Entrada: A = 5, B = 2, C = 3
Salida: x^3 – 10x^2 + 31x – 30 = 0
Explicación:
Dado que 5, 2 , y 3 son raíces de las ecuaciones cúbicas. Entonces, la ecuación viene dada por:
(x – 5)(x – 2)(x – 3) = 0
(x – 5)(x^2 – 5x + 6) = 0
x ^3 – 5x^2 + 6x – 5x^2 + 25x – 30 = 0
x^3 – 10x^2 + 31x – 30 = 0.
Enfoque: Deje que la raíz de la ecuación cúbica ( ax 3 + bx 2 + cx + d = 0 ) sea A, B y C. Luego, la ecuación cúbica dada se puede representar como:
ax 3 + bx 2 + cx + d = x 3 – (A + B + C)x 2 + (AB + BC+CA)x + A*B*C = 0.
Sea X = (A + B + C)
Y = (AB + BC+CA)
Z = A*B*C
Por lo tanto, utilizando la relación anterior, encuentre el valor de X , Y y Z y forme la ecuación cúbica requerida.
A continuación se muestra la implementación del enfoque anterior:
C++
// C++ program for the approach #include <bits/stdc++.h> using namespace std; // Function to find the cubic // equation whose roots are a, b and c void findEquation(int a, int b, int c) { // Find the value of coefficient int X = (a + b + c); int Y = (a * b) + (b * c) + (c * a); int Z = a * b * c; // Print the equation as per the // above coefficients cout << "x^3 - " << X << "x^2 + " << Y << "x - " << Z << " = 0"; } // Driver Code int main() { int a = 5, b = 2, c = 3; // Function Call findEquation(a, b, c); return 0; }
Java
// Java program for the approach class GFG{ // Function to find the cubic equation // whose roots are a, b and c static void findEquation(int a, int b, int c) { // Find the value of coefficient int X = (a + b + c); int Y = (a * b) + (b * c) + (c * a); int Z = a * b * c; // Print the equation as per the // above coefficients System.out.print("x^3 - " + X+ "x^2 + " + Y+ "x - " + Z+ " = 0"); } // Driver Code public static void main(String[] args) { int a = 5, b = 2, c = 3; // Function Call findEquation(a, b, c); } } // This code contributed by PrinciRaj1992
Python3
# Python3 program for the approach # Function to find the cubic equation # whose roots are a, b and c def findEquation(a, b, c): # Find the value of coefficient X = (a + b + c); Y = (a * b) + (b * c) + (c * a); Z = (a * b * c); # Print the equation as per the # above coefficients print("x^3 - " , X , "x^2 + " ,Y , "x - " , Z , " = 0"); # Driver Code if __name__ == '__main__': a = 5; b = 2; c = 3; # Function Call findEquation(a, b, c); # This code is contributed by sapnasingh4991
C#
// C# program for the approach using System; class GFG{ // Function to find the cubic equation // whose roots are a, b and c static void findEquation(int a, int b, int c) { // Find the value of coefficient int X = (a + b + c); int Y = (a * b) + (b * c) + (c * a); int Z = a * b * c; // Print the equation as per the // above coefficients Console.Write("x^3 - " + X + "x^2 + " + Y + "x - " + Z + " = 0"); } // Driver Code public static void Main() { int a = 5, b = 2, c = 3; // Function Call findEquation(a, b, c); } } // This code is contributed by shivanisinghss2110
Javascript
<script> // Javascript program for the approach // Function to find the cubic // equation whose roots are a, b and c function findEquation(a, b, c) { // Find the value of coefficient let X = (a + b + c); let Y = (a * b) + (b * c) + (c * a); let Z = a * b * c; // Print the equation as per the // above coefficients document.write("x^3 - " + X + "x^2 + " + Y + "x - " + Z + " = 0"); } let a = 5, b = 2, c = 3; // Function Call findEquation(a, b, c); </script>
x^3 - 10x^2 + 31x - 30 = 0
Complejidad de tiempo: O(1)
Espacio Auxiliar: O(1)