You are here: Symbol Reference > Polynoms Namespace > Functions > Polynoms.PolyRoots Function
MtxVec VCL
ContentsIndex
PreviousUpNext
Polynoms.PolyRoots Function

Finds the roots of the polynomial from the coefficents.

Pascal
procedure PolyRoots(Roots: TVec; Coeff: TVec);

Finds the roots of the polynomial from the coefficents. The Coeff holds the coefficients and the result is placed in the Roots. 

 

P(x) = coeff[0]*x^n + coeff[1]*x^(n-1) + .. + coeff[n+1] = (x - roots[0])* .. *(x - roots[n-1]) n ... order of the polynomial P(x).. value of the polynomial evaluated at x.

 

The Length and Complex property of the Roots parameter are set automatically. The inverse to this routine is PolyCoeff Roots are computed by finding the eigenvalues of the companion matrix.

uses MtxExpr, Math387, MtxVec, MtxVecEdit, Polynoms; procedure TForm42.Button1Click(Sender: TObject); var Coeff, Roots: Vector; begin // coefficients of the polynomial 1*x^2 - 2*x + 1: Coeff.SetIt(false,[1, -2, 1]); PolyRoots(Roots,Coeff); // Roots now hold the roots of the polynomial = [ 1, 1 ] // x^2 - 2x + 1 = (x - 1) * (x - 1) ViewValues(Roots,'Roots'); end;
#include "MtxExpr.hpp" #include "Polynoms.hpp" #include "MtxVecTee.hpp" void __fastcall TForm1::BitBtn1Click(TObject *Sender) { sVector Coeff, Roots; // coefficients of the polynomial 1*x^2 - 2*x + 1 Coeff.SetIt(false,OPENARRAY(double,{1, -2, 1})); PolyRoots(Roots,Coeff); // Roots now hold the roots of the polynomial = [ 1, 1 ] // x^2 - 2x + 1 = (x - 1) * (x - 1) ViewValues(Roots,"Roots"); }
Examples on GitHub
Copyright (c) 1999-2025 by Dew Research. All rights reserved.
What do you think about this topic? Send feedback!