Finds the roots of the polynomial from the coefficents.
The Coeff holds the coefficients and the result is placed in the Roots.
The Length and Complex property of the Roots parameter are set automatically. The inverse to this routine is
Roots are computed by finding the eigenvalues of the companion matrix.
Example 1
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 "MtxVecCPP.h" //MtxVecCPP.cpp must be included in the project
#include "Polynoms.hpp"
#include "MtxVecTee.hpp"
void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{
Vector 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");
}
using Dew.Math;
using Dew.Math.Units;
using Dew.Math.Editors;
namespace Dew.Examples
{
private void Example()
{
Vector Coeff = new Vector(0);
Vector Roots = new Vector(0);
// coefficients of the polynomial 1*x^2 - 2*x + 1:
Coeff.SetIt(false,new double[] {1, -2, 1});
Polynoms.PolyRoots(Roots,Coeff);
// Roots now hold the roots of the polynomial = [ 1, 1 ]
// x^2 - 2x + 1 = (x - 1) * (x - 1)
MtxVecEdit.ViewValues(Roots,"Roots");
}
}